RAGEngineering Hub
Chapter 10 · 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

Offline and online evals, regression tests and slices

Run the golden set in CI and block changes that lose answers; split results by case type so a weak slice cannot hide in the average; and watch live traffic for what the golden set misses.

A real question

A change raises the total score. Is it safe to ship?

Not yet. Check per question and per slice: did any question stop working, did any kind of question get worse? Then watch live traffic, because users ask things the golden set never imagined.

The problem

Why this matters

If the total went up, ship it.
The belief

If the total went up, ship it.

Vector search scored 44 of 47 overall, which looks fine. By slice, conflict questions were 1 of 2 and plain answerable questions 15 of 17, while tables, versions and codes were perfect. The average hides where it breaks.
What really happens

Vector search scored 44 of 47 overall, which looks fine. By slice, conflict questions were 1 of 2 and plain answerable questions 15 of 17, while tables, versions and codes were perfect. The average hides where it breaks.

Why not the simpler way

A golden set used once is a report. Used on every change, it is a safety net. And the net has holes: real users ask in ways the set does not cover. Offline and online evaluation together catch most problems before or soon after users see them.

The idea

The idea in plain words

Offline evaluation runs fixed test cases on demand: fast, repeatable, cheap. Online evaluation observes real use: realistic, noisy, slower to read. Regression tests fail when something that worked stops working. Slices are subsets by case type, language, product or user role, reported separately.

Car makers run crash tests in the lab and also study real accidents. Each finds problems the other misses.

How it works

Step by step

  1. Run the retrieval checks on every pull request that touches chunking, embeddings, search or prompts. It takes seconds.
    1

    Golden set in CI

    Run the retrieval checks on every pull request that touches chunking, embeddings, search or prompts. It takes seconds.

  2. Fail the build if a question that passed now fails, or a slice drops below its bar. Print the diff.
    2

    Gate per question and slice

    Fail the build if a question that passed now fails, or a slice drops below its bar. Print the diff.

  3. 3

    Watch live traffic

    Feedback buttons, sampled human reviews, abstention and flag rates, and new failure cases added back to the golden set.

In detail

CI job. Rebuild the index for the changed config, run the golden set, compare with the stored baseline per question. Retrieval checks need no model calls; answer checks can run nightly or before releases.

Bars. A minimum per slice (for example, every exact-code question in the top 3) and a rule that no passing question may start failing without an explicit accept.

Online signals. Thumbs down rate and reasons, abstention rate, verification flags (RAG-37), latency and cost per question, and a weekly human review of a random sample.

Closing the loop. A bad live answer becomes a golden item with its evidence (RAG-40).

The code

Try it in Python

import json, sys

def gate(baseline_path: str, current: dict[str, dict], k: int = 3, bars: dict[str, float] | None = None):
    base = json.load(open(baseline_path))
    hit = lambda r: r is not None and r <= k
    broke = [q for q in base if hit(base[q]["rank"]) and not hit(current[q]["rank"])]
    slices: dict[str, list[bool]] = {}
    for q, r in current.items():
        slices.setdefault(r["type"], []).append(hit(r["rank"]))
    low = {s: sum(v) / len(v) for s, v in slices.items() if bars and sum(v) / len(v) < bars.get(s, 0)}
    if broke or low:
        print("broke:", broke, "slices below bar:", low)
        sys.exit(1)

See it

What we measured

Measured · answer in the top 3 by slice

Polder corpus, 34 recursive 512 token chunks, 47 golden questions with an answer. Slices from the golden set's case_type.

answerable (17)vector 15hybrid 17
table (8)vector 8hybrid 8
version (8)vector 8hybrid 8
exact-code (4)vector 4hybrid 4
multi-clause (3)vector 3hybrid 3
conflict (2)vector 1hybrid 2
paraphrase, multi-doc, restricted, injection (5)vector 5hybrid 5

Measured 2026-11-04 with corpus/scripts/measure-parts-4-7.mts. Slices with 1 to 4 questions are too small to trust alone; they flag where to look.

Try it on a real example

Vector search by slice, 47 golden questions, answer in the top 3

Show
1.table · 8 of 8Numbers in tables.✓
2.version · 8 of 8Old and new versions.✓
3.exact-code · 4 of 4Error codes and product codes.✓

The slices we feared most were fine at 512 tokens.

Choosing

Use it when, avoid it when

Use it when
  • A CI gate on per-question regressions and slice bars
  • Online feedback and sampling, fed back into the golden set
Avoid it when
  • Shipping on a higher total alone
  • Online-only evaluation with no fixed set

What it costs · Retrieval checks in CI take seconds. Answer checks cost model calls; run them less often.

In production

Keep the baseline file in the repository next to the golden set, and update it only in a commit that explains why. Show the per-question diff in the pull request. For online evaluation, segment by the same slices as offline, so a drop in one product line is visible. Watch for drift: when the corpus changes, re-run the whole set, not just the affected questions.

Watch out

Common mistakes

  • A higher total is a better system. One slice can still get worse.
  • Small slices are noise. They are; they still point at where to look.
  • Online feedback is enough. Most users do not click; sampling is needed.

Check yourself

Remember this

Remember these

  • Offline: the golden set on every change, in CI.
  • Gate on per-question regressions and slice bars, not on the total.
  • Online: feedback, sampled reviews, abstention and flag rates.
  • Every production failure becomes a new golden question.

Say it in an interview

  1. 01My golden set runs in CI; the gate fails on any question that stops passing.
  2. 02I report by slice: vector search was 44 of 47 overall but 1 of 2 on conflicts.
  3. 03Hybrid search fixed both weak slices, which the slice report showed directly.
  4. 04Online I track feedback, abstention, verification flags and sampled reviews.
  5. 05Every production failure becomes a new golden item with its evidence.

Quick quiz

Three questions

Question 1

Q1

Vector search scored 44 of 47 overall. Which slice was weakest?

Question 2

Q2

What should a regression gate in CI check?

Question 3

Q3 · from RAG-41

What does MRR show that recall@3 hides?

Saved on this device. No account needed.