trialswithai
Essay evals

How we measure RAG quality

RAG quality by vibes doesn't survive a second engineer. Break the score down by stage, build the eval set from real failures, calibrate the judge, gate CI.

Essay · evals How we measure RAG quality5 min · evals
TL;DRthe 30-second version
  • The point of measuring RAG is answering which stage broke? the moment something regresses. One quality score can't tell you that.
  • Build the eval set from real failures. Questions you invent cluster around the cases you already handle well.
  • Trace every eval query to where its source got lost. On our last run, 67 of 75 cited the right source, and the biggest loss was retrieval (4 queries).
  • Treat an LLM judge as an instrument with known biases (verbosity, position), calibrate it against human labels, and gate every change on the eval set in CI.

For a while, “is it good?” was answered by someone typing a few questions, reading the answers and saying “yeah, looks good.” That works until two people disagree, or until a change makes the system better on the questions you remember and worse on the ones you don’t. Vibes don’t survive a second engineer or a second release.

It broke for me on a re-ranking change I was sure had helped. The handful of answers I spot-checked came back tighter and better sourced, so I shipped it. A week later someone asked a question that started in a Jira ticket and ended in code, exactly the cross-source case I hadn’t thought to test, and got a confident, fluent, wrong answer that the old configuration would have got right. I’d improved the queries I happened to remember and regressed a whole class I didn’t. Nobody caught it, because “looks good” has no memory.

The fix was to measure RAG quality with named metrics on a fixed dataset, the way you’d never ship code without tests. I leaned on the RAGAS-style breakdown: faithfulness (does the answer stay grounded in the retrieved context), answer relevance (does it address the question), context precision (is the retrieved context on topic or padded with noise) and context recall (did retrieval pull the chunks that hold the answer). The breakdown matters because “the answer was bad” is useless for debugging. “Context recall was low” points at retrieval, and “faithfulness was low on good context” points at generation.

Building the eval set

The metrics are only as good as the dataset under them. Ours is 75 hand-written ground-truth queries against one real product’s corpus. Each is labelled with the concrete artefacts the answer should rest on: the expected symbols and file paths. They’re grouped by the shapes of question the system really gets: an exact single-symbol lookup, a conceptual “how does this work” question, a cross-source query that has to jump from a ticket into code, and one that has to reach a design file. 75 sounds small. What makes it worth something is that every query is a real shape of question, labelled by hand against the real repository.

I seeded it from real usage. Questions you invent cluster around the cases you already handle well. The cross-ticket and cross-design groups exist because those were the queries that had embarrassed the system. An eval set that never hurts isn’t measuring much.

The breakdown that caught something real

The breakdown that earned its keep is what I call stage attribution. Every eval query is traced through the pipeline, and I record where the ground-truth file was lost:

  • Retrieval: it never entered the hybrid retrieval pool.
  • Rerank: the re-ranker dropped it after it got there.
  • Fetch: it survived ranking but was never fetched as content.
  • Synthesis: it was fetched, and the model never cited it.

Where the ground-truth source is lost

Fig. 1 Each dot is one of the 75 eval queries from the last run, traced to the stage where its ground-truth file dropped out. Lost at retrieval: never entered the hybrid pool. Rerank: dropped after it got there. Fetch: ranked but never fetched. Synthesis: fetched but never cited.

On the last run, 67 of the 75 queries cited the right source (89.3%). Four were lost at retrieval (5.3%), none at rerank, one at fetch (1.3%) and three at synthesis (4.0%). Those four retrieval losses changed my plan. They weren’t hallucinations. The file holding the answer never entered the candidate pool, so no prompt change downstream could have rescued them.

That’s the payoff of breaking the score down. One end-to-end number would have said the answers were mediocre. The stage breakdown said which stage to fix, and it wasn’t the one I’d assumed: I’d been about to spend a week on the prompt for a problem that lived in retrieval.

Where the LLM judge misled me

Early on I wanted to score faithfulness with an LLM judge, because deciding whether a synthesised answer is grounded felt like the fuzzy kind of judgement only a model could make at scale. It does scale in a way human rating doesn’t, and it’s useful. It also has biases you have to design around, and I learned that slowly.

Two bit me. Verbosity bias: the judge rewarded the answer that restated more of the retrieved context, so longer read as more thorough even when a three-line answer was more correct. Position bias: in pairwise comparisons it leaned towards whichever candidate I showed first, regardless of content. Zheng et al. (2023) measured both, along with self-enhancement bias, and still found strong judges agreeing with human preferences over 80% of the time, about as often as humans agree with each other. So the judge is usable, provided you measure where it goes wrong.

The fixes are mundane. Randomise the order and average across both arrangements to cancel position effects, and calibrate against a human-labelled slice so you know where the judge and a person diverge. That calibration is why the core of our eval stayed deterministic: relevance is scored by whether a result’s symbols and file paths match the labelled ground truth, on a fixed 1.0 / 0.75 / 0.5 / 0.25 scale. The judge stays at the edges, where I’ve measured its error.

Evals as a CI gate

What made all of this matter day to day was wiring the eval set to a hard threshold: NDCG@10 has to clear 0.75 or the change doesn’t merge. The first thing it caught was a symbol-extraction tweak that improved the exact-lookup queries and dragged down the cross-design ones. The blended average barely moved, but the per-group and stage breakdowns showed exactly which group had regressed, and it never shipped.

Once the eval set runs on every change to retrieval, prompts, the embedding model or the re-ranker, “we think this is better” becomes “this cleared the bar we agreed on.” Quality turns from an argument into a check. It changes how the team talks, too: people stop defending changes with intuition and point at the numbers, which is a much shorter conversation.

The takeaway

The goal is answering “which stage broke?” the moment something regresses, and stopping a regression before it reaches users. Break the score down so a bad answer tells you where to look, build the eval set from real failures, calibrate the judge before you trust it, and run the whole thing in CI. A quality bar you don’t enforce on every change isn’t a bar.

A green eval suite has a limit of its own, though: it only proves something once you’ve watched it go red. That’s the next post, Your evals have no tests.

References

  1. Es, James, Espinosa-Anke & Schockaert. 2023. RAGAS: automated evaluation of retrieval augmented generation.
  2. Zheng et al. 2023. Judging LLM-as-a-judge with MT-Bench and Chatbot Arena. NeurIPS Datasets and Benchmarks.