The most agonizing thing about RAG systems is that there are too many things to tune: chunk size, embedding model, BM25 parameters, fusion weights, reranking model, number of chunks, wrapper format, generation instructions. Change any one of them, and you can always find a few examples that got better and a few that got worse. Without an evaluation set, tuning is basically gradient descent on your most recent impression.
After getting burned, I set a rule for myself: only allow parameter changes once there’s a reproducible evaluation set.
Post 11/15 in this series · Previous: Context Construction: It’s Only Just Begun After Retrieval · Next: Agentic RAG: Handing Retrieval to an Agent Scheduler
Evaluation Set Before Metrics
A hundred-plus carefully constructed evaluation items is far more useful than a thousand auto-generated synthetic questions. My construction method hasn’t changed much over the years, and has roughly settled into the following.
Stratified sampling from real logs by frequency. Sampling only high-frequency queries inflates overall metrics, because high-frequency questions tend to be the easiest. I split into three strata: high-frequency, mid-frequency, long-tail, then add a batch of real but messy queries—colloquialisms, typos, omitted context all included.
Hand-write boundary samples. These categories must have their own groups: error codes and IDs, colloquial rewrites, containing negation, multi-condition combinations, answerable only across documents, time-sensitive, and requiring citations. At least a dozen per group, scored separately.
Keep a set of “no-answer” questions. Content never mentioned in the corpus, used to test refusal. Without this group, the system will optimize itself into “answer everything,” and the metrics will still look good.
Annotate to doc_id / chunk_id, not to answer text. Retrieval-layer evaluation needs “which chunks should appear in the top K positions”; answer text is left to the generation layer. The annotation spec must be written clearly, especially the definition of “relevant”: does mentioning a keyword count as relevant, does merely providing background count as relevant. Even when I annotate alone I’m inconsistent over time, so I sample a batch for re-review, record disputed samples separately, and don’t force consensus.
The evaluation set itself must be versioned, and you can’t tune on it and also report on it. My approach is to split into three: a dev set to run freely, a validation set for selection decisions, and a small held-out set looked at only during quarterly reviews. When the sample size is small, this split feels extravagant, but it guards against the most typical self-deception: tuning parameters until you overfit the evaluation set, then declaring the system improved.
Layered Metrics: First Locate Which Layer Broke
I gave a table earlier when discussing symptom attribution; what the evaluation system needs to do is quantify it. I split metrics into three layers:
| Layer | Metrics | Question Answered |
|---|---|---|
| Recall | Recall@K, MRR | Did the correct material enter the candidate pool |
| Ranking | nDCG@K, top-K precision | Did the correct material rank where it will be read |
| Generation | Faithfulness, answer relevance, citation accuracy, answerability rate | Given the right material, is the answer correct |
This layering has a very practical corollary: generation-layer errors can’t be fixed by only changing the prompt. If Recall@50 is only 0.6, no amount of generation instruction optimization will raise the ceiling. Conversely, if Recall@50 is near 1 but answer faithfulness is low, the problem is likely in context construction or generation constraints—going back to tune BM25 parameters is pure waste.
Beyond quality metrics, latency P95 and per-query cost must be treated as first-class metrics, recorded in the same table. A reranking model that lifts nDCG by two points but pushes P95 from 800ms to 2.5s may not be an improvement in production. Outputting a full record per evaluation run is more reliable than just looking at the score column.
1 | def run_eval(pipeline, dataset, k=50): |
aggregate(by='group') This line is what I most want to emphasize. Overall scores average out “ID-type up 20 points, colloquial-type down 5 points” into an unremarkable small gain, and then you ship with a regression. This is exactly the pit I fell into when swapping embedding models earlier.
Generation-Layer Evaluation: Break the LLM’s Judgment into Smaller Pieces
Generation quality has no simple string metric that covers it, so a stronger model is commonly used as judge. The core idea of frameworks like RAGAS isn’t “have an LLM give a score,” but to break fuzzy judgments into decidable sub-questions:
- Faithfulness: split the answer into independent statements, ask for each “can this statement be directly inferred from the given material,” and compute the supported ratio. This is far more stable than directly asking “is the answer faithful.”
- Answer relevance: ask “does this answer address the question, or is it off-topic or evasive.”
- Context precision: ask “of the material fed in, how many items are truly necessary to answer this question.”
Once broken into sub-questions, the judge model’s output becomes a set of booleans or enums—reproducible, sampleable for human review, and able to pinpoint exactly which statement wasn’t supported.
But LLM-as-judge has its own biases that must be actively managed.
Position and length preference: it tends to score longer, more polished answers higher. The workaround is to have the judge look only at the “statement vs. material” correspondence, not writing style.
Self-preference: using the same model to generate and judge systematically favors its own output. I try to keep the judge model in a different family from the generation model, or at least a different tier.
Drift: change one word in the judge prompt and scores jump across the board. So fix the judge template and version, and treat judge results as something that needs regression testing too. The approach is to first hand-label 30–50 golden samples, run them periodically, and check the agreement rate between judge model and human; if agreement drops, don’t trust the scores from that period.
Cost: per-statement calls multiply evaluation cost several times over. During development you can run the full set; for daily regression, run only a fixed subset.
I never put absolute LLM-judge scores into external reports—only relative changes and layered attribution, and important conclusions always go back to human sampling review.
Ablation and Regression Defense
Evaluation isn’t just scoring; it’s an attribution tool. After a change takes effect, I ablate by layer, changing one variable at a time: turn off reranking, turn off BM25, revert to the old chunking, roll back to the wrapper without prefixes. Seeing “how much this step actually contributed” is more valuable than looking at the total score. Some components are very effective at launch, but after the corpus changes their contribution approaches zero or even goes negative—without ablation you’d never find out, and would just keep piling things on.
Wiring evaluation into CI is the last step, and the easiest to abandon halfway. My minimum viable version is this:
- On every index rebuild, model or prompt change, run a fixed small regression set—a few dozen items, finishing in minutes.
- Set layered thresholds: overall metrics may fluctuate slightly, but if any group’s recall drops beyond a set margin, it’s a red light.
- Set a separate threshold for the “no-answer” group’s false-answer rate; degradation in this group is almost always a serious problem.
- Archive the full layered results of this run and the last; trends matter more than single points.
- A red light doesn’t necessarily block release, but someone must explicitly confirm and record the reason.
On the online side, add three more signals to catch problems the evaluation set doesn’t cover: sudden changes in refusal rate, citation validation failure rate, and the proportion of users “re-asking” or downvoting. The evaluation set is a sample; the online distribution drifts, so you need to watch both.
It’s worth building, but not at every stage
The benefits are in a few very concrete places: turning “it feels better” into reproducible numbers; being able to pinpoint which layer broke, so you don’t keep tuning parameters at the wrong layer; giving high-risk actions like swapping models, rebuilding indexes, and changing prompts a basis for rollback; and giving team discussions a shared factual foundation.
The hassle is unavoidable too. Annotating and maintaining the eval set is ongoing manual effort, and once the corpus changes, the annotations go stale; LLM judging needs calibration itself, otherwise you’ve just moved the uncertainty somewhere else; metrics are never complete—politeness, answer style, and handling of ambiguous questions are hard to quantify. There’s also a more fundamental limitation: eval sets come from past queries and have no predictive power for entirely new types of questions, so samples must be periodically replenished from new logs.
The cases where it doesn’t apply should be stated clearly too: for one-off prototypes, corpora with only a few pages of documents, or when the system is still undergoing drastic structural changes, don’t build a formal eval system yet—collecting twenty real questions and expected answers is enough. I’ve seen projects that designed dozens of metrics from the start, and in the end not a single one was run continuously over time. Better to first fill in the traces (call-chain records).
Once an eval system is in place, a more fundamental question surfaces: the whole pipeline is a fixed sequence, but some questions simply can’t be answered by a single retrieval. “Compare the performance difference between versions A and B, then check why it was changed at the time” requires decomposition, retrieval, judging whether the evidence is sufficient, and then another round of retrieval. At that point, should retrieval be a pipeline stage, or a tool in the Agent’s hands? The next post enters the fusion part of the series. When you change a parameter now, how long does it take you to know whether it goes up or down on “numbered-type” queries?
Comments