Build your own semantic search
Is it correct? (recall@k vs exact NN)·5 min

What recall@k measures

0 / 1

Two genuinely different questions hide behind "is my search good?", and the same word — recall — gets used for both. Keep them apart.

First: did my index find the true nearest neighbors? That's a correctness / self-consistency check against exact NN — and since you ARE the exact brute force, you should hit it perfectly.

Second (next chapter): did it find the docs humans marked relevant? That's retrieval quality against gold labels. This chapter grades recall vs exact NN, and that distinction is the whole point.

recall@k = fraction of the true top-k you retrieved

recall@k
recall@k = |retrieved_topk ∩ true_topk| / |true_topk|

Worked example: true top-5 = {12, 7, 88, 3, 41}; you returned {12, 7, 88, 3, 999} → 4 of 5 hits → recall@5 = 0.8.

Why recall@k = 1.0 is the bar here — and what it does NOT claim

The ground truth gt_knn.json is exact brute-force kNN (computed in float64). Your TS brute force computes the same thing. So your recall@10 against it should be 1.000 — anything less means a bug (a wrong cosine, a broken tie-break, a row-indexing slip). This is a regression test for your own engine, not a claim about retrieval quality. "1.000" here means "my engine is the exact NN," never "my engine finds 100% of the docs humans want."

recall vs precision — denominator matters

recall@k divides by the number of relevant (or true-NN) docs, not by k. Precision@k is the one that divides by k. They answer different questions; don't swap them.