0
0
LangChainframework~10 mins

Contextual compression in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the ContextualCompressionRetriever from langchain.

LangChain
from langchain.retrievers import [1]
Drag options to blanks, or click blank then click option'
ASimpleRetriever
BVectorStoreRetriever
CContextualCompressionRetriever
DCompressionRetriever
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a similarly named but incorrect retriever class.
Misspelling the class name.
2fill in blank
medium

Complete the code to create a ContextualCompressionRetriever using a base retriever named base_retriever.

LangChain
compression_retriever = ContextualCompressionRetriever(base_retriever=[1])
Drag options to blanks, or click blank then click option'
Abase_retriever
Bretriever
Ccompressor
Dbase_compressor
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a wrong variable name that does not exist.
Confusing parameter names.
3fill in blank
hard

Fix the error in the code to correctly create a ContextualCompressionRetriever with a compressor named compressor_instance.

LangChain
retriever = ContextualCompressionRetriever(base_compressor=[1])
Drag options to blanks, or click blank then click option'
Acompress
Bcompressor_instance
CcompressorInstance
Dcompressor
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase instead of snake_case variable names.
Passing a variable that is not defined.
4fill in blank
hard

Fill both blanks to create a ContextualCompressionRetriever with a base retriever and return_source_documents=True.

LangChain
retriever = ContextualCompressionRetriever(base_retriever=[1], [2]=True)
Drag options to blanks, or click blank then click option'
Abase_retriever
Bcompressor
Creturn_source_documents
Duse_compression
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing parameter names for the boolean flag.
Passing wrong variable names.
5fill in blank
hard

Fill all three blanks to create a ContextualCompressionRetriever with a base retriever, a compressor, and enable returning source documents.

LangChain
retriever = ContextualCompressionRetriever(base_retriever=[1], base_compressor=[2], [3]=True)
Drag options to blanks, or click blank then click option'
Abase_retriever
Bcompressor_instance
Creturn_source_documents
Duse_compression
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up variable names for base retriever and compressor.
Using incorrect parameter names for the boolean flag.