LLM Lab

Evaluating RAG & agents

A RAG system or an agent can fail in several places. Grade each stage separately, not only the final answer.

Where this sits when evaluating a model
Choose test data→Score the outputs→Compare models→Check trust (calibration, leaks)→Evaluate whole systems→Measure speed and cost

RAG: retriever and generator

Evaluate the two halves apart. The retriever is judged with ranking metrics such as recall@k: did the right passages come back? The generator is judged on faithfulness (is each claim supported by the passages?) and on answer correctness.

Agents: the trajectory

An agent’s answer depends on a chain of steps. Besides task success, look at the trajectory: were the tool calls valid, did each step help, how many steps were wasted? Two runs with the same answer can differ greatly in cost and risk.

In the lab, mark each step of a run as good or bad and see the scores change.

A worked example

A question has two relevant documents. The retriever returns five; the relevant ones are ranked 1st and 4th. Recall@3 is 1/2 and recall@5 is 1. If the generator reads only the top 3, it is missing half of the evidence before writing a word, so a wrong answer is the retriever’s fault, not the model’s.

retrieved1. doc 7 ✓ 2. doc 2 3. doc 9 4. doc 4 ✓ 5. doc 1
recall@31 of the 2 relevant docs in the top 3 = 0.5
recall@52 of 2 = 1.0
Recall@k for one question with two relevant documents (✓). Only one of them is in the top 3, so a generator that reads three chunks misses half of the evidence.

In practice

Build a small labelled set of questions with known relevant passages and reference answers. Measure retrieval (recall@k), faithfulness (every claim supported by the retrieved text) and correctness separately, so you know which part to fix. For agents, log full trajectories and check tool-call validity and cost alongside the final answer.

Easy to confuse

Check yourself · 1 of 3

A RAG answer is fluent and correct, but the retrieved passages never mention the answer. What did the model rely on?

Check yourself · 2 of 3

Two agents both finish the task. One used 4 tool calls and the other 19. What does final-answer accuracy say?

Check yourself · 3 of 3

Retrieval recall@3 is 0.5. What does that mean?

Read more in the books

  • AI Engineering, Chip Huyen: Ch. 6, “RAG and Agents”.
  • AI Engineering, Chip Huyen: Ch. 4, “Evaluate AI Systems”: design your evaluation pipeline.
  • Introduction to Information Retrieval, Manning, Raghavan, Schütze: Ch. 8, “Evaluation in information retrieval”.
All books
Labtrajectory grader
How to read this
  • Pick a run. Each row is one step of the agent’s trajectory; click the pill to mark the step good or bad.
  • The tiles report task success, the share of good steps, and efficiency (the shortest possible run divided by the actual number of steps).