NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Senior2 views

How are Recall and Precision metrics calculated in the context of document retrieval?

Practice

AI answer

Document search is usually evaluated against relevant documents labeled for each query:

  • Precision = number of retrieved relevant documents / total number of retrieved documents. It shows what proportion of the results are relevant.
  • Recall = number of retrieved relevant documents / total number of relevant documents in the collection. It shows what proportion of all relevant documents were found.

For example, if the system returns 10 documents, 8 of which are relevant, and there are 20 relevant documents in total, then Precision = 8/10 = 0.8 and Recall = 8/20 = 0.4. For ranked results, Precision@k, Recall@k, MAP, or nDCG are often used as additional metrics. Calculating these metrics requires ground-truth relevance labels for a set of test queries.