RAGEngineering Hub
Chapter 9 · concept 5 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

Hallucination checks and answer verification

Check an answer after it is written: are its numbers, codes and dates in the cited sources? A simple number check passed 38 of 39 real answers on our corpus and caught 28 of 39 answers with one number changed.

A real question

The answer looks right and has a citation. How do you know it is not made up?

Check it after it is written. Pull out the numbers, codes and dates, and look for each one in the cited source. It is cheap, catches many invented values, and tells you when to retry or refuse.

The problem

Why this matters

With RAG, the model only says what the documents say.
The belief

With RAG, the model only says what the documents say.

RAG gives the model sources; it does not force it to use them. A cheap check helps: on our golden answers, a number check passed 38 of 39 correct answers and flagged 28 of 39 answers where we changed one number.
What really happens

RAG gives the model sources; it does not force it to use them. A cheap check helps: on our golden answers, a number check passed 38 of 39 correct answers and flagged 28 of 39 answers where we changed one number.

Why not the simpler way

A grounding prompt (RAG-34) lowers hallucination; it does not end it. Models still slip a wrong digit, mix two versions, or round a number the source never rounded. In domains like insurance, banking and telecom, one wrong amount is the whole answer. A check after generation catches what the prompt missed.

The idea

The idea in plain words

Verification checks the answer against the sources. Rule checks (string, number and format matching) are fast and exact but shallow. Model checks ask a second model whether each claim is supported (faithfulness, RAG-42); they are deeper, slower and need their own testing (RAG-43). Self-consistency compares several sampled answers.

A cashier counts the change twice. It does not prove the price was right, but it catches the common mistake.

How it works

Step by step

  1. Numbers, amounts, dates, codes and quoted phrases. These are what users act on, and what models most often get wrong.
    1

    Extract checkable facts

    Numbers, amounts, dates, codes and quoted phrases. These are what users act on, and what models most often get wrong.

  2. Look for the value in the chunk the answer cites. Normalize formats first: 3,000 and 3000 are the same.
    2

    Find each in the source

    Look for the value in the chunk the answer cites. Normalize formats first: 3,000 and 3000 are the same.

  3. Retry with a stricter prompt, show the answer with a warning, or abstain. For claims without numbers, use a model-based check (RAG-42).
    3

    Act on a miss

    Retry with a stricter prompt, show the answer with a warning, or abstain. For claims without numbers, use a model-based check (RAG-42).

In detail

Number check. Normalize thousands separators and decimal marks, extract numbers from the answer, and test each is in the cited chunk (or the whole context, a weaker test). Our version: 39 golden answers contain numbers; 38 had every number in the top-3 context.

Why it misses. "about 2.24 million" is a correct rounding of 2,236 thousand, but the text never writes 2.24: a false alarm. And a changed value can appear elsewhere by chance: 12 of our 39 altered answers slipped through.

Codes and dates. Same idea: product codes, error codes and dates must appear exactly.

Escalation. Pass → show. Miss → one retry with the failed value named, then abstain or show with a warning.

The code

Try it in Python

import re

def plain(s: str) -> str:
    return re.sub(r"(\d)[,  ](?=\d{3}\b)", r"\1", s)     # 3,000 -> 3000

def unsupported_numbers(answer: str, cited_text: str) -> list[str]:
    nums = re.findall(r"\d+(?:\.\d+)?", plain(answer))
    src = plain(cited_text)
    return [n for n in nums if n not in src]

def verify(answer, sources):
    cited = " ".join(sources[int(i) - 1] for i in re.findall(r"\[(\d+)\]", answer) if 0 < int(i) <= len(sources))
    missing = unsupported_numbers(answer, cited or " ".join(sources))
    return ("ok", []) if not missing else ("flag", missing)

See it

What we measured

Measured · number check on expected answers against the top-3 hybrid context

Polder corpus, 34 recursive 512 token chunks, 47 golden questions, hybrid search. Expected answers from the golden set; altered answers made by adding 1 to the first number.

Expected answers that contain numbers39 of 47
Correct answers passing the check38 of 39
Altered answers caught28 of 39
False alarm1 (a rounded value, 2.24 million)

Measured 2026-11-04 with corpus/scripts/measure-parts-6-7.mts on the golden set's expected answers, not on model output. Checking real model answers needs model calls (not measured yet).

Try it on a real example

“What is the maximum payout for a stolen laptop?” Expected: “3,000 euros per item.”

Check

Answer

The maximum payout is 3,000 euros per item [1].

“3000” is found in source [1]. Pass.

Choosing

Use it when, avoid it when

Use it when
  • Rule checks on numbers, codes and dates for every answer
  • A retry or abstain path when a check fails
Avoid it when
  • Treating a passed check as proof of correctness
  • Showing flagged amounts without a warning

What it costs · Rule checks: microseconds. A retry costs one more model call, only on flagged answers.

In production

Run rule checks on every answer; they cost microseconds. Log every flag with the value and the sources; a rising flag rate after a model or prompt change is a regression signal. Sample flagged and unflagged answers for human review, to learn the check's real false-alarm and miss rates on live traffic.

Watch out

Common mistakes

  • Citations mean no hallucination. A cited answer can still change a number.
  • A passed check means correct. 12 of 39 altered answers passed here.
  • Verification needs a second model. The cheapest useful check is string matching.

Check yourself

Remember this

Remember these

  • Verify answers after generation, not only before.
  • Check numbers, dates and codes against the cited source.
  • Our check passed 38 of 39 correct answers and caught 28 of 39 altered ones.
  • It misses values that appear by chance and derived values; combine it with other checks.

Say it in an interview

  1. 01I verify answers after generation: numbers, codes and dates must appear in the cited source.
  2. 02On my golden answers, the check passed 38 of 39 correct ones and caught 28 of 39 altered ones.
  3. 03It misses values that appear by chance and flags derived values like roundings.
  4. 04A failed check triggers one retry, then abstention or a warning.
  5. 05For claims without numbers I add a model-based faithfulness check, tested against labels.

Quick quiz

Three questions

Question 1

Q1

Our number check failed one correct expected answer. Why?

Question 2

Q2

Why did the check catch only 28 of 39 answers with a changed number?

Question 3

Q3 · from RAG-01

What is a hallucination?

Saved on this device. No account needed.