Lesson 3: Dense, sparse, hybrid

Two retrievers with opposite blind spots, and the two-line formula that combines them.

~15 minutes. Builds on Lesson 2.

Two ways to match

Dense (embeddings)Sparse (BM25)
Scores byVector similarity between query and chunk embeddingsWeighted overlap of exact terms, rare terms weighing more[1]
FindsParaphrase and meaning: "cosy flat with outdoor space" matches "apartment with terrace"Exact tokens: "OMN-4812", "Kortrijksesteenweg 12", "EPC label B"
MissesIdentifiers, codes, names - embeddings smear rare exact tokensAny wording the document does not literally use

Real-estate queries arrive in both kinds, often in the same sentence. So run both.

Hybrid: fuse the two lists

Reciprocal rank fusion merges ranked lists using only ranks - no fragile score normalisation:[2]

RRF(d) = sum over lists L of  1 / (k + rank_L(d))     # k = 60 by convention

dense_list  = vector_search(embed(query), top=100)
sparse_list = bm25_search(terms(query), top=100)
candidates  = top_by_rrf(dense_list, sparse_list, top=100)

A document ranked 1st in one list and absent in the other scores 1/61; ranked ~30th in both scores ~2/90 - agreement between retrievers beats a single strong showing at depth. The constant k=60 flattens the curve so rank 1 does not drown everything; the paper found it deliberately insensitive.[2]

Two rules that prevent silent failure

  1. One embedding model for queries and chunks. Vectors from different models live in different spaces; similarity between them is noise. Changing embedding model means re-embedding the whole corpus.[3]
  2. Questions are not documents. "why did the Verhaeghe sale fall through" is shaped nothing like the CRM notes that answer it. When dense retrieval underperforms on question-shaped queries, rewrite: HyDE embeds a generated hypothetical answer instead of the question, so the query vector lands where answers live.[4]

Retrieval practice

From memory, before scrolling up.

Your win: shown any query, you can predict which retriever finds it, which one misses it, and write the RRF line that fuses them.

Primary source

Read the RRF paper - two pages, and you will never need to look the formula up again. BM25 background, when wanted: Robertson & Zaragoza via the free mirror in RESOURCES.md.

Want to sanity-check a fusion design against your actual query log? Bring examples to your teaching agent.