Command Palette

Search for a command to run...

Hectal
Phase 3: Vector Search: Exact, IVF, HNSW and Smaller Vectors
RAG and Vector Search · Exercise 2 of 6 PreviousNext
Beginner

Recall at k, and its average

Write recall_at_k(found, truth, k): look only at the first k ids of each list, and return the fraction of truth[:k] that also appears in found[:k]. Order does not matter. If truth[:k] is empty, return 1.0 (there was nothing to find).

Write average_recall(runs, k) where runs is a list of (found, truth) pairs. Return the average recall@k, or 0.0 for an empty list.

What Check tests

  1. Two of four neighbours found gives 0.5
  2. Order does not matter
  3. Only the first k ids count
  4. Nothing found gives 0
  5. Nothing to find gives 1
  6. The average is over queries

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.