Measuring Retrieval, Not Vibes: A Golden Set, Recall@k and MRR
How I stopped judging search changes by a few good-looking answers, what the evaluation measures, and why my golden set is still too small.
When you change a retrieval system, the temptation is to try three questions, like the results, and ship. That works until a change quietly makes a different class of question worse. For 3arif.ai I wanted changes judged on numbers.
The setup
The evaluation reads a golden set: one JSON object per line, each with a question, a type, and the stable references that count as a correct hit. A reference can be a verse, a hadith record or a chunk id, and any one of the listed references counts.
It then runs every question through a retrieval target once per mode and reports, per mode, recall at several cutoffs and mean reciprocal rank.
- Recall@k here is binary per question: did any relevant item appear in the top k results.
- MRR is the mean of one over the rank of the first relevant item, so it rewards putting the right passage first, not only somewhere in the list.
Both metrics are small pure functions with unit tests, so the maths is not in question. The hard part is the data and the plumbing.
Two targets, one interface
A retrieval target is just a function from a question and mode to ranked chunks. There are two:
- One runs the code in the checkout exactly as the chat endpoint does, including the query harness for Auto mode, the hadith-allusion merge and the reranker hook. It needs the real databases and keys.
- One calls a deployed API and keeps only the first sources event, the passages the answer is generated from, then disconnects. It needs no credentials, but because those sources carry no chunk ids, it cannot score rows labelled only by chunk id.
Tests use fakes, so the unit tests never need infrastructure.
Decisions that matter more than the metrics
A failed lookup is not a miss. If retrieval throws for a question, it is reported as errored and left out of the aggregates. Flaky infrastructure should not look like a quality regression.
Comparisons use the same questions. The change in each mode against the baseline mode is computed only over questions both modes scored, so an error on one side cannot skew the delta.
Negatives are measured differently. Out-of-corpus questions have no right answer to find. For those, the evaluation reports the top similarity score, so I can see whether the system returns something confident-looking when it should have nothing.
Unlabelled rows are loaded but never scored. I would rather see them listed than silently counted as zero.
The honest part: the golden set is small
The file currently has 81 rows: 74 labelled, 6 negatives and 1 unlabelled. They span verse lookups, hadith allusions, fiqh across several schools and marjaʿ, tafsīr, history, theology and cross-sectarian questions. That is enough to catch a gross regression and compare two modes. It is not enough to claim a small improvement is real, and several categories have only a handful of rows. Confidence intervals on a set this size are wide.
The labels are also human judgments about which sources count as correct, written by me and testers, so they inherit our blind spots.
How I use it
Before changing retrieval, I run the baseline and the change side by side across modes. A change has to help the questions it targets without hurting the categories it does not. When the numbers and my impression disagree, the numbers get a closer look, not a veto.
Next
Grow the set to hundreds of labelled rows with a reviewer outside my own head, add more negatives, and run the evaluation on a schedule so drift shows up without me remembering to check.
Takeaway
You do not need a big benchmark to start measuring. You need a stable file of questions, two honest metrics, a rule that infrastructure errors are not misses, and the discipline to report how small your sample is.