Skip to content
AgenticAIWiki
  1. Learn
  2. Part 4
  3. 26. Evaluating RAG
  4. 26.5

Lesson 26.5 · 5 of 7 · 6 min read · Reviewed 24 Nov 2026

Context precision and context recall

By the end, you can

  • Explain context precision and context recall.
  • Compute both for one test case from judged chunks and reference claims.

Retrieval metrics without chunk labels

Recall@kHit rate@k: The share of test questions with at least one relevant chunk in the top k results. and MRR (26.1, 26.4) need labels: for each question, someone has listed the chunkChunking: Splitting documents into smaller passages before embedding and indexing them. ids that answer it. Those labels break whenever you re-chunk the documents, because the ids change.

Context precision and context recall avoid that. They compare the retrieved text with the question and a reference answer, and a model judge does the matching. If you change chunk size, the reference answer still holds. The names come from the RAGAS work, and other tools use similar ideas under other names.

Context recall: did we fetch the facts?

  1. Split the reference answer into short claims.
  2. For each claim, the judge asks: can it be found in the retrieved context?
  3. Context recall = supported claims / all claims.

Worked example. Question: “Can I return sale shoes I’ve worn once?”

Reference claim In retrieved context?
Sale items are final sale yes (pol-4.3)
Faulty items are an exception yes (pol-4.3)
Worn footwear is accepted only if faulty no

Context recall = 2 / 3 = 0.67. The footwear rule was never retrieved, so even a perfect generator could not give the full answer.

Context precision: is the useful text near the top?

  1. For each retrieved chunk, in rank order, the judge says useful or not useful for reaching the reference answer.
  2. At each useful position k, compute precision@k (useful chunks so far / k).
  3. Context precision = the average of those precision@k values.

Worked example, four chunks judged useful, not, useful, not:

rank 1 useful   precision@1 = 1/1 = 1.00
rank 3 useful   precision@3 = 2/3 = 0.67
context precision = (1.00 + 0.67) / 2 = 0.83

If the two useful chunks had been at ranks 1 and 2, the score would be 1.0. Like nDCG, it rewards order, but it uses yes or no judgements.

Reading the two together

Context recall Context precision What it suggests
High High Retrieval is doing its job; look at generation (26.2)
Low High What comes back is good, but facts are missing: raise k, add hybrid search, fix chunking
High Low Facts are there but buried in noise: add a reranker, lower k
Low Low Retrieval is the main problem; start there

Common mistakes

  • Trusting the judge blindly. A model decides “found in context”. Hand-label 30 to 50 cases and check agreement before you rely on the numbers (chapter 18).
  • Weak reference answers. If the reference leaves out a needed fact, context recall cannot notice it is missing. Write references with care (26.3).
  • Confusing context precision with faithfulnessFaithfulness: Whether every claim in an answer is supported by the retrieved context.. Context precision scores the retrieved chunks. Faithfulness scores the generated answer against those chunks.
  • Comparing across judge models. Changing the judge model changes the scores. Pin it, like any other part of the evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria..

Key points

  • Context precision asks whether the retrieved chunks that matter sit near the top, judged against the question and reference.
  • Context recall asks what share of the reference answer's claims can be found in the retrieved context.
  • Both need a reference answer, not labelled chunk ids, so a model judge does the matching; check it against people.
  • Low context recall points at retrieval missing facts; low context precision points at noise and ordering.
Hands-on labRuns in the Playground

Compute context precision and recall

Score retrieved context against a reference answer without chunk labels, using a simple stand-in for the model judge.

You will have: A script that prints context precision and context recall for one test case, with the judgement behind each.

Steps

  1. Split the reference answer into claims.
  2. Use the provided judge function (word overlap, standing in for a model) to say whether each claim is found in the context.
  3. Compute context recall: found claims over all claims.
  4. For each retrieved chunk in rank order, judge it useful or not, and compute context precision as the mean precision@k at useful positions.
  5. Swap the chunk order and see which metric moves.

Done when

  • Context recall prints as 0.67: the worn-footwear claim is missing.
  • Context precision prints as 0.83 for the order useful, not, useful, not.
  • Putting both useful chunks first raises context precision to 1.00 and leaves recall unchanged.

Open in the Playground No API key needed.

Starter code (Python)
REFERENCE = ["Sale items are final sale.", "Faulty items are an exception.", "Worn footwear is accepted only if faulty."]
RETRIEVED = [
    ("pol-4.3", "Sale items are final sale unless faulty items are reported."),
    ("pol-9.1", "Our stores open at nine on weekdays."),
    ("pol-4.6", "Faulty items are an exception to every sale rule."),
    ("pol-2.2", "Gift cards cannot be exchanged for cash."),
]

def found(claim, text):
    # Stand-in for a model judge: most of the claim's words appear in the text.
    cw = {w.strip(".").lower() for w in claim.split()}
    tw = {w.strip(".").lower() for w in text.split()}
    return len(cw & tw) / len(cw) >= 0.7

def context_recall(reference, retrieved):
    # TODO: share of reference claims found in any retrieved chunk
    return 0.0

def context_precision(reference, retrieved):
    # TODO: a chunk is useful if any reference claim is found in it;
    # average precision@k over the positions k where the chunk is useful
    return 0.0

print(f"context recall = {context_recall(REFERENCE, RETRIEVED):.2f}")
print(f"context precision = {context_precision(REFERENCE, RETRIEVED):.2f}")
Show a solution
REFERENCE = ["Sale items are final sale.", "Faulty items are an exception.", "Worn footwear is accepted only if faulty."]
RETRIEVED = [
    ("pol-4.3", "Sale items are final sale unless faulty items are reported."),
    ("pol-9.1", "Our stores open at nine on weekdays."),
    ("pol-4.6", "Faulty items are an exception to every sale rule."),
    ("pol-2.2", "Gift cards cannot be exchanged for cash."),
]

def found(claim, text):
    # Stand-in for a model judge: most of the claim's words appear in the text.
    cw = {w.strip(".").lower() for w in claim.split()}
    tw = {w.strip(".").lower() for w in text.split()}
    return len(cw & tw) / len(cw) >= 0.7

def context_recall(reference, retrieved):
    hits = [any(found(c, t) for _, t in retrieved) for c in reference]
    for c, h in zip(reference, hits):
        print(f"  claim {'found  ' if h else 'MISSING'}  {c}")
    return sum(hits) / len(hits)

def context_precision(reference, retrieved):
    useful = [any(found(c, t) for c in reference) for _, t in retrieved]
    print("  judged:", ", ".join("useful" if u else "not" for u in useful))
    precs, seen = [], 0
    for k, u in enumerate(useful, start=1):
        if u:
            seen += 1
            precs.append(seen / k)
    return sum(precs) / len(precs) if precs else 0.0

print(f"context recall = {context_recall(REFERENCE, RETRIEVED):.2f}")
print(f"context precision = {context_precision(REFERENCE, RETRIEVED):.2f}")
reordered = [RETRIEVED[0], RETRIEVED[2], RETRIEVED[1], RETRIEVED[3]]
print(f"after reordering: context precision = {context_precision(REFERENCE, reordered):.2f}")
Quick checkA reference answer has four claims. The retrieved chunks support three of them. What is the context recall?
How sure are you?
Pick an answer and how sure you are