AI & Data
11 min read
November 22, 2026
How to evaluate a RAG system before it reaches users
A practical evaluation plan for retrieval-augmented generation: building a golden set, measuring retrieval and answers separately, grading with care, and gating releases in CI.
By Parth Patel
A retrieval-augmented generation (RAG) prototype is easy to love. You load a few documents, ask the questions you already know the answers to, and the system responds fluently with plausible citations. Then real users arrive with real questions, and nobody can say whether last week's prompt change made answers better or worse.
The fix is not a cleverer prompt. It is an evaluation harness: a repeatable way to measure whether the system finds the right information and uses it faithfully. This guide walks through building one before launch, so quality is a number you can track instead of a feeling you argue about.
Start by defining the job
"Answer questions about our documentation" is not a specification. Before measuring anything, write down:
- Who asks, and what they need. A support agent looking up a refund rule needs a precise, cited answer. A sales engineer exploring a product needs breadth.
- What counts as correct. Exact facts? A summary that covers the important points? A pointer to the right document?
- What the system must refuse. Questions outside the corpus, requests for personal data, anything that needs a human decision.
These answers decide which metrics matter. A system that drafts replies for agents can tolerate a weaker answer if it always surfaces the right sources. A customer-facing assistant cannot.
Build a golden set from real questions
Your evaluation is only as good as the questions in it. The best sources are the ones users already produce: search logs, support tickets, chat transcripts and the questions subject-matter experts get asked every week.
Aim for 50 to 200 examples to start. Each one should record more than an answer:
{
"id": "refunds-014",
"question": "Can a customer get a refund after 30 days if the item was faulty?",
"type": "policy-lookup",
"answerable": true,
"expected_sources": ["policies/refunds.md#faulty-items"],
"reference_answer": "Yes. Faulty items can be refunded up to 12 months after purchase with proof of the fault.",
"must_include": ["12 months", "proof of the fault"]
}Three details make the difference:
- Expected sources, not just expected answers. They let you measure retrieval on its own.
- Unanswerable questions, roughly one in ten. A system that answers everything confidently is a liability.
- Question types. Tag examples as lookups, comparisons, multi-step reasoning or out-of-scope, so you can see where the system fails instead of a single average hiding it.
Measure retrieval separately
Most RAG failures are retrieval failures. If the right passage never reaches the model, no prompt will fix the answer. So score retrieval first, on its own:
- Recall@k: for what share of questions does at least one expected source appear in the top k retrieved chunks?
- Mean reciprocal rank (MRR): how high does the first relevant chunk appear? Rank matters because models pay more attention to early context.
A minimal implementation is a few lines:
type Example = { id: string; expectedSources: string[] };
type Retrieved = Record<string, string[]>; // example id → source ids, in rank order
export function recallAtK(examples: Example[], retrieved: Retrieved, k: number) {
const answerable = examples.filter((e) => e.expectedSources.length > 0);
const hits = answerable.filter((e) =>
(retrieved[e.id] ?? []).slice(0, k).some((source) => e.expectedSources.includes(source)),
);
return hits.length / answerable.length;
}
export function meanReciprocalRank(examples: Example[], retrieved: Retrieved) {
const answerable = examples.filter((e) => e.expectedSources.length > 0);
const total = answerable.reduce((sum, e) => {
const rank = (retrieved[e.id] ?? []).findIndex((s) => e.expectedSources.includes(s));
return sum + (rank >= 0 ? 1 / (rank + 1) : 0);
}, 0);
return total / answerable.length;
}With retrieval measured, chunking and indexing decisions become experiments instead of opinions. Typical levers, roughly in order of impact:
| Lever | What to try | Watch for |
|---|---|---|
| Chunking | Split on document structure (headings, sections) instead of fixed token counts | Chunks that lose the heading that gives them meaning |
| Hybrid search | Combine keyword (BM25) and vector scores | Product names, codes and acronyms that embeddings handle poorly |
| Metadata filters | Filter by product, region, document type or permissions before ranking | Over-filtering that hides the right answer |
| Re-ranking | Retrieve 20–50 candidates, re-rank to the best 5 with a cross-encoder | Added latency and cost per query |
Measure answers with a rubric, not a vibe
Once retrieval is reliable, score the generated answers. Useful dimensions are:
- Groundedness: is every claim supported by the retrieved passages?
- Correctness: does the answer match the reference, including the facts listed in
must_include? - Citation accuracy: do the cited passages actually support the sentences they are attached to?
- Refusal behavior: does it decline unanswerable questions, and avoid declining answerable ones?
Grading hundreds of answers by hand does not scale, so most teams use a strong model as a judge. That works if you treat the judge as a measuring instrument that needs calibration:
- Write a rubric with concrete criteria and a small scale (for example, 0–2 per dimension).
- Have people grade 30–50 answers with the same rubric.
- Run the judge on the same answers and check agreement. If it disagrees often, fix the rubric or the judge prompt before trusting it.
- Re-check agreement whenever you change the judge model.
Make evaluation repeatable
An evaluation you run once is a report. An evaluation you run on every change is a safety net. Version everything that affects results (the corpus snapshot, chunking parameters, embedding model, prompts and generation model) and store results per run so you can compare them.
Then turn your thresholds into release gates:
# eval/thresholds.yml — CI fails if any gate is not met
retrieval:
recall_at_5: 0.90
mrr: 0.70
answers:
groundedness: 0.95
correctness: 0.85
citation_accuracy: 0.90
refusals:
unanswerable_refused: 0.90
answerable_wrongly_refused: 0.05
budgets:
p95_latency_ms: 4000
cost_per_answer_usd: 0.02Gates turn conversations about quality into concrete trade-offs. If a cheaper model drops correctness from 0.88 to 0.81, the decision is explicit instead of discovered by a customer.
Keep evaluating after launch
Offline evaluation tells you whether the system is ready. Production tells you whether it stays ready:
- Capture feedback in the interface, and make it cheap: a thumbs down plus an optional reason.
- Sample for review. A few percent of real conversations, graded with the same rubric, reveals drift that feedback misses.
- Feed failures back. Every confirmed bad answer becomes a new golden example, so the same failure cannot quietly return.
- Watch the operational numbers next to quality: latency percentiles, cost per answer and the share of answers that cite nothing.
A pre-launch checklist
- A written definition of the job, including what must be refused
- A golden set from real questions, with expected sources, question types and unanswerable cases
- A held-out portion that was never used for tuning
- Retrieval metrics (recall@k, MRR) measured separately from answer quality
- An answer rubric, and a judge calibrated against human grades
- Results broken down by question type, with the worst cases read by a person
- Thresholds enforced in CI, plus latency and cost budgets
- Feedback capture, sampling and a path for failures to become test cases
None of this is glamorous, and all of it is cheaper than discovering in production that the assistant confidently invents a refund policy. The goal is not a perfect system. It is a system whose quality you can see, defend and improve.