Bird
0
0

You want to compress documents contextually but also filter them by metadata before compression. Which approach is best?

hard📝 Conceptual Q8 of 15
LangChain - RAG Chain Construction
You want to compress documents contextually but also filter them by metadata before compression. Which approach is best?
AUse ContextualCompressionRetriever alone with metadata filter argument
BCompress documents first, then filter metadata on compressed results
CUse a base retriever that filters by metadata, then wrap it with ContextualCompressionRetriever
DFilter metadata after retrieving compressed documents manually
Step-by-Step Solution
Solution:
  1. Step 1: Understand order of operations

    Filtering should happen before compression to reduce data size efficiently.
  2. Step 2: Apply filtering in base retriever

    Base retriever can filter by metadata; then compression retriever compresses filtered docs.
  3. Final Answer:

    Use a base retriever that filters by metadata, then wrap it with ContextualCompressionRetriever -> Option C
  4. Quick Check:

    Filter before compress = A [OK]
Quick Trick: Filter first, then compress for best results [OK]
Common Mistakes:
  • Compressing before filtering wastes resources
  • Expecting compression retriever to filter metadata
  • Filtering after compression is inefficient

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes