How to evaluate a RAG system (the eval harness I ship)
A practical, production-grade eval harness for retrieval-augmented generation: ground-truth sets, the metrics that map to real failures, deploy gates, and cost/latency budgets.
Most RAG demos look great on five hand-picked questions. Production breaks on the sixth. The difference between a demo and a system is an eval harness — a labeled set, metrics tied to real failures, and a gate that stops regressions from shipping.
This is the harness I use, and the one running behind this site.
TL;DR
- Ground truth first. 50–100 real questions with known-good answers and the supporting passages.
- Measure groundedness and refusal precision, not just "did it answer".
- Set a threshold a non-engineer can audit and make it block deploys.
- Run it in CI on every change to retrieval, prompts, models or chunking.
- Track cost and latency next to quality — they are product requirements, not footnotes.
1. Build the ground-truth set
You cannot improve what you cannot check. For each item, store:
| Field | Why |
|---|---|
question | The real user phrasing, not a clean paraphrase |
gold_answer | What a domain expert would accept |
gold_context | The passages that actually support the answer |
type | lookup, multi-hop, numeric, out-of-scope, etc. |
Include out-of-scope questions on purpose. A system that answers everything is a system that hallucinates. Refusal is a feature.
2. Pick metrics that map to failure modes
Every metric should exist because a specific failure hurts users.
- Groundedness — is the answer supported by retrieved context? Catches confident hallucinations.
- Answer relevance — does it address the question? Catches technically-true-but-useless answers.
- Context recall / recall@k — did retrieval even find the right passage? Separates retrieval bugs from generation bugs.
- Refusal precision — when it should decline, does it? Catches overconfident guessing.
- Citation accuracy — do cited passages actually contain the claim?
If a metric doesn't change a decision, delete it.
3. Turn scores into a deploy gate
A number nobody acts on is decoration. Define per-metric thresholds, then compute a single gate:
GATE = {"groundedness": 0.90, "refusal_precision": 0.95, "recall_at_k": 0.85}
def gate_ok(scores: dict[str, float]) -> bool:
return all(scores[m] >= t for m, t in GATE.items())
Fail the build, not the user. The gate is the contract between the AI team and everyone else.
4. Automate it in CI
Wire the harness into the pipeline so regressions are caught before deploy. Here is the actual runner this site uses — deterministic, offline, exit code non-zero below the gate:
uv run python -m app.evals.run_evals # fallback, no model needed
uv run python -m app.evals.run_evals --live # against the configured model
for case in cases:
out = answer(case["question"])
ok = all(kw.lower() in out["reply"].lower() for kw in case["must_include"])
ok &= case["expect_tool"] in out["sources"]
Grow the set by promoting every real failure into a permanent case. The suite becomes your institutional memory.
5. Report cost and latency with quality
Quality without a budget is a science project. Put them on the same dashboard:
- p95 latency end-to-end (retrieval + rerank + generation).
- $ per 1k queries, split by retrieval vs generation.
- Cache hit rate and fallback rate.
On this site the numbers are shown on the Proof section next to the eval table — because a green score with no cost context is half a story.
The habit that matters
The harness is not a one-time task. It is the loop: measure → gate → ship → promote failures → repeat. Teams that do this ship faster, not slower, because they stop arguing about vibes and start reading a table.
If you want to talk shop about building one — or you're hiring someone who treats AI like engineering — get in touch.
Frequently asked
What is the most important metric for a RAG system?
Groundedness — the share of answers fully supported by retrieved context. It is the metric closest to the failure users actually feel (a confident wrong answer), so it should gate deploys alongside refusal precision.
How big should a RAG eval set be?
Start with 50–100 labeled real questions covering the main query types and known failure modes. It is enough to catch regressions; grow it over time by promoting real failures into permanent test cases.
How often should you run RAG evals?
On every change that touches retrieval, prompts, models or chunking — ideally in CI, blocking the deploy on a regression below an agreed threshold.
Keep reading
Hiring an AI Engineer who ships like this?