Retrieval Refinement is a pattern that refines retrieved chunks after the initial search but before they reach the LLM. Techniques include re-ranking by relevance, deduplicating near-identical passages, filtering by recency or metadata, and compressing context to fit token budgets.
At a Glance
- Problem: Vector similarity ranks chunks by topical closeness, not by whether they answer the question, so the top result can be tangential while the answer sits at position seven, buried in noise, outdated, or about a same-named entity.
- Forces: Relevance gains from reranking versus added latency and model cost; compression saves context, but can strip the context that gives a passage its meaning; strict metadata filters block bad results, but can drop the only chunk with the answer.
- Solution: Add a stage between retrieval and generation that filters a broad candidate set by metadata, reranks the remainder with a cross-encoder that reads query and chunk together, and compresses the top results down to their relevant passages.
- Consequences: Gains: the chunks that reach the LLM actually answer the query, and reranking alone often adds 10 to 25 percentage points of relevance. Costs: 100 to 300 milliseconds of added latency, another model to host, irreversible compression decisions, and more pipeline stages to evaluate and debug.
What problem does Retrieval Refinement solve?
You run a vector search and get back your top ten chunks. The cosine similarity scores look reasonable. But when you feed them to the LLM, the generated answer is mediocre, sometimes outright wrong. You inspect the chunks manually and find that chunk number seven contains the answer while chunk number one, the highest-scored result, is only tangentially related.
This happens because vector similarity is a blunt instrument. It measures how close two embeddings are in a high-dimensional space. It does not measure whether a chunk answers the specific question being asked. A chunk about "database configuration best practices" will score highly against a query about "database connection timeout errors" because the topics overlap semantically. But that chunk might not contain anything about timeouts at all.
There are other failure modes too. Retrieved chunks might contain the right answer buried inside three paragraphs of irrelevant context. They might refer to an entity with the same name but in a completely different context, such as "Mercury" the planet versus "Mercury" the database. They might be correct but outdated, superseded by a newer document. Or they might be so generic that they add no value to the response. Retrieval got you close to the answer, and refinement has to close the remaining gap.
How does Retrieval Refinement work?
Node postprocessing is a processing stage that sits between retrieval and generation. It takes the raw retrieved chunks and transforms them into a refined set the LLM can use. Think of it as a quality control checkpoint.
Reranking usually gives the biggest gain. You take your initial retrieved set, typically 20 to 50 chunks, and pass them through a cross-encoder model that scores each chunk against the original query. Unlike the embedding model used during retrieval, a cross-encoder sees the query and the chunk together and can make fine-grained relevance judgments. It can distinguish between "this chunk is about the same topic" and "this chunk directly answers this question." After reranking, you take the top-k results from the reranked list, typically 3 to 5 chunks. The improvement is often large, and documents that were buried at position 15 in the original ranking jump to position 1.
Contextual compression addresses the problem of chunks that contain the answer alongside a lot of noise. Instead of passing the entire chunk to the LLM, you use a smaller model to extract only the sentences or passages that are relevant to the query. A 500-token chunk might get compressed down to 80 tokens of relevant content. This saves context window space and reduces the chance that the LLM latches onto irrelevant parts of the chunk.
Disambiguation handles the entity collision problem. When your knowledge base contains documents about multiple entities that share a name, retrieved chunks can mix them together. A postprocessing step can detect when chunks refer to different entities and filter out the ones that do not match the user's intent. This often requires looking at metadata like document source, category, or timestamp to resolve the ambiguity.
Metadata filtering applies hard constraints based on chunk metadata. You might filter by recency, keeping only documents updated in the last year. You might filter by source, preferring official documentation over community posts. You might filter by confidence score, dropping anything below a threshold. These filters are simple but they prevent entire categories of bad results from reaching the LLM.
These techniques compose well. A typical production pipeline retrieves a broad initial set, applies metadata filters to remove obviously irrelevant chunks, reranks the remainder, compresses the top results, and passes the compressed output to the LLM.
When should you use Retrieval Refinement?
If your retrieval accuracy is below 80% on your evaluation set and you have already tuned your embedding model and chunking strategy, postprocessing is where to look next. Reranking alone often yields a 10 to 25 percentage point improvement in relevance metrics.
Use reranking when you can tolerate an additional 100 to 300 milliseconds of latency per query. Cross-encoder models are slower than bi-encoder retrieval but still fast enough for most interactive use cases.
Use contextual compression when your chunks are large, say 500 tokens or more, and you are concerned about context window usage or LLM distraction from irrelevant content.
Use metadata filtering when your knowledge base has clear freshness requirements, when documents have reliable source quality indicators, or when entity ambiguity is a known issue.
When not to use it: Skip postprocessing if your retrieval is already highly accurate, if latency requirements are extremely tight (under 200ms total), or if your knowledge base is small enough that retrieved chunks are almost always relevant. If the right document never enters the candidate set because users and documents use different words, reranking cannot rescue it; fix recall with Hybrid Retrieval first. If the answer needs evidence from several documents, use Deep Search.
Worked Example: Cost and Latency
A docs assistant answers 10,000 questions a day; the baseline passes the top 10 chunks of 500 tokens straight to the large model.
| Setup | Calls per request | Tokens into the large model (in / out) | Cost per 1,000 requests | Latency per request |
|---|---|---|---|---|
| Top 10 chunks, no refinement | 1 search + 1 LLM | 5,300 / 300 | $20.40 | 5.8 s |
| Retrieve 40, rerank, keep top 4 | 1 search + 1 rerank + 1 LLM | 2,300 / 300 | $11.54 | 6.0 s |
| Rerank, then compress top 4 to 80 tokens each | 1 search + 1 rerank + 4 small LLM (parallel) + 1 LLM | 620 / 300 | $7.00 | 7.0 s |
The baseline costs 5,300 × $3.00 per million = $0.0159 plus 300 × $15.00 per million = $0.0045, so $20.40 per 1,000, with 0.3 s for search and 0.5 s + 300 / 60 = 5.5 s to generate. Reranking takes 0.2 s, inside this page's 100 to 300 ms range, on a GPU we assume costs $2.50 per GPU-hour: 0.2 / 3,600 × $2.50 ≈ $0.14 per 1,000. Compression runs four small-model calls in parallel, each reading 520 tokens and writing 80: 4 × (520 × $0.15 + 80 × $0.60) per million ≈ $0.50 per 1,000, taking 0.5 s + 80 / 150 ≈ 1.0 s. With only 620 input tokens the large-model call drops to $6.36 per 1,000, for $7.00 in total.
Reranking alone cuts the cost per answer by about 43%, and adding compression takes it to about two thirds when the baseline sends many long chunks, but each stage adds latency, so if your baseline already sends 3 to 5 short chunks the savings shrink and only the relevance gain remains.
What are the common pitfalls?
Reranking models have their own biases. They can prefer longer chunks over shorter ones, favor formal language over casual documentation, or struggle with domain-specific terminology they were not trained on. If you use a general-purpose reranker on a highly specialized corpus, the reranking might make things worse.
Contextual compression can remove important context. If a chunk says "unlike the previous approach, this method uses connection pooling," the compression step might extract "this method uses connection pooling" and drop the contrast with the previous approach. That lost context can change the meaning of the extracted passage.
If your metadata filters are too aggressive, you might filter out the only chunk that contains the answer. A strict recency filter will drop older documents that are still accurate. A strict source filter might exclude community-written content that happens to have the best explanation.
Stacking too many postprocessing steps creates a pipeline that is hard to debug. When the final answer is wrong, you need to trace back through compression, reranking, filtering, and retrieval to find where the relevant information was lost. Each step is a potential point of failure.
What are the trade-offs?
Reranking adds latency and requires hosting or calling an additional model. Cross-encoder models are more expensive to run than bi-encoder retrieval because they process the query-document pair together rather than using pre-computed embeddings. For high-throughput systems, this cost adds up.
Compression reduces the information available to the LLM. That is usually the goal, but it means you are making an irreversible decision about what is relevant before the LLM sees the content. If the compression model gets it wrong, the LLM has no way to recover.
The overall engineering cost is moderate. Reranking is a well-understood pattern with good library support. Compression and disambiguation require more custom work. The testing and evaluation burden increases because you now need to measure quality at multiple pipeline stages as well as at the final output.
The biggest trade-off is complexity versus quality. A simple retrieve-and-generate pipeline is easy to build, easy to debug, and easy to explain. Each postprocessing step improves answers and makes the system harder to maintain. Add them incrementally and measure the impact of each one independently.
Goes Well With
Hybrid Retrieval improves the initial retrieval step. Better input to postprocessing means better output. HyDE and query expansion feed higher-quality candidate sets into the reranking stage.
Basic RAG is the foundation pipeline that postprocessing extends. Understanding the baseline helps you identify where postprocessing adds value and where it does not.
Grounded Generation builds on clean retrieval results. Accurate citations and hallucination detection work much better when the chunks reaching the LLM are relevant and well-compressed.
References
- Nogueira, R., & Cho, K. (2019). Passage Re-ranking with BERT. arXiv preprint. arXiv