What is context precision vs context recall in RAG?
Beginner · 2 min read · Evaluation & Testing
Open in study mode to save this question and track progressShort answer: Context Precision measures the signal-to-noise ratio of retrieved chunks (how many of the retrieved passages were actually relevant); Context Recall measures whether all the ground-truth information necessary to answer the prompt was successfully retrieved.
Detail
Evaluating the retrieval stage of a RAG pipeline requires separating retrieval precision from generation quality (e.g. in the Ragas evaluation framework).
Retrieved Context Chunks: [Chunk 1 (Relevant), Chunk 2 (Irrelevant), Chunk 3 (Irrelevant)] ├── Context Precision = Low (1/3 relevant chunks = high noise) └── Context Recall = High (if Chunk 1 contains ALL necessary facts)
| Metric | Focus Question | Target Metric Optimization |
|---|---|---|
| Context Precision | "Are top-ranked chunks actually relevant, or did we retrieve clutter?" | Optimizes rank position (Rerankers, higher similarity thresholds) |
| Context Recall | "Did the retriever find all key facts required to answer the question?" | Optimizes recall search (Increasing , hybrid search BM25 + Dense) |
Context Precision Formula (Ragas)
Where indicates if chunk is relevant.
Example
Python concept evaluating context recall against ground truth statements:
python
def calculate_context_recall(ground_truth_statements: list[str], retrieved_context: str) -> float:
# Check what fraction of required ground truth facts exist in retrieved context
found = 0
for stmt in ground_truth_statements:
if stmt.lower() in retrieved_context.lower():
found += 1
return found / len(ground_truth_statements) if ground_truth_statements else 0.0
gt = ["Server restarted at 02:00 UTC", "Error code was 503"]
context = "System logs show server restarted at 02:00 UTC due to maintenance."
print("Context Recall:", calculate_context_recall(gt, context)) # 0.5 (1 of 2 facts retrieved)Interview tips
- Emphasize that high context recall prevents hallucinations, while high context precision reduces prompt token costs and latency.
- Connect this to the Ragas evaluation trilemma (Faithfulness, Context Recall, Answer Relevance).