RAG Done Right: Retrieval Before Generation

Most 'the model hallucinated' complaints in RAG systems are retrieval failures. Fix chunking, ranking, and grounding first — the generation step is rarely the weakest link.

Last reviewed Jul 7, 2026

The checklist

  • Chunk by document structure (headings, sections), not by fixed character counts; keep titles and breadcrumbs attached to every chunk.
  • Use hybrid retrieval (BM25 + embeddings) with a reranker; embeddings alone miss exact identifiers, names, and codes.
  • Evaluate retrieval separately from generation — recall@k on a labeled set — before touching prompts.
  • Force grounding: instruct the model to answer only from retrieved context and to say 'not found' otherwise; require citations.
  • Store chunk metadata (source, date, permissions) and filter at query time — freshness and access control are retrieval features.
  • Log every query with retrieved chunks and outcome; failed answers become tomorrow's test set.

1. Chunk along the document's own structure

Do: Split on headings/sections with sensible size bounds, prepend the document title and section path to each chunk, and keep tables and code blocks intact.
Don't: Slice every document into blind 512-character windows that cut sentences, split tables, and orphan pronouns.

Why: A chunk that carries its own context ('Refund policy > Enterprise plans') retrieves and reads correctly in isolation; a blind window does neither.

2. Retrieve hybrid, then rerank

Do: Combine lexical search (BM25) with vector similarity, merge candidates, and apply a cross-encoder reranker to pick the final few chunks.
Don't: Rely on cosine similarity alone, especially for queries containing part numbers, error codes, names, or rare terms.

Why: Embeddings capture meaning but blur exact tokens; lexical search is the opposite. Production QA corpora consistently show hybrid+rerank beating either alone by large recall margins.

3. Measure retrieval on its own

Do: Build a labeled set of question → relevant-chunk pairs and track recall@k and reranker hit rate as you tune chunking and indexing.
Don't: Judge the whole pipeline by final answer quality and guess which stage failed.

Why: If the right chunk isn't in the top-k, no prompt can save the answer. Separating the metrics tells you whether to fix the index or the prompt — they are different weeks of work.

4. Make grounding non-negotiable

Do: Instruct the model to answer strictly from the provided context, to cite chunk IDs, and to reply 'not in the knowledge base' when retrieval comes back weak.
Don't: Let the model quietly blend its pretraining knowledge with retrieved facts.

Why: The blend is where confident wrong answers come from — stale prices, deprecated APIs, invented policy details delivered in a trustworthy tone with a real-looking citation.

5. Treat freshness and permissions as query-time filters

Do: Attach source, updated-at, and access-control metadata to every chunk; filter by user entitlement and prefer recent versions at query time; re-index on document change.
Don't: Build one flat, permissionless index of everything and re-embed the corpus once a quarter.

Why: The two worst RAG incidents in practice are leaking a document to the wrong user and answering from a superseded version. Both are metadata problems, not model problems.

6. Close the loop with query logs

Do: Log question, retrieved chunks, answer, and user feedback; review the worst sessions weekly and convert them into labeled eval cases.
Don't: Ship the pipeline and only revisit it when complaints arrive.

Why: Real user queries are unlike your test questions. The log is a free, perfectly representative eval set that compounds in value.

Set up before you start

clone or study these first

The 80/20 of RAG

When a RAG system gives a wrong answer, instrumented pipelines show the failure lives in retrieval most of the time: the right passage was never fetched, was fetched but ranked below the cutoff, or was chopped so badly it no longer contained the fact. Generation — the model actually misreading a good chunk — is the minority case.

That ordering dictates the work: structure-aware chunking and hybrid retrieval with reranking are the highest-leverage changes, retrieval-only metrics tell you when you’re done, and grounding instructions plus citations contain whatever errors remain. Token cost matters here too — reranking lets you send 4 good chunks instead of 20 mediocre ones, which is also a direct saving (see the token optimization playbook).

What changed in this playbook

  • First edition.