Course contentsShow
← AI Engineering
Lesson 404 of 1,88610. RAG - Improving RetrievalFree lesson

Precision and Recall for Retrieval

Computing precision and recall metrics to measure how many relevant documents are retrieved.

Precision and Recall for Retrieval

What You'll Learn

You'll learn how to measure retrieval quality by calculating precision (accuracy of returned results) and recall (completeness of relevant results found).

Understanding Precision and Recall

When your RAG system retrieves documents, you need to know: Are these the right documents? and Did I miss any important ones?

Precision answers: "Of everything I retrieved, how much was actually relevant?"

  • Formula: Precision = Relevant Retrieved / Total Retrieved
  • Example: If you retrieve 10 documents and 7 are relevant → 70% precision

Recall answers: "Of all relevant documents in my database, how many did I find?"

  • Formula: Recall = Relevant Retrieved / Total Relevant (in entire dataset)
  • Example: If 15 relevant documents exist and you retrieved 7 → 47% recall

The Trade-off

Think of precision like accuracy (few false positives) and recall like thoroughness (few misses). A search that returns 1 perfect document has 100% precision but likely low recall. A search returning 1,000 documents might have high recall but terrible precision.

In RAG systems, this matters because:

  • Low precision → You waste context window space on irrelevant content
  • Low recall → You miss critical information, leading to incomplete answers

Measuring in Practice

You need a labeled test set where you know which documents should be retrieved for specific queries. Then compare your system's retrievals against ground truth to calculate both metrics.

Key Takeaway: Precision measures retrieval accuracy (correctness), while recall measures completeness (coverage) — both are essential for evaluating whether your retrieval pipeline finds the right context efficiently.