Notes

Retrieval Step (RAG)

Everything before this point is preparation: documents were split into chunks, embedded, and written into an index. The retrieval step is the moment the question arrives and the system goes and fetches — the one part of a RAG pipeline that runs fresh for every query, under the user's patience.

What actually happens
  • The query is turned into whatever the index understands — an embedding vector for dense search, weighted terms for BM25, or both for hybrid search.
  • The index is searched for nearest neighbours, almost always approximately: HNSW or IVF trade a sliver of recall for a hundredfold speedup.
  • Filters are applied — tenant, date, access rights — before or during the search, which is a correctness requirement, not a nicety.
  • A top-k of candidates comes back with scores, ready for reranking and context synthesis.
Why it decides answer quality

A generator cannot use what it was never shown. If the right chunk is not in the top-k, the model has two options and both are bad: refuse, or fill the gap from parametric memory and sound confident doing it. This is why recall@k is the metric that matters here rather than precision — a wrong passage can be filtered out downstream, a missing one cannot be recovered. It is also where latency concentrates: a few tens of milliseconds is the budget, because it is spent before the first token is generated.

Tuning it is unglamorous and high-yield: k, chunk size, the embedding model, and whether a keyword leg is needed for the names and part numbers that dense vectors blur together.

The retrieval step is the query-time stage of a RAG pipeline that converts the user's question into a search against the prepared index and returns the top-ranked chunks. It is the only stage that runs per request, so it carries both the latency budget and the recall risk: a passage missed here cannot be recovered later, leaving the generator to answer from memory. Getting k, filters and search type right matters more than model choice.

Think of a student who is allowed to bring notes into an exam. Before the exam, the notes were written and organised — that part is done well in advance. The retrieval step is the moment the question is read and the student flips to the right page. It happens live, while you wait, and it takes a second or two. Everything hangs on it: if the student turns to the wrong page, the answer will be wrong too, no matter how clever they are. That is why most of the effort in these systems goes into making the flipping accurate.