Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 39/ 160
02. RAG

Recall@k

Measure whether the right documents appear in the top-k retrieved set.

IntermediateRetrieval Metric · Top-k3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

It counts how often the right answer is somewhere in the first few results the search returned.

Think of it like…

A hiring shortlist: recall@10 asks, of all the genuinely qualified applicants, how many ended up on the shortlist of 10? A qualified person left off the list can never be hired, however good the interviewers are.

Where you’ve seen it

A team builds 250 test questions, each labelled with the chunk ids that contain the answer. Dense retrieval gives recall@5 = 0.72 and recall@50 = 0.93; hybrid search lifts recall@5 to 0.81 and recall@50 to 0.97. Because recall@50 is 0.97, they rerank 50 candidates and keep 6: the reranker can fix ordering but can't recover the 3 percent that never made the list, which they investigate individually and find mostly parsing failures.

Words you’ll hear

Relevant set
The labelled documents or chunks that contain the answer for a query.
Top-k
The first k results returned by the retriever.
Hit rate
Share of queries with at least one relevant result in the top k.
Recall–precision trade-off
Larger k raises recall but lowers precision (more irrelevant results).

Visual diagram

Loading interactive diagram

Theory & deep dive

Definition, variants and a worked example

For query q with relevant set R(q) and retrieved top-k list T_k(q): recall@k(q) = |R(q) ∩ T_k(q)| / |R(q)|, and the reported score is the mean over queries. When each query has exactly one relevant item, recall@k equals hit rate@k. Example: q has two relevant chunks {c88, c91}; the top-5 contains c88 but not c91, so recall@5 = 1/2 = 0.5 and hit@5 = 1. A related metric, precision@k = |R ∩ T_k| / k, measures how clean the list is: with one relevant chunk in the top 5, precision@5 = 0.2.

Different k answer different questions. Recall@k for k equal to the number of chunks you pass to the LLM (for example 5 or 6) tells you about final context quality; recall@k for the candidate depth you give a reranker (30 to 100) tells you the ceiling the reranker can reach. Many RAG answers need several chunks (multi-part questions), so report recall rather than only hit rate when queries have multiple relevant items.

Two queries, one average

q1: relevant {a}, top-5 contains a → recall 1.0. q2: relevant {b, c}, top-5 contains b only → recall 0.5. Mean recall@5 = 0.75; hit@5 = 1.0 (both queries have at least one relevant result).

Key takeaway: Recall@k = share of relevant items found in the top k; pick k to match your pipeline.

Building a test set and using the metric well

Create the evaluation set from real questions (logs, support tickets, subject-matter experts), with a labelled relevant chunk or span for each. You can bootstrap with an LLM that generates questions from chunks, but review a sample, because synthetic questions tend to be easier and echo the chunk's wording. Aim for 100 to 300 queries covering different question types, document types, languages and difficulty levels, and keep a held-out portion. Label at the document or passage level and remember chunking changes: store the source document and passage so labels can be mapped to new chunk ids.

Use recall@k to compare methods fairly (same queries, same k): dense vs BM25 vs hybrid, chunk sizes, embedding models, filters, query rewriting. Slice results by query type to find weak spots (identifier queries, multi-hop questions, other languages), and inspect failures individually. Recall@k ignores order inside the top k and gives no credit for ranking relevant items higher, so pair it with a rank-aware metric (MRR, nDCG) when order matters, and always confirm that gains in recall translate to better end-to-end answers.

A comparison table

Dense: recall@5 0.72, @50 0.93. BM25: 0.65, 0.88. Hybrid: 0.81, 0.97. Hybrid + contextual chunks: 0.86, 0.98. Slicing shows identifier queries improved most with hybrid (0.52 → 0.91).

Key takeaway: Use a realistic labelled set, compare methods at matching k, slice by type, and inspect failures.

How it works, step by step

Step 1 of 4
Dataset

1. Build a labelled query set

Collect 100–300 real questions and label the chunk or passage ids that contain each answer.

q17 → {c88, c91}
Key numbers at this step
Review
synthetic questions

When to use it & trade-offs

What it is

Recall@k measures how often a retriever puts the relevant document(s) inside its top k results. For one query: recall@k = (relevant documents found in the top k) ÷ (total relevant documents), and averaged over queries. With one relevant document per query it equals the hit rate: the share of queries where the answer is in the top k. It answers the RAG question "did we even bring the evidence into the candidate set?", which must be true before any reranker or LLM can use it.

Why it matters: If the right chunk isn't retrieved, the best prompt and model can't produce a grounded answer. Recall@k isolates retrieval from generation so you can tune chunking, embeddings, hybrid search and filters with a clear number, and decide how many candidates to rerank. It's cheap to compute, doesn't need an LLM judge, and is the first metric to build for any retrieval system.

When to reach for it

  • Comparing chunking, embeddings and hybrid search
  • Choosing how many candidates to rerank
  • Regression tests for the retrieval layer

When to avoid or be careful

  • Judging retrieval from a handful of hand-picked queries
  • Comparing methods at different k
  • Treating recall gains as proof of better answers

Retrieval metrics

Recall@k
Best for: Did the evidence reach the candidate set?

Strengths: Simple; no LLM judge; ties to reranker depth.

Watch out: Ignores order within the top k.

Precision@k
Best for: How clean is the context we send?

Strengths: Reflects noise in the prompt.

Watch out: Falls as k grows even when recall rises.

MRR / nDCG
Best for: Ranking quality

Strengths: Rewards relevant items appearing earlier.

Watch out: More complex; needs graded or first-hit labels.

Interview signals & numbers to know

When this topic comes up

  • “How do you evaluate retrieval?”
  • “The answer isn't in the retrieved chunks”
  • “How many candidates should we rerank?”
  • Hit rate
  • Evaluation datasets

Benchmarks & rules of thumb

100 – 300 -
queries in a decent evaluation set
0.72 → 0.81 -
recall@5 gain from hybrid in the example
k = LLM context size -
the most relevant k to report

Common mistakes & follow-ups

Common interview mistakes

  • Labelling relevance at the chunk id level and then re-chunking, which invalidates the labels.
  • Reporting only recall@50 and ignoring that the LLM sees just the top 6.
  • Using only LLM-generated easy questions and overestimating real-world recall.

Likely interviewer follow-ups

  • How is recall@k different from precision@k?
  • How would you build a retrieval test set?
  • Why isn't recall@k enough on its own?
Interview tip: Report recall at two k values: the k you give the LLM and the k you give the reranker. That reveals both the pipeline's quality and its ceiling.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Recall@k with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Agentic RAG
Next topic
MRR and nDCG