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.

Not startedJump to quiz

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 ()

ChunkBM25 rankVector rankRRF score
A141/61 + 1/64 ≈ 0.03202
B221/62 + 1/62 ≈ 0.03226
C—11/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

  1. Retrieve broadly and cheaply: hybrid search for the top 30–100 candidates.
  2. Rerank those candidates with a cross-encoder.
  3. 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

, with . Uses ranks only, so scales don't matter.

Bi-encoder vs cross-encoder

Bi-encoder: embeds query and chunk separately, fast, for retrieval. Cross-encoder: reads both together, accurate, for reranking.

Two-stage retrieval

Hybrid search for 30–100 candidates (recall) → rerank → top 3–8 to the LLM (precision).

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateWith RRF and , a chunk is ranked 1st by BM25 and 3rd by vector search. What is its fused score?
Q2conceptWhy does hybrid search fuse ranks rather than add the raw BM25 and cosine scores?
Q3conceptWhat is the key difference between a bi-encoder and a cross-encoder?
Q4applyYou can afford to send 5 chunks to the LLM. How should the two-stage pipeline be set up?
Q5diagnoseYour evals show the right chunk is in the top 50 candidates 95% of the time, but in the 5 sent to the LLM only 60% of the time. What should you fix?