How do you evaluate the retriever in a RAG (retrieval-augmented generation) system separately from the generator? Suppose three queries have relevant chunk IDs R1={c2,c5}, R2={c8,c9,c10} and R3={c12}, and the retriever returns top-5 lists L1=[c1,c2,c4,c5,c7], L2=[c8,c1,c3,c6,c11] and L3=[c3,c4,c7,c9,c15]. What are the recall@5, precision@5, hit rate@5 and MRR (mean reciprocal rank), and how does scoring both retrieval and generation let you separate a retrieval miss from a generation error?

ML systems and evaluation, Retrieval evaluation
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can decouple retrieval quality from LLM (large language model) generation quality in a RAG (retrieval-augmented generation) pipeline and compute standard top-k retrieval metrics.

Key idea

Evaluating a RAG system end to end hides where errors happen, so you score the retriever against ground-truth relevant chunks and the generator against both the retrieved context and the reference answer. Recall@5 measures coverage of relevant chunks, precision@5 measures how clean the top 5 are, hit rate@5 checks whether at least one relevant chunk appeared, and MRR (mean reciprocal rank) averages the inverse rank of the first hit.

Steps

  1. Define the four top-k retrieval metrics for k=5 across Q=3 queries: for query q with relevant set Rq and retrieved top-5 list Lq, recall@5=∣Lq∩Rq∣/∣Rq∣, precision@5=∣Lq∩Rq∣/5, hit@5=1 if Lq∩Rq≠∅ else 0, and reciprocal rank RRq=1/rq where rq is the rank of the first relevant chunk (or 0 if none is retrieved).
  2. Score query 1 (R1={c2,c5}, L1=[c1,c2,c4,c5,c7]): two relevant chunks appear at ranks 2 and 4, so recall@5=2/2=1.00, precision@5=2/5=0.40, hit@5=1, and RR1=1/2=0.50.
  3. Score query 2 (R2={c8,c9,c10}, L2=[c8,c1,c3,c6,c11]): only c8 appears (at rank 1), so recall@5=1/3≈0.333, precision@5=1/5=0.20, hit@5=1, and RR2=1/1=1.00.
  4. Score query 3 (R3={c12}, L3=[c3,c4,c7,c9,c15]): no relevant chunk appears, so recall@5=0, precision@5=0, hit@5=0, and RR3=0.
  5. Average across the three queries: mean recall@5=(1+1/3+0)/3=4/9≈0.444, mean precision@5=(0.40+0.20+0)/3=0.20, hit rate@5=(1+1+0)/3=2/3≈0.667, and MRR=(0.50+1.00+0)/3=0.50.
  6. Evaluate the generator separately using two checks: faithfulness (groundedness, whether every claim in the answer is supported by the retrieved chunks rather than hallucinated) and answer correctness (whether the answer matches the ground-truth answer). Scoring both sides isolates failures: low recall@5 with a wrong answer points to a retrieval miss (as in query 3), whereas high recall@5 with low faithfulness or low answer correctness points to a generation or prompting error.

Common mistakes

How long your answer should be

About 3–4 minutes: per-query numbers, four averages, and two sentences on generator metrics and error attribution.

Read this

Previous in ML systems and evaluation: A classifier on 1,000 test examples has TP = 10, FN = 10, FP = 5 and TN = 975. Compute the accuracy, the F1 score and the Matthews correlation coefficient, MCC=TP⋅TN−FP⋅FN(TP+FP)(TP+FN)(TN+FP)(TN+FN). What do these give for a model that always predicts negative?
Next in ML systems and evaluation: How do you monitor a deployed ML (machine learning) model when ground-truth labels arrive weeks late or never arrive at all?