Course contentsShow
← Machine Learning and Deep Learning
Lesson 2025 of 3,53843. Retrieval-Augmented Generation: Advanced TechniquesFree lesson

Mean Average Precision (MAP)

Calculating MAP to evaluate ranked retrieval results, accounting for both relevance and ranking quality.

Mean Average Precision (MAP)

What you'll learn: How to calculate MAP to measure both relevance and ranking quality in retrieval systems, going beyond simple precision and recall.

The Problem with Simple Precision

You've learned about precision and recall for retrieval evaluation. But there's a catch: precision at k doesn't care where in the ranked list relevant documents appear. Getting 3 relevant docs in positions 1, 2, 3 is much better than positions 8, 9, 10—but they both give you precision@10 of 30%.

MAP solves this by rewarding systems that rank relevant documents higher.

How MAP Works

Average Precision (AP) for a single query works like this:

  1. Go through your ranked results one by one
  2. At each position where you find a relevant document, calculate precision at that position
  3. Average those precision values
  4. Ignore positions with non-relevant documents

Mean Average Precision (MAP) simply averages AP across all queries in your evaluation set.

Example

Query results: [relevant, irrelevant, relevant, irrelevant, relevant]

  • Position 1 (relevant): precision = 1/1 = 1.0
  • Position 3 (relevant): precision = 2/3 ≈ 0.67
  • Position 5 (relevant): precision = 3/5 = 0.6

AP = (1.0 + 0.67 + 0.6) / 3 = 0.76

If you had two queries with APs of 0.76 and 0.84, MAP = (0.76 + 0.84) / 2 = 0.80

Why It Matters for RAG

In RAG systems, MAP tells you if your retriever consistently puts the best documents at the top—critical because you typically only pass top-k chunks to the LLM. A system with high MAP wastes fewer tokens on irrelevant context.

Key Takeaway: MAP evaluates both retrieval completeness and ranking quality by averaging precision scores at each relevant document position, making it ideal for assessing RAG retrieval systems where rank order directly impacts generation quality.