Lesson 2.4 · 8 min read · about 55 min to master at a very slow pace
Hybrid Search and Reranking
Combine keyword and semantic search with reciprocal rank fusion, then rerank the best candidates with a cross-encoder. The two-stage retrieval design most production RAG systems use, with RRF worked by hand.
Hybrid search
Run both searches for every query: keyword (BM25) for exact terms and codes, vector search for meaning. Each returns a ranked list. You then need to merge them, but their scores are on different scales (a BM25 score of 12.4 and a cosine of 0.81 cannot be added).
Reciprocal rank fusion
RRF ignores raw scores and uses only ranks. A document's fused score is
with a constant , usually 60. A document ranked high in both lists beats one ranked first in only one.
Worked example ()
| Chunk | BM25 rank | Vector rank | RRF score |
|---|---|---|---|
| A | 1 | 4 | 1/61 + 1/64 ≈ 0.03202 |
| B | 2 | 2 | 1/62 + 1/62 ≈ 0.03226 |
| C | — | 1 | 1/61 ≈ 0.01639 |
B, second in both lists, wins narrowly over A. C, top of one list but missing from the other, comes last.
Reranking
Embeddings compare the query and a chunk separately (a bi-encoder): fast, because chunk vectors are computed in advance, but coarse. A cross-encoder reranker reads the query and a chunk together and outputs a relevance score. It is much more accurate and much slower, so it is used on a short list only.
The two-stage design
- Retrieve broadly and cheaply: hybrid search for the top 30–100 candidates.
- Rerank those candidates with a cross-encoder.
- Send the top 3–8 to the LLM.
Why this works
Stage 1 cares about recall: is the right chunk anywhere in the candidates? Stage 2 cares about precision: are the few chunks we send the best ones? Measure each stage separately (Section 5) and you know which to fix.
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passWhy is the constant in RRF 60?
It is an empirical default from the original paper that works well across many datasets. A larger flattens the difference between top ranks; a smaller one rewards first place more. It is rarely worth tuning before everything else.
Going deeperIs reranking worth the extra latency?
Usually, when the LLM only sees a few chunks: better chunks mean better answers and fewer tokens. Reranking 50 short candidates adds roughly 100–300 ms. Check on your eval set whether precision in the top 5 actually improves enough to justify it.
Cheatsheet
Reciprocal rank fusion
Bi-encoder vs cross-encoder
Two-stage retrieval
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.