Reranking Retrieved Results
Retrieve broadly, then use a cross-encoder or LLM reranker to put the truly relevant chunks at the top before generation.
Intermediate · about 3 hours · difficulty 3/5
Learn first: Hybrid Search: Keywords Plus Vectors
First-stage retrieval (vector or hybrid) is fast but coarse. A reranker takes the query plus, say, the top 50 candidates and scores each pair carefully, then you keep the best 5 to 10 for the prompt.
Why rerankers are more accurate
Embedding models encode query and document separately (bi-encoders), so they cannot compare them word by word. Cross-encoder rerankers read the query and the chunk together, which captures fine-grained relevance at the cost of more compute per pair. That is why they are only applied to a shortlist.
Options
- Hosted rerank APIs (for example from Cohere, Voyage, Jina).
- Open cross-encoder models via sentence-transformers or other open rerankers, run locally.
- LLM-as-reranker: ask a small model to score or order candidates. Flexible, slower and pricier.
Tuning
- Candidate count (retrieve 20 to 100) versus latency.
- Final k: fewer, better chunks often produce better answers than many mediocre ones.
- A minimum relevance score to drop junk and let the model say "not found".
Pitfalls
Rerankers add latency (tens to hundreds of milliseconds). Measure end-to-end impact; if first-stage retrieval never finds the right chunk, reranking cannot help.
Good enough to move on
You can add a reranker to your pipeline and show improved precision in the top results on your test questions.
Key concepts
- Bi-encoders vs cross-encoders
- Hosted rerank APIs
- Open-source cross-encoders
- LLM-based reranking
- Candidate count and final k
- Relevance thresholds
Mini project
Add a cross-encoder reranker over the top 30 hybrid results in your RAG app, and measure precision at 5 and latency before and after.
Check yourself
Why not simply use a cross-encoder to score every document in the corpus?
Free resources
- Sentence Transformers: cross-encoders (SBERT)
- Cohere docs: rerank (Cohere)