Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 17 / Topic 2 of 6

Measuring retrieval

Before any prompt is written: can the retriever even find the right document? If not, the model cannot possibly answer correctly. The metric is recall@k over labelled question–document pairs:

# examples/01_measure_retrieval_before_building_rag_recall.py (abridged)
for k in [1, 3]:
    hits = [q["relevant"] in retrieve(q["question"], k) for q in EVAL_QUESTIONS]
    print(f"recall@{k} = {sum(hits)}/{len(hits)}")
# recall@1 = 6/8
# recall@3 = 7/8
# miss at k=1: 'How long do I have to send something back?' -> damaged (wanted returns)
# miss at k=1: 'When will my express order arrive?' -> cancel (wanted shipping)

Eight labelled questions already localise the weakness: both misses are paraphrases sharing no keywords with their documents — Part 16's sparse gap, measured. That tells you the fix (dense/hybrid retrieval) before you touch a prompt.

🧪 Quick quiz

  1. What does recall@3 = 7/8 mean?
Show the answer

For 7 of 8 questions, the relevant document appeared in the top 3 results. A retrieval metric — it says nothing yet about answer quality.

Done here? The practice set for Part 17 — 4 exercises with solutions — is on the part page.

Search the guide