Retrieval Contextual Compression: Keep the Evidence a Question Needs
Retrieval contextual compression is the step that selects only the evidence a question needs—or briefly summarizes it—instead of passing every retrieved document unchanged to the answer model. It can remove irrelevant context and reduce input length, but compression may also lose conditions, exceptions, or source details, or incorrectly merge claims from different sources. If exact source wording matters, prefer extractive selection. Use a short synthesis across passages only when each claim can still be linked back to its original location.
Retrieval Contextual Compression: Keep the Evidence a Question Needs
Retrieval contextual compression is the step that selects only the evidence a question needs—or briefly summarizes it—instead of passing every retrieved document unchanged to the answer model. It can remove irrelevant context and reduce input length, but compression may also lose conditions, exceptions, or source details, or incorrectly merge claims from different sources. If exact source wording matters, prefer extractive selection. Use a short synthesis across passages only when each claim can still be linked back to its original location.
How does compression differ from search and reranking?
Search finds documents that may be relevant to a query; reranking changes the relevance order of the retrieved candidates. Compression comes afterward and narrows or restates the parts of candidate documents that will support the answer. It therefore cannot reliably fix poor candidate retrieval, and a compressor must not invent evidence when relevant documents were never found.
One general flow is retrieval → candidate reranking → query-aware evidence selection/compression → answer generation → source check. This is an example design pattern, not a requirement to use a particular library. Pass document IDs, versions, and passage locations through every step so the final answer can be traced back to its source.
Should you select sentences or summarize them?
| Method | What it preserves | When it fits | Main risk |
|---|---|---|---|
| Extractive selection | Original sentences and wording | Exact quotation, numbers, rules, or auditability matter | Removing surrounding context can obscure pronouns or conditions |
| Abstractive compression | A shorter restatement of several sentences | Evidence is spread across passages and a shorter input matters | Dropping conditions or counterexamples, merging sources, or adding a conclusion absent from the source |
| Selective omission | Nothing when evidence is absent or insufficient | Retrieved results may not answer the question and irrelevant context could distract | Omitting needed material too aggressively |
| Pass selected source passages through | Some relevant passages unchanged | Avoiding an extra model call and keeping provenance clear are priorities | Longer input, context limits, and duplication |
“Summary” and “sentence selection” are not the same compression strategy. If the task requires a direct quotation, a compressor’s paraphrase cannot be presented as a quotation. Use a summary to help draft an answer, but obtain quotations from the original source.
Work through a small design example
Hypothetical question: “Can I get a refund if I cancel an annual plan partway through?” Suppose retrieval returns a pricing table, a refund policy, and last month’s FAQ.
The reranker places the current policy and pricing document near the top.
The compression step selects sentences about `annual billing`, `mid-term cancellation`, `refund`, and `exceptions`, while retaining the effective date and applicable product.
If the FAQ uses different wording, check the dates and authority of both sources. Resolve priority using code or an approved business rule.
Do not cite the compressed summary in the final answer. Link the relevant source document ID, page, or section instead.
If the policy does not answer the question, return an empty compression result or an insufficient-evidence state, then request another search or human review.
This is an illustrative procedure and makes no claim about a real plan or refund policy.
What should compression rules preserve?
Preserving only facts related to the question is not enough; preserve the scope in which each fact applies. Keep units and reference periods with numbers; keep audience, conditions, exceptions, and effective dates with rules; and keep source and location with claims. If a summary retains “the policy allows cancellation before shipment” but drops “custom-made goods are excluded,” it is shorter but becomes misleading evidence. Do not merge conflicting statements into one; pass along the conflict and its sources.
You can separate the user’s question from retrieved documents in the prompt and instruct the model to treat document text as data, not as directions. But a prompt telling the compressor to ignore malicious instructions inside a document is not a complete security control. Restrict the tools that retrieved documents can invoke, never let a compression result directly authorize an external action, and validate factual claims in the final answer.
How do you evaluate whether compression helps?
Compare against a baseline with compression disabled, using the same questions and retrieved results. Measure more than final-answer correctness: did necessary evidence survive, were conditions and source locations preserved, and did the system return an empty result correctly when evidence was missing? Also track token savings, the extra model-call cost, end-to-end latency, and human-review effort. Fewer tokens are not a quality improvement if an exception needed for a correct answer disappeared.
Xu, Shi, and Choi’s RECOMP study distinguishes extractive compressors that select useful sentences from retrieved documents from abstractive compressors that summarize multiple documents. It also studies selective augmentation, which can return an empty result when retrieved information is irrelevant or unhelpful. The authors evaluated high compression rates and performance in language modeling and open-domain question answering experiments. Those results apply to their trained compressors and research datasets and models; they do not guarantee the same compression rate or performance in a general commercial retrieval pipeline. Original RECOMP paper
When should you skip compression?
Retrieved evidence is already short, and using the original passage and location is clearer.
The exact wording or scope matters, as with a long quotation, legal clause, or numeric table.
The cost and latency of another model call exceed the input savings.
There is no reliable priority rule for resolving conflicts among documents.
You cannot preserve traceability to the source after compression, while the final answer requires exact citations.
In these cases, it may be safer to reduce the number of candidates through reranking, select a relevant passage directly, or search again.
Sources
Xu, Shi, and Choi, “[RECOMP: Improving Retrieval-Augmented LMs with Compression and Selective Augmentation](https://arxiv.org/abs/2310.04408),” ICLR 2024.
[OpenAI API: Retrieval](https://developers.openai.com/api/docs/guides/tools-file-search) — How to inspect document and passage information returned by a retrieval tool.