Reranking
Cross-encoders and LLM judges that reorder top-k candidates for higher precision.
In plain words
A fast search finds a pile of maybe-relevant passages, and a slower, smarter judge reads each one next to the question and puts the best ones on top.
Think of it like…
A recruiting funnel: a quick keyword screen shortlists 50 CVs from thousands (fast, rough), then a senior interviewer reads each shortlisted CV against the job description (slow, careful) and picks the best five.
Where you’ve seen it
A contract assistant's hybrid retrieval returns the correct clause within the top 50 for 97 percent of questions but within the top 5 only 71 percent of the time. Adding a cross-encoder reranker over the top 50 raises top-5 hit rate to 90 percent and answer accuracy from 74 to 84 percent. Latency rises by 180 ms on a GPU-hosted model, which fits their 2-second budget; they cap candidate text at 512 tokens each to control cost.
Words you’ll hear
- Bi-encoder
- Embeds query and document separately; fast, precomputed, approximate.
- Cross-encoder
- Scores (query, document) jointly; more accurate, can't be precomputed.
- Candidate depth
- How many first-stage results are passed to the reranker (e.g. 30–100).
- Listwise reranking
- An LLM orders a whole list of candidates in one prompt.
Visual diagram
Theory & deep dive
Why cross-encoders are more accurate
A bi-encoder compresses each document into a single vector before any query exists, so subtle relations between the query and specific words in the document are lost. A cross-encoder concatenates query and document and runs full self-attention over both, so every query token can attend to every document token: it can tell that "termination for convenience" in the query matches a clause about ending the contract without cause, or that a passage mentions the right term but negates it. The price: one forward pass per candidate per query, nothing precomputed, so latency and cost scale with candidate count.
Options: hosted rerank APIs (Cohere Rerank, Voyage rerank, Jina and similar), open models you host (the BGE-reranker family, mixedbread, Qwen-based rerankers, ms-marco cross-encoders), and LLM-based reranking (pointwise: score each candidate; listwise: order a list in one prompt), which is flexible and strong but slower and costlier. Late-interaction models such as ColBERT sit between bi- and cross-encoders, keeping token-level vectors for richer matching with precomputation.
pairs = [(query, chunk.text) for chunk in candidates]; scores = reranker.predict(pairs); top = [c for _, c in sorted(zip(scores, candidates), reverse=True)][:6] sends 50 pairs and keeps the six best.
Design choices and evaluation
Pick candidate depth from recall curves: measure first-stage recall@k for k = 10, 30, 50, 100 and choose the smallest k where recall plateaus near your target (often 30 to 100). Reranking more candidates costs latency linearly. Limit each candidate to what the model handles (often 512 tokens), batch requests, run on GPU or use a hosted API with parallelism, and set a timeout with fallback to the first-stage order. Choose the final cut-off (top 5 to 10) by answer quality and token cost; some systems also drop candidates below a score threshold, which needs calibration per model.
Evaluate with labelled queries: compare nDCG@10 and recall@5 with and without reranking, then end-to-end answer accuracy and citation correctness. Check for failure modes: long-document truncation cutting the answer, domain mismatch (a general reranker underperforming on legal or code text, which fine-tuning or a domain model can fix), position bias in LLM rerankers, and added latency at the tail (p95 rather than average). Rerankers can also enforce business logic such as freshness or authority boosts after relevance scoring.
First-stage recall: @10 = 78%, @30 = 93%, @50 = 97%, @100 = 98%. Depth 50 captures nearly all the gain; depth 100 doubles reranking cost for one more point.
How it works, step by step
Step 1 of 41. Measure first-stage recall by depth
Compute recall@k for several depths to see how many candidates the reranker needs.
- Choose
- knee of the curve
When to use it & trade-offs
What it is
Reranking is a second retrieval stage that reorders a short candidate list (say the top 50 from hybrid search) with a more accurate but slower model, then keeps the best 5 to 10. A cross-encoder reads the query and each candidate together in one forward pass and outputs a relevance score, which lets it model fine-grained interactions that a bi-encoder (separate query and document embeddings) can't. LLM-based rerankers (pointwise or listwise) do the same with a general model. First stage buys recall; reranking buys precision.
Why it matters: Fast retrieval is approximate: the right passage is often in the top 50 but not the top 5, and the LLM can only use a handful of chunks (and is distracted by irrelevant ones). A reranker is one of the highest-return additions to a RAG pipeline, typically lifting answer accuracy several points for tens to a couple of hundred milliseconds of latency. Choosing the candidate depth, model and cut-off is an important design decision.
When to reach for it
- RAG pipelines where the answer is in the top 50 but not the top 5
- Reducing prompt tokens by sending fewer, better chunks
- Applying business ranking rules after relevance scoring
When to avoid or be careful
- Reranking thousands of candidates per query
- Passing full long documents to the reranker without truncation
- No fallback when the reranker times out
Reranker options
Strengths: No GPUs; strong quality; simple integration.
Watch out: Per-request cost; data sent to a vendor; added network latency.
Strengths: Fixed cost; tunable; data stays in your environment.
Watch out: You run GPU inference.
Strengths: Flexible, instruction-following.
Watch out: Slowest and costliest; position bias; non-determinism.
Interview signals & numbers to know
When this topic comes up
- “The right passage is retrieved but ranked low”
- “Bi-encoder vs cross-encoder”
- “LLM answers are distracted by irrelevant chunks”
- Two-stage retrieval
- nDCG improvements
Benchmarks & rules of thumb
- 30 – 100
- typical candidates to rerank
- 5 – 10
- chunks usually kept for the LLM
- 100 – 300 ms
- typical added latency
Common mistakes & follow-ups
Common interview mistakes
- Reranking only the top 10 results, which can't recover answers ranked 15th.
- Using a reranker trained on web search for code or legal text without testing.
- Ignoring p95 latency and timing out under load.
Likely interviewer follow-ups
- Why is a cross-encoder more accurate than a bi-encoder?
- How do you choose how many candidates to rerank?
- When would you use an LLM as a reranker?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Reranking with generative AI interview Q&A and hands-on practice.