How to test a RAG system when the answer is different every time
Exact-match testing on a generative system measures nothing. Four axes — retrieval recall, citation precision, refusal correctness, stability — and the run protocol that makes a score comparable across releases.
The standard first attempt at evaluating a retrieval-augmented system is a spreadsheet of questions with one expected answer each, compared by string match. It fails immediately and for two reasons: the model will phrase a correct answer differently every run, and a large share of the questions that matter most have answers that are wrong to give.
The fix is not a better string metric. It is to stop grading the prose and start grading the four things the prose depends on.
The four axes
- Retrieval recall. Did the chunk that contains the answer appear in the retrieved set at all? If not, nothing downstream can be right. Measure this separately, with no model in the loop.
- Citation precision. Of the sources the answer cites, how many actually support the claim attached to them? An answer that cites the right document for the wrong sentence is worse than no citation, because it looks verifiable.
- Refusal correctness. When the corpus does not contain the answer, does the system say so — or does it invent a plausible number? This is the axis that decides whether the product is deployable, and it is the one most test suites omit.
- Stability. Run the same question several times. A system that is right 60% of the time and confidently wrong 40% is not a 60% system; it is an unpredictable one.
Build the gold set like a lawyer, not like a demo
Fifty to a hundred and twenty pairs is enough to see movement, if they are chosen deliberately. Deliberately means including the ugly cases:
- Unanswerable questions. At least a fifth of the set should have no answer in the corpus. This is how you measure refusal at all.
- Near-duplicates with different answers. Two versions of the same policy, one superseded. Correct behaviour is citing the current one and saying the old one is superseded.
- Multi-hop questions. The answer requires two documents — a price list and a discount rule. Single-chunk retrieval fails here, and you want to see it fail.
- Table and figure questions. Spreadsheet cells and drawing dimensions are where parsing silently mangles content.
- Adversarial phrasing. The question that a customer would actually type, including the mistaken premise.
Each pair stores the expected answer facts — not a sentence — plus the document ids that legitimately support them, and a label: answerable / unanswerable / superseded.
Run protocol
- Temperature zero is not determinism. Sampling, batching and retrieval tie-breaking all introduce variation. Run each question three to five times.
- Report a median and a span, not a single number. "Citation precision 0.82 (runs: 0.79–0.86)" tells a reader something; "0.82" invites false confidence.
- Freeze the index. Change one thing per run — prompt, chunking, model, reranker. A run where the corpus moved as well is not a comparison.
- Grade facts, not words. Use a rubric per pair: is the number correct, is the entity correct, is the qualifier preserved, is the cited document the right one. A second model can grade this, if its own error rate is measured against a hand-labelled subset.
Turning scores into a release gate
Absolute numbers are less useful than a baseline plus a rule. Ours, expressed generically:
| Metric | Gate |
|---|---|
| Retrieval recall (answerable) | no regression below 0.95 |
| Citation precision | no regression below 0.90 |
| Refusal correctness (unanswerable) | no regression below 0.85 |
| Cross-run span | must stay under 0.10 |
A release that improves average quality while widening the span has become less trustworthy, and in a customer-facing deployment that is a regression even if the average went up.
What this does not measure
Tone, latency, cost per answer, and whether a human would accept the reply in a real conversation. Those need a small human panel and a sampled transcript review; they are not a substitute for the four axes, and the four axes are not a substitute for them. The mistake is testing only one of the two and calling it quality.
Frequently asked
Why not just compare the answer to an expected answer?
Because a correct answer is phrased differently on every run, and because the questions that matter most — the ones with no answer in the corpus — cannot be graded by string match at all. Grade the facts and the citations instead, and measure whether the system refuses when it should.
How many test questions do I need?
Fifty to one hundred and twenty deliberately chosen pairs will show movement. The composition matters more than the count: at least a fifth unanswerable, plus superseded-document near-duplicates, multi-hop questions, table questions and realistically phrased customer questions.
Is temperature zero enough for reproducible results?
No. Sampling, batching and retrieval tie-breaking still introduce variation. Run each question three to five times, report a median with a span, and treat a widening span as a regression even when the average improves.
Related notes
- Measurable twins without Gaussian splatting: mesh first, texture second
- When Gaussian splatting is the wrong tool
- 720° panorama capture on an X5: the rules that make self-calibration work
- The twin is the agent's world model
Written by 双玺堂 ROBOTICS from live project work. More notes: Insights. 中文技术文章 900+ 篇:文章库.