Retrieval-Augmented Generation

Retriever + generator: how to build it, measure it and fix it.

Reference · Chapter 6 (RAG)

Shape

Retrievers

Term-based (TF-IDF, BM25)Embedding-based
MatchesWordsMeaning
StrengthFast, cheap, strong baseline; exact codes and namesParaphrases and natural queries; improvable by finetuning
WeaknessSynonyms; ambiguous termsExact strings; cost (embedding, storage, ANN search)

Hybrid search: in sequence (cheap fetch → precise rerank) or in parallel (reciprocal rank fusion: Σ 1/(k + rank), k ≈ 60).

Measure

Fix

SymptomTactic
Exact codes or names missed by embeddingsHybrid search
Facts cut at chunk boundaries; chunks too big or smallChunking: recursive splits, overlap, tune size
Too many candidates; stale resultsReranking (precision or recency)
Follow-ups like “How about Emily?”Query rewriting
Chunks lack their document's context; users phrase things differently from the docsContextual retrieval: add tags, questions answered, a 50–100-token summary

Beyond text

← Lesson 6EvaluationGlossary

Related ideas