RAGEngineering Hub
Chapter 4 · concept 6 of 6 · show all
  1. 1What RAG is, and why
    1. 1.1Why models need outside knowledge, and what hallucination means
    2. 1.2What RAG is: anatomy of a request
    3. 1.3RAG vs fine tuning vs long context and prompt caching
    4. 1.4Use cases and the quality, latency and cost triangle
    5. Chapter overview
  2. 2Tokens, cost and your first RAG
    1. 2.1Tokens and context windows for RAG
    2. 2.2The RAG lifecycle and your first RAG in miniature
    3. Chapter overview
  3. 3Getting documents in
    1. 3.1Content sources and file formats
    2. 3.2Parsing, layout and OCR
    3. 3.3Tables, images and mixed content
    4. 3.4Cleaning, normalization and quality gates
    5. 3.5Metadata, document identity and versioning
    6. 3.6Updates, deletes, reindexing and ingestion pipelines
    7. Chapter overview
  4. 4Chunking
    1. 4.1Why we chunk, and the main chunking strategies
    2. 4.2Structure aware chunking and tables
    3. 4.3Chunk size, overlap and token based sizing
    4. 4.4Contextual chunking and late chunking
    5. 4.5Parent child and multi representation indexing
    6. 4.6Chunk metadata, provenance and the chunking debugging playbook
    7. Chapter overview
  5. 5Embeddings
    1. 5.1Embeddings and similarity from first principles
    2. 5.2What embeddings cannot do
    3. 5.3Choosing an embedding model: size, cost, language
    4. 5.4Embedding model migration and index rebuilds
    5. Chapter overview
  6. 6Vector stores and scores
    1. 6.1Vector databases, ANN indexes and choosing a store
    2. 6.2Score calibration and thresholds
    3. 6.3Late interaction and multivector retrieval
    4. Chapter overview
  7. 7Finding the right chunks
    1. 7.1Query understanding, rewriting and expansion
    2. 7.2Dense retrieval and keyword search with BM25
    3. 7.3Hybrid retrieval and rank fusion
    4. 7.4topK, no good match, and metadata filtering
    5. 7.5Routing, diversity, deduplication and caching
    6. 7.6Reranking: two stage, cross encoder and LLM rerankers
    7. Chapter overview
  8. 8When retrieval fails
    1. 8.1Retrieval failure analysis playbook
    2. Chapter overview
  9. 9Building the answer
    1. 9.1Context selection, packing and citations
    2. 9.2Grounding prompts and abstention
    3. 9.3Lost in the middle and context management
    4. 9.4Conflicts, staleness and freshness rules
    5. 9.5Hallucination checks and answer verification
    6. 9.6Conversational RAG, answer UX and RAG APIs
    7. Chapter overview
  10. 10Measuring
    1. 10.1Why measure, and what to measure
    2. 10.2Building a golden dataset
    3. 10.3Retrieval metrics: precision, recall, MRR, nDCG
    4. 10.4Faithfulness and answer correctness
    5. 10.5LLM as judge, and judging the judge
    6. 10.6Offline and online evals, regression tests and slices
    7. Chapter overview
  11. 11Safety and operations
    1. 11.1Prompt injection and poisoned documents
    2. 11.2Access control, privacy and governance
    3. 11.3Index lifecycle operations
    4. 11.4Observability and tracing
    5. 11.5Latency, cost, caching and model routing
    6. 11.6Reliability, degraded modes and launch readiness
    7. Chapter overview
  12. 12Scale and advanced RAG
    1. 12.1Scaling, multi tenancy and enterprise architecture
    2. 12.2Choosing an architecture: naive, advanced, agentic, graph
    3. 12.3Agentic RAG and RAG as an MCP tool
    4. 12.4GraphRAG, structured data and multimodal RAG
    5. Chapter overview

Chunk metadata, provenance and the chunking debugging playbook

What to store with every chunk so you can cite, filter and update it, and a step by step way to find out why a question was missed.

A real question

A test question failed. Was it the chunk size, the search, or the document?

Check four things in order: is the answer in the corpus, is it whole in one chunk, was that chunk found, and was it ranked high enough. Metadata on every chunk makes each check quick.

The problem

Why this matters

An answer was missed, so change the chunk size.
The belief

An answer was missed, so change the chunk size.

Across all 16 settings, cut answers only happened with small fixed chunks. Every other miss was the right chunk ranked too low, which a new size will not fix.
What really happens

Across all 16 settings, cut answers only happened with small fixed chunks. Every other miss was the right chunk ranked too low, which a new size will not fix.

Why not the simpler way

The simple chunk is a string and a vector. It searches fine, but when something goes wrong you cannot answer basic questions: which document and version did this come from, which section, is it still valid, may this user see it? And when a golden question fails, you cannot tell whether the cut, the ranking or the document was to blame.

The idea

The idea in plain words

Every chunk should carry its provenance: where it came from and in which state. With that, you can cite, filter, update and debug. Debugging then becomes a checklist instead of a guess: is the answer in the corpus, was it kept whole by the chunker, was it retrieved, and was it ranked high enough?

A museum label tells you the artist, the year, the room and the loan status. Without it, a painting is just a picture.

How it works

Step by step

  1. Search the raw documents for the answer text. If it is missing, the problem is ingestion.
    1

    Is the answer in the corpus?

    Search the raw documents for the answer text. If it is missing, the problem is ingestion.

  2. If no chunk holds the whole answer, the cut split it: fix size, overlap or strategy.
    2

    Is it whole in one chunk?

    If no chunk holds the whole answer, the cut split it: fix size, overlap or strategy.

  3. Just below the top 3: try hybrid search or reranking. Far down: look at the wording of question and chunk.
    3

    What rank did it get?

    Just below the top 3: try hybrid search or reranking. Far down: look at the wording of question and chunk.

In detail

Store with every chunk: document id, version, file or URL, section path, character or page span, chunk index, content hash, effective dates, access labels, language and the chunker settings that made it.

The playbook for a missed question:

  1. In the corpus? Search the raw documents for the evidence text. If it is missing, it is an ingestion problem.
  2. Whole in one chunk? If no chunk contains the evidence, the cut split it. Fix the chunker, size or overlap.
  3. Retrieved at all? Find the chunk's rank. If it is far down, look at the question and chunk wording, then try hybrid search or a contextual header.
  4. Ranked below k? If it is just below the cut-off, try reranking or a slightly larger k, and measure the cost.

The code

Try it in Python

def diagnose(q, corpus_text, chunks, ranked_ids, k=3):
    """Classify why a golden question missed, in playbook order."""
    if q["evidence"] not in corpus_text:
        return "not in corpus: ingestion problem"
    holders = [c["id"] for c in chunks if q["evidence"] in c["text"]]
    if not holders:
        return "split: no chunk holds the whole answer"
    rank = min(ranked_ids.index(h) for h in holders)
    return "hit" if rank < k else f"ranked low: best holder at rank {rank + 1}"

See it

What we measured

Measured · misses by cause, 47 golden questions

All 16 precomputed settings, vector search with bge-small-en-v1.5, top 3. Split: no chunk holds the whole evidence. Ranked low: a chunk holds it but ranks below 3.

Fixed 128, no overlap: 6 split, 5 ranked lowbaseline11 misses
Fixed 128, 15% overlap: 0 split, 9 ranked low119 misses
Recursive 512: 0 split, 3 ranked low113 misses
All 13 other settings-1 split in total

Measured 2026-11-03 with the Chunk Lab logic. Splits happened only in fixed windows of 128 and 256 tokens without overlap. Every other miss was a ranking problem, so after a sensible chunk size the next gains come from retrieval, not from cutting.

Try it on a real example

Diagnose a real miss: “How much notice is given for a price change during a fixed term?” (recursive 512, vector search)

Check

Tariff sheet 2026.1

Price changes during a fixed term are announced at least 30 days in advance by e-mail.

Yes. Ingestion is fine.

Choosing

Use it when, avoid it when

Use it when
  • Provenance on every chunk: id, version, span, hash, dates, access
  • The four-step playbook on every failed golden question
Avoid it when
  • Chunks stored as bare text and vectors
  • Changing chunk size to fix what is really a ranking miss

What it costs · A few hundred bytes of metadata per chunk, and logging per evaluation run. Small next to the time it saves on the first incident.

In production

Log the chunk ids and ranks for every golden question in every evaluation run, and keep them next to the score. When a number drops after a change, you can diff which questions moved and why. Use the content hash to detect which chunks really changed on a re-index, and the effective dates and access labels as filters at query time.

Watch out

Common mistakes

  • Misses mean the chunk size is wrong. Here, most misses were ranking misses.
  • Overlap is a safe default. It fixed splits and created more ranking misses.
  • Metadata is only for filters. It is also how you cite, update and debug.

Check yourself

Remember this

Remember these

  • Store provenance on every chunk: document, version, span, hash, dates, access.
  • Diagnose misses in order: in corpus, whole, found, ranked high enough.
  • Overlap on 128 token chunks turned 6 cut answers into 0, but ranking misses rose from 5 to 9.
  • Log chunk ids and ranks per test question, so you can compare runs.

Say it in an interview

  1. 01Every chunk carries provenance: document, version, span, hash, dates and access labels.
  2. 02My playbook for a miss: in the corpus, whole in a chunk, retrieved, ranked high enough.
  3. 03Across 16 settings, splits only happened in small fixed windows; the rest were ranking misses.
  4. 04Overlap on fixed 128 turned 6 splits into 0 but raised ranking misses from 5 to 9.
  5. 05I log chunk ids and ranks per golden question so I can diff runs after a change.

Quick quiz

Three questions

Question 1

Q1

Across all 16 chunk settings, what caused most misses?

Question 2

Q2

Adding 15% overlap to fixed 128 changed the misses how?

Question 3

Q3 · from RAG-15

What does evidence recall check that document recall does not?

Saved on this device. No account needed.