Performance: Contextual compression
Contextual compression affects how much data is sent and processed during language model calls, impacting network load and response time.
compressed_context = compress_context(get_full_text()) response = llm.call(compressed_context)
full_context = get_full_text() response = llm.call(full_context)
| Pattern | Data Size Sent | Network Latency | Server Processing | Verdict |
|---|---|---|---|---|
| Uncompressed Context | Large (50-200kb) | High (200-500ms) | Longer | [X] Bad |
| Compressed Context | Small (10-40kb) | Low (100-200ms) | Shorter | [OK] Good |
Contextual compression in langchain?ContextualCompressionRetriever in langchain?base_retriever first, then llm.compressed_docs?
from langchain.retrievers import ContextualCompressionRetriever compressed_retriever = ContextualCompressionRetriever(base_retriever, llm) compressed_docs = compressed_retriever.get_relevant_documents(query)
TypeError: ContextualCompressionRetriever() missing 1 required positional argument. What is the likely cause?
compressed_retriever = ContextualCompressionRetriever(llm)
ContextualCompressionRetriever correctly in a langchain app?Pass the test and this pattern moves unknown