Bi-encoder retrieval is a compromise: one vector per chunk, fast ANN, approximate relevance. When your top-20 looks “related” but the answer paragraph sits at rank 14, generation never sees it. A reranker for RAG scores the query against each candidate jointly—usually with a cross-encoder—and reorders the list before you spend context tokens.
Reranking is not a substitute for hybrid search or good chunking. It is a precision stage: widen recall upstream, then spend compute to pick the passages the LLM should read. This guide covers model choices, latency budgets, failure modes, and how to measure lift without vanity metrics.
Why cross-encoders see what bi-encoders miss
Bi-encoders embed query and document separately. Similarity is a dot product or cosine over those frozen vectors. Cross-encoders read the pair together, allowing token-level interactions: negation, constrasting clauses, and “almost the same topic but wrong entity” cases. That accuracy costs latency—you cannot cross-encode millions of chunks per query—so production systems retrieve a shortlist first.
Typical pattern: retrieve 20–100 candidates via dense, sparse, or hybrid search RAG; rerank; keep top 3–8 for the prompt. If your shortlist never contained the answer, the reranker cannot invent it. Fix recall upstream with chunking and hybrid retrieval before blaming the cross-encoder.
Hugging Face hosts many reranker checkpoints under sentence-transformers and related orgs; start from maintained model cards rather than random uploads. Cohere, Jina, and others offer hosted rerank APIs when you prefer not to operate GPUs. Pick based on latency SLO, data residency, and whether you need to fine-tune on proprietary click or judgment data.
Where rerankers sit in the pipeline
Place reranking after fusion and filters, before parent expansion and prompt packing. Filtering first avoids spending cross-encoder calls on unauthorized or wrong-version docs. Expanding parents after rerank preserves the ranking signal on the precise child while giving the LLM surrounding context—pair with RAG chunking strategies that store parent ids.
Some stacks rerank twice (cheap model then expensive model) or use LLM-as-reranker for tiny candidate sets. LLM reranking is flexible and slow; reserve it for high-value queries or offline evaluation, not every autocomplete keystroke. For architectural context, see how this stage fits advanced RAG architecture.
| Stage | Job | Cost profile |
|---|---|---|
| Retrieve | High recall candidate set | ANN / BM25, cheap per doc |
| Filter | ACL, version, locale | Metadata, near-free |
| Rerank | Precision ordering | Cross-encoder, GPU/API |
| Assemble | Parents, dedupe, order | CPU, token accounting |
| Generate | Answer + citations | LLM tokens |
Latency, batching, and when to skip
Cross-encoders scale with candidates × query. Batch inferences, truncate long passages to the model’s max length, and cache results for identical (query, chunk_id, model_version) triples when your traffic has repeats. If p95 latency already burns the budget on generation alone, try fewer candidates, a distilled reranker, or rerank only when the top dense score margin is weak (uncertainty-triggered rerank).
Skip reranking when the corpus is tiny and top-3 from hybrid is already correct on your gold set, or when the product is exploratory search with a human scrolling results. Always rerank when context slots are scarce and wrong neighbors cause confident hallucinations.
Prompt design still gates outcomes: a perfect ranking ignored by a vague system prompt wastes money. Tie evidence blocks to citation rules in the prompt engineering guide.
Training signals and domain adaptation
Off-the-shelf rerankers trained on web search or MS MARCO-style data transfer reasonably to technical docs but can stumble on internal jargon. Collect hard negatives from your own retrieval logs: passages that ranked high but were marked irrelevant by reviewers. Fine-tune with pairwise or listwise losses if you have volume; otherwise, prefer prompting-free off-the-shelf models and invest in better candidates.
Do not train on the same LLM judge scores you use as the only production metric without a human audit sample—you will overfit to the judge’s quirks. Mix human labels, click/dwell signals (carefully, with position bias awareness), and offline metrics from RAGAS RAG evaluation.
Failure modes unique to rerankers
- Shortlist miss: answer never retrieved; reranker reshuffles noise. Widen or hybridize upstream.
- Length bias: some models prefer longer passages. Normalize or truncate consistently.
- Near-duplicate obsession: top ranks are restatements of one section. Add diversity (MMR) after scores.
- Stale model vs new chunker: chunk ids change meaning after re-ingestion; invalidate caches and re-eval.
- Over-trusting scores: absolute cross-encoder scores are not calibrated probabilities—use ranks and margins, not fake confidences in the UI.
Rerankers also interact with knowledge freshness: a beautifully ranked obsolete policy is still wrong. Coordinate index updates with agent knowledge freshness practices. When the right move is a live tool instead of a passage, route out of RAG via patterns in MCP vs API function calling and the broader RAG vs fine-tuning vs agents decision guide.
Diversity after scores: MMR and neighbor collapse
Raw cross-encoder scores happily promote five paraphrases of the same paragraph. The LLM then wastes half its context repeating one idea while a secondary supporting fact never appears. Maximal marginal relevance (MMR) and simple embedding-distance dedupe after rerank keep the top score winner, then prefer candidates that are both relevant and dissimilar to what is already selected.
Tune the diversity lambda on multi-aspect questions (“pricing and cancellation”). Too much diversity can demote the single authoritative policy section in favor of loosely related blog posts. Log both the pre-diversity and post-diversity lists during debugging so you can see whether a bad answer came from ranking or from over-aggressive dedupe.
Parent expansion interacts here: if three children map to one parent, expand once and drop sibling children. That rule alone removes a large class of near-duplicate contexts without hurting recall of the underlying section.
Measurement that justifies the GPU bill
Compare pipelines with and without rerank on the same candidate generator. Report nDCG or MRR on labeled query–passage pairs, plus end-to-end answer faithfulness and citation accuracy. If ranking metrics rise but answer metrics flatline, your bottleneck is generation or chunk content—not order.
Store retriever_version, reranker_model, and candidate_k in traces so regressions are attributable. Vector store choice affects how easily you fetch wide candidate lists; see vector databases for AI. Embedding quality remains foundational—what embeddings are in AI—because rerankers inherit the candidate set those embeddings propose.
Useful external starting points: Hugging Face sentence-transformers documentation on cross-encoders / reranking, and vendor rerank API docs (Cohere Rerank, Jina Reranker). Read model cards for max sequence length and recommended candidate counts.
FAQ
What is a reranker for RAG?
A model—often a cross-encoder—that scores each retrieved passage against the query and reorders candidates so the most relevant evidence fills the limited context sent to the generator.
How many candidates should I rerank?
Common production ranges are 20–100 depending on latency. Start at 50 for doc QA, measure p95, and reduce until quality drops on your gold set.
Can I use an LLM instead of a cross-encoder?
Yes for small lists or offline judging. For high QPS, specialized rerankers are usually cheaper and more stable than full generative models.
Does reranking replace hybrid search?
No. Hybrid improves which documents enter the shortlist; reranking improves order within that shortlist.
Why did reranking hurt my answers?
Possible causes include length bias, duplicate-heavy tops, truncating away the answer span, or a domain mismatch. Inspect swapped ranks on failure cases before swapping models blindly.
Should every query pay for a reranker?
Not necessarily. Uncertainty triggers, tiered models, or skipping when the top score margin is huge can preserve quality for hard queries while saving budget on easy ones.
AI Generated Apps AI Code Learning Technology

One comment
Pingback: Parent Document Retrieval for RAG Context