LESSON 96 / 215·2 min readIntermediate

Retrieval precision, recall, relevance, and ranking

Must knowConcept lesson
01 Understand02 Recall03 Prepare

Words made simple

A few useful meanings before you read the explanation.

Retrieval
Finding and fetching information that is useful for the current question.
Embedding
A list of numbers that represents the meaning of some content. Similar meanings can produce nearby lists of numbers.
Chunking
Dividing a long document into smaller pieces so relevant parts can be found and sent to the model.
More words from this lesson
Overlap
Repeating a small amount of text in neighboring document chunks to help retain context near their boundaries.
Reranking
Checking an initial set of search results again and putting the most useful ones nearer the top.

Overview

  • Precision measures how many retrieved items are relevant.
  • Recall measures how much relevant evidence was retrieved.
  • Relevance indicates usefulness for the query; ranking metrics also consider whether good evidence appears early enough to be used.

Why this matters

Generation cannot answer from evidence it never receives, and irrelevant evidence adds cost and confusion.

An everyday example

Finding two needed books and eight unrelated books is different from finding only one of four needed books.

A technical example

Relevant IDs are {A,B,C} and top-3 results are {A,X,B}: precision@3 is 2/3, recall@3 is 2/3.

How it works

  1. Label eligible relevant chunks/documents
  2. Retrieve top-k
  3. Compare sets and positions
  4. Aggregate by query type
  5. Inspect gaps.

Architecture and flow

Query + relevant source labels → retrieval → precision/recall/rank metrics.

The insurance assistant example

Evaluate whether both a coverage clause and its exception appear in the selected evidence.

When to use it

Chunking, embedding, hybrid-search, index, and reranker comparisons.

When to avoid it

Do not calculate recall from incomplete labels without acknowledging the limit or count duplicated overlap chunks as independent relevant evidence.

Interview answer

“Recall tells me whether needed evidence was found; precision and rank tell me how useful the returned context is. I evaluate at a consistent evidence granularity.”

Benefits, trade-offs, and production considerations

  • MRR, mean reciprocal rank, rewards the position of the first relevant result. nDCG rewards useful graded results near the top.
  • Label source sections or normalized evidence units when chunker changes make exact chunk IDs unstable.
TypeScript
function retrievalMetrics(retrieved: string[], relevant: Set<string>) {
  const unique = [...new Set(retrieved)];
  const hits = unique.filter((id) => relevant.has(id)).length;
  return {
    precision: unique.length ? hits / unique.length : 0,
    recall: relevant.size ? hits / relevant.size : null,
  };
}
// null recall marks an unlabeled/no-relevant-evidence case for separate scoring.

For a query with no answer in the corpus, evaluate correct abstention and irrelevant retrieval separately rather than pretending conventional recall is meaningful.

PAUSE & RECALL

Can you explain it without the notes?

Retrieval precision, recall, relevance, and ranking

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Precision measures how many retrieved items are relevant. Recall measures how much relevant evidence was retrieved. Relevance indicates usefulness for the query; ranking metrics also consider whether good evidence appears early enough to be used.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Faithfulness, answer correctness, and citation quality

Adapted from 13_AI.MD · “Retrieval precision, recall, relevance, and ranking”. Examples are study fragments; framework behavior can depend on your version.