Chapter 7: Context

Sometimes the text is too big to read and you don't know where the answer is, so a search system picks for you.

Retrieval (RAG)

Also called Retrieval-augmented generation, BM25

Searching a body of text, taking the top matches and putting them in the prompt so the model answers from them. Keyword search (BM25 is the standard scoring formula) finds exact words. Embeddings find related meaning. Each misses what the other finds.

The model sees only what came back, so a missed page may as well not exist, and the answer still sounds sure. For code, the leading agents have moved towards searching live. For big piles of documents nobody can grep usefully, retrieval still earns its place, if you measure it.

Say it to your agent

“Search docs/ with rg first. If we build retrieval, measure it: write 20 real questions, each with the document that answers it, and report how many of those documents appear in the top 5, for BM25 alone and for BM25 with embeddings.”

The workshop

Name a word, or describe what you mean in everyday language.