Lesson 9.5core4 h⚡ live demo

Retrieval quality: hybrid search, reranking, query transforms and metrics

Getting the right chunks to the top, and proving it

Retrieval quality is the ceiling on everything a RAG system does (9.1 Why RAG, and the canonical pipeline), and it is improvable in measurable steps: lexical plus dense search fused by rank, a cross-encoder reranker, and cheap query rewrites before search. This lesson derives BM25 term by term, gives you reciprocal rank fusion and the three retrieval metrics with a worked example, and shows how to build the test set that turns retrieval tuning from guesswork into engineering.

You'll be able to

  • Explain the BM25 formula term by term and contrast it with TF-IDF and dense retrieval
  • Fuse rankings with reciprocal rank fusion and know when score interpolation is better
  • Place cross-encoder, ColBERT and LLM rerankers in a pipeline with their cost profiles
  • Choose query transformations (rewriting, multi-query, HyDE, step-back, decomposition, routing) from observed failure modes
  • Compute recall@k, MRR and nDCG by hand and build a retrieval test set

Key ideas

  1. Dense retrieval matches meaning and misses exact identifiers; lexical retrieval is the mirror image — hybrid search beats either alone, especially on jargon-heavy corpora.
  2. BM25 = Σ IDF(t) · f(k₁+1) / (f + k₁(1 − b + b·|D|/avgdl)): term-frequency saturation (k₁), length normalization (b) and rarity weighting (IDF).
  3. Reciprocal rank fusion RRF(d) = Σ_r 1/(60 + rank_r(d)) merges rankings without calibrating scores; documents liked by both systems rise.
Show 4 more key ideas
  1. Rerank the top 50–100 with a cross-encoder (or ColBERT/LLM reranker) to turn recall into precision; it is the most reliable upgrade after hybrid search.
  2. Query transformations — rewriting, multi-query, HyDE, step-back, decomposition, routing — fix vocabulary mismatch and multi-hop questions at the cost of an extra LLM call.
  3. Recall@k is the ceiling metric, MRR rewards the first hit's rank, nDCG handles graded relevance with a log₂ position discount.
  4. A versioned retrieval test set of 50–200 labelled queries, grown from real failures, is what makes every retrieval change measurable.

Suggested path through this lesson