Retrieval is tested separately from answers, with metrics computed from document IDs. For each query you know which documents are relevant, and you have the ranked list the retriever returned:
- Recall@k: the share of the relevant documents that appear in the top k.
- Precision@k: the share of the top k slots that hold a relevant document. Divide by k, even when fewer than k came back.
- MRR (mean reciprocal rank): 1 divided by the position of the first relevant document, averaged over queries; 0 when none was returned.
Your task
Implement the three functions. The script averages them over the queries at k = 3. On submit they also run on queries you have not seen, including one that returned no documents at all.