Skip to content

3.5 RAG Pipeline Design: Chunking and Indexing

A RAG pipeline answers from a document collection in stages: ingest, chunk, embed, index, retrieve, optionally rerank, generate. A chunk is a passage cut from a document. Embedding search compares chunks by meaning. Keyword search, such as BM25, matches exact tokens. Each stage has its own failure mode.

This lesson uses one made-up example throughout: a scaffolding firm whose assistant answers staff from its inspection procedures, hire terms and parts catalogue. Retrieval quality limits generation quality. If the right passage never reaches the context, the best model can only guess. When an earlier stage fails to bring the right passage into the context, the failure appears as hallucination in the answer. Design works stage by stage, and so does diagnosis.

A chunk is the unit that retrieval finds. A chunk that is too small loses needed context. For example, a table split from its caption, or a clause split from its heading, becomes unfindable or misleading. A chunk that is too large lowers relevance and spends tokens on text that is not needed. A whole-document chunk matches everything weakly. Structure-aware chunking respects sections, headings and tables. With a modest overlap to guard against losses at chunk boundaries, it performs better than fixed-size splitting. The meaning is in the structure, so the firm keeps each hire-terms clause with its heading.

The chunk “the company’s revenue grew 3%” is unfindable until it says which company and which quarter. Many retrieval failures have that root cause: context that is lost at the chunk boundary. Before embedding and indexing, contextual retrieval adds a short explanation to the start of each chunk. The explanation is specific to that chunk and places it in its document. The firm’s chunk “re-inspect after high winds” gets the name of its procedure. Anthropic’s published benchmark shows that contextual retrieval measurably reduces retrieval failures. The gains grow as contextual BM25 and reranking are added. The rule to remember is this: restore each chunk’s lost context before you index it.

Embedding search often misses exact strings. An exact error code needs BM25’s token match. A question such as “why does the sync fail overnight” needs semantic similarity. Corpora with identifiers, part numbers, error codes or clause references need hybrid indexing: embeddings plus keyword. Metadata filters (date, source, product) narrow the candidate set before similarity ranks it. Pure embedding search over an identifier-heavy corpus returns passages that are thematically similar but wrong, and no chunk tuning fixes this. The firm’s part-number catalogue needs both.

A RAG pipeline is a data system and needs data-system operations. At the firm, every procedure update must reach the index.

  • Refresh triggers re-embed and re-index, atomically. When documents are updated without a re-index, the index silently serves the old corpus. Answers cite outdated content with full confidence.
  • Pin the embedding-model version everywhere. A corpus embedded with one model and queried with another degrades silently. No errors are thrown, and retrieval is wrong.
  • Monitor retrieval quality. Recall on a labelled query set (Domain 4 covers the measurement) turns index breakage into an alert (objective 3.4), not something that users discover.
  • Evaluate retrieval separately from generation. A pipeline that can only be debugged end to end is expensive to debug. Separate measurement isolates a failure to one stage.

Retrieval is not the default. A corpus that is small and stable enough for the cached prompt is faster and cheaper to serve whole, and it has no retrieval failure. Domain 2’s decision about what belongs in the context comes before pipeline design. The first decision is whether the pipeline should exist. One short, stable document at the firm needs no pipeline.

The exam tests both design and diagnosis. Its favourite failure pattern comes from the guide’s own sample: confident wrong answers immediately after a document refresh. At the firm, the assistant quotes the old inspection procedure after an update. The right answer investigates the retrieval/indexing step first, because it is the stage most likely to return irrelevant or stale chunks.

The contextual retrieval benchmark figures and the current token threshold for cached prompts are dated. They are in the Domain 3 quick reference.

A support knowledge base of 40k articles serves a RAG assistant. After a bulk content migration, answers cite outdated procedures confidently; latency and model are unchanged. What should the team do first?

  • A. Upgrade to a more capable model, since a stronger model should be better at recognising and discounting outdated procedures on its own
  • B. Verify the migration triggered re-embedding and re-indexing, and add retrieval-recall monitoring so index breakage alerts
  • C. Increase the number of retrieved chunks per query so the correct, current version of each article is more likely to be included
  • D. Lower the temperature setting so the assistant stops asserting outdated procedures with such confidence
Answer & explanation

Correct: B

  • A — The model is generating faithfully from what retrieval hands it; stale chunks in, confident stale answers out, whatever the model tier.
  • B — The failure signature (wrong-but-confident immediately after a refresh, everything else unchanged) points at the index serving pre-migration content. The fix is operational, and the monitoring stops the silent recurrence.
  • C — More chunks from a stale index means more outdated content in context; the failure amplifies rather than resolves.
  • D — Temperature shapes sampling variability, not grounding; the model would cite the stale procedures more consistently, not less.