Skip to content
mentoor

Topic 5 of 5 · 4 min read

Running RAG evals on every pipeline change

Goal: Wire a RAG eval suite into a change process and decide from a before-and-after report whether a change ships.

Run the same eval set after every change to chunking, embeddings, retrieval settings, prompts or models, and decide from a before-and-after report. RAG has many connected settings. A change that helps one question type often hurts another, and nobody notices without a re-run.

Check yourself · 1 of 3

Why save a trace for each question during an eval run?

Choose one answer

Why it matters

Swapping the embedding model, shrinking chunks or upgrading the generator each feels like a safe improvement. Each one can move recall, faithfulness or refusals in a direction you did not expect. A suite that runs in minutes turns "it seems better" into numbers.

How to wire it

  1. One command runs everything. It loads the question set, runs the pipeline on each question, saves a trace per question (query, retrieved ids with scores, the prompt sent, the answer, citations), then computes metrics from the traces.
  2. Use a framework for the metrics. Ragas offers faithfulness, context precision and recall, and answer correctness, and you can use its metrics or write your own. Keep the traces in your own format so you can re-score without calling the pipeline again.
  3. Pin what could vary. Fix the corpus snapshot, set temperature to 0 where possible, and record the model names and index version in the report. Without this a difference may be noise.
  4. Report per metric and per slice, and list the questions that changed from pass to fail.
  5. Set the gate. For example: no drop in recall@5 or refusal accuracy beyond one question; any new failure on a must-pass question blocks the change.

Reading a before-and-after report

Do not read only the average. Look at the questions that flipped. A change that raises faithfulness from 0.88 to 0.91 but breaks 5 formerly correct answers is not a clear win, even if the mean went up. With 50 questions, a difference of one or two is noise, so repeat the run or grow the set before reacting to it.

Before and after

Weak: "We switched to a new embedding model and it feels sharper." Fixed: "Embedding change: recall@5 0.80 to 0.86, MRR flat, faithfulness unchanged, 3 questions regressed (all error-code lookups). Ship behind a flag after adding keyword search for exact codes."

What goes wrong

  • Running only the metric you were improving. Run the whole suite.
  • Changing two things at once. You cannot tell which change helped. Change one setting per run.
  • No traces. A failing score without the retrieved text cannot be debugged.
  • Judge changes mixed in. Changing the judge model shifts every score. Re-baseline when it changes.

Examples

A suite entry point

import json, sys
from pipeline import answer          # returns dict with ids, scores, text, citations
from metrics import score_all        # recall@5, mrr, faithfulness, correctness, refusal

def run(set_path, out_path, tag):
    rows = [json.loads(l) for l in open(set_path)]
    traces = [{**r, **answer(r['question'])} for r in rows]
    json.dump(traces, open(out_path + '.traces.json', 'w'))
    report = score_all(traces)
    report['tag'] = tag
    json.dump(report, open(out_path + '.report.json', 'w'), indent=2)

if __name__ == '__main__':
    run(*sys.argv[1:4])

A ship or hold decision

Metric Baseline New chunking
recall@5 0.80 0.86
MRR 0.61 0.60
faithfulness 0.90 0.84
refusal accuracy (unanswerable) 10 of 12 7 of 12

Recall improved, but faithfulness fell and 3 more unanswerable questions got invented answers. Hold the change, read the traces for those 3, and fix before shipping.

Key points

  • Run the same suite after every change to chunking, embeddings, retrieval settings, prompts or models.
  • Save a trace per question with the retrieved ids, prompt and answer, so you can re-score and debug without rerunning.
  • Pin the corpus snapshot, model names and temperature, and record them in the report.
  • Read the list of questions that flipped from pass to fail, not just the averages.
  • Change one setting per run, and re-baseline whenever the judge model changes.

Common mistakes

  • Re-running only the metric the change was meant to improve.
  • Changing the chunker and the prompt in the same run, so the effect cannot be attributed.
  • Keeping scores but not traces, which makes failures impossible to debug.
  • Comparing runs scored by different judge models as if the numbers were on one scale.

Check yourself · 2 of 3

You change the chunk size and the generator model in one run, and faithfulness drops. What is the problem with this experiment?

Choose one answer

Check yourself · 3 of 3

A change raises mean faithfulness from 0.88 to 0.91 but 5 previously correct answers now fail. What should you do?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic