Lesson 5.4 · 8 min read · about 55 min to master at a very slow pace

Evaluating RAG and Agents in Production

The metrics that matter for RAG answers (faithfulness, answer relevance, correctness, refusal behaviour) and for agents (task success, steps, cost), plus offline regression suites, online monitoring and user feedback as one evaluation loop.

Not startedJump to quiz

The RAG metrics

MetricQuestion it answersHow to score
Context recallDid retrieval find the evidence?Recall@k against labelled chunks (lesson 5.2)
Faithfulness (groundedness)Is every claim supported by the retrieved sources?LLM judge, claim by claim
Answer relevanceDoes it address the question asked?LLM judge
CorrectnessDoes it match the reference answer?LLM judge against the reference, or exact match for facts
Refusal accuracyDoes it refuse when it should, and only then?Should-refuse and should-answer test cases
Citation accuracyDo the cited sources support the cited claims?Code check + LLM judge

Faithfulness and correctness differ: an answer can faithfully repeat an outdated source (faithful but incorrect) or be right from the model's general knowledge (correct but unfaithful). For client systems you usually want both.

Agent metrics

  • Task success rate: did it achieve the goal? Best checked on the end state (was the right ticket created with the right fields?) rather than on the text it wrote.
  • Steps and tool calls per task; cost and latency per task.
  • Tool-call accuracy: right tool, valid arguments.
  • Safety: actions attempted without approval, policy violations (should be zero).

Agents are non-deterministic: run each task several times and report the rate, not a single pass or fail.

Offline and online, one loop

  1. Offline: the eval set runs in CI on every change. Release only if no metric regresses beyond its noise.
  2. Online: in production, sample real conversations and run the judges on them; track refusal rate, latency, cost and errors on a dashboard.
  3. User feedback: thumbs up/down, "was this helpful?", escalations to a human, edits to drafts. Cheap signals; low-rated cases go to review.
  4. Close the loop: reviewed failures become new eval cases, and the next change is tested against them.

A release decision

A new reranker raises context recall from 0.82 to 0.90 and correctness from 78% to 84% on 300 cases, with faithfulness unchanged at 96%, and adds 150 ms latency. Standard error on 300 cases at 80% is about 2.3 points, so the 6-point gain is real. Ship it, and watch latency online.

Stuck? Common doubts

Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.

First passDo I need an evaluation platform?

Not to begin. A spreadsheet or JSON file of cases, a script that runs the system and the judges, and a results table work. Platforms help with tracing, dataset versioning, comparing runs and online sampling; adopt one when the number of cases, people or releases makes the script painful.

Going deeperIs it acceptable to run judges on real user conversations?

It can be, but it is processing of personal data. Tell users in the privacy notice, minimise what you keep, redact personal details where possible, and make sure the judge model's provider terms (data retention, region) fit the client's requirements (lesson 6.3).

Cheatsheet

RAG metrics

Context recall, faithfulness, answer relevance, correctness, refusal accuracy, citation accuracy.

Faithful vs correct

Faithful: supported by the retrieved sources. Correct: matches the truth. An outdated source gives faithful but wrong.

Agent metrics

Task success on end state, steps, cost, latency, tool-call accuracy, safety violations. Run tasks several times.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1conceptAn answer accurately repeats a retrieved 2023 price list that has since changed. How does it score?
Q2applyHow should you measure whether a ticket-filing agent succeeded?
Q3interpretAn agent passes a task on 7 of 10 identical runs. How should you report it?
Q4applyOnline, 4% of answers get a thumbs-down. What should happen to them?
Q5interpretA change raises correctness from 80% to 81% on 300 cases (standard error ≈ 2.3 points) but adds 1.2 s latency. What should you do?