promptdojo_

Retrieval metrics and vector-DB shape — recall@k, MRR, and why the filter runs before the search — step 6 of 7

Write recall_at_k(retrieved, relevant, k): take the first k ids from the ranked retrieved list, count how many are in the relevant set, and return that count divided by the size of the relevant set.

The harness runs it at k=1, 3, and 5. Expected output:

recall@1: 0.00
recall@3: 0.50
recall@5: 0.75

Notice the shape of those numbers: recall@k can only go up as k grows. That's why "just raise k" always looks like a fix — until you remember precision falls and the token bill climbs with it.

full-screen editor opens — close anytime to keep reading.