Metrics

A metric turns a ranked list of results into one number. judy reports seven at a depth k. The set sets k, or you pass --k. Every metric reads only two things: the ids the search returned, in order, and the grades people gave them. That is why judy scores every kind of search the same way.

The examples on this page use one query from the offline quickstart. The query is yellow fruit, and the search returns three results.

Query yellow fruit. The search returns apple with grade 0, lemon with grade 2 and banana with grade 3.

Metric The question it answers Value for the example
success@k Is there a relevant result in the top k? success@1 0, success@3 1
mrr@k How high is the first relevant result? 0.5
ndcg@k How good is the whole order? 0.606
recall@k How many of the relevant results did the top k find? 1.0
precision@k How many of the top k are relevant? 0.667
err@k How likely is a searcher to stop early? 0.370
judged@k How much of the top k has a rating? 0.6

A scorecard prints the mean over the queries it can score. precision@k is not in the default scorecard. You can ask for any metric by name, written kind@k (for example precision@5 or ndcg@20), in a set's gates and with judy compare --metric.

success@k is 1 when any relevant result sits in the top k, and 0 otherwise. It matches what a searcher feels: did I see something right at the top?

In the example, the first result is an apple. So success@1 is 0. A lemon and a banana follow, so success@3 is 1.

Trust it when you care about the first screen. It ignores how good the result is, and where it sits inside the top k.

mrr@k is the reciprocal rank of the first relevant result. A first relevant result at rank 1 scores 1. At rank 2 it scores 1/2, and at rank 4 it scores 1/4. The mean over queries is the mean reciprocal rank (definition).

In the example, the first relevant result is the lemon at rank 2, so mrr is 0.5. A mean of 0.859 means the first relevant result sits at roughly rank 1.2.

Trust it when one good answer is enough, such as a search for a known item. It ignores every result after the first good one.

ndcg@k scores the whole order. A result earns a gain of 2^grade - 1. The gain shrinks by log2(rank + 1), so the same result counts less the lower it sits. The sum is the discounted cumulative gain. Dividing it by the sum for the best possible order gives a value from 0 to 1 (definition).

The apple, lemon and banana order earns 5.393. The best order, banana then lemon then apple, earns 8.893. The ratio is 0.606.

Trust it when your grades have more than two levels. It is the metric to improve in most cases. It rewards the best result at rank 1, and it punishes a great result buried at rank 8. Compare it against a baseline, because the best value you can reach depends on your data.

recall@k is the share of the relevant results that the top k found. precision@k is the share of the top k that is relevant (definition).

In the example, two results are relevant and the top 3 holds both. So recall@3 is 1.0, and precision@3 is 2/3.

Trust recall when each query has fewer relevant results than k. It is low whenever a query has more relevant results than k. WANDS has hundreds for some queries, so a recall@10 of 0.057 is not a failure.

err@k is the expected reciprocal rank. It models a searcher who reads down the list and stops when satisfied. A great result high up makes the searcher stop, so the results below it matter less (paper).

Trust it when you want a second opinion on nDCG. It agrees with nDCG on most changes. It disagrees when a perfect result at rank 1 matters more to you than a good list.

judged@k is the share of the top k that has a judgement of any grade. A result that nobody rated counts as not relevant.

Ten result slots. Seven are rated and three are not. The value of judged at 10 is 0.7.

Trust the other metrics only when judged@k is high. A new target can return many results that your set has never seen. Its scores are then a floor, so the comparison is unfair to it. judy compare warns when the two sides rated different shares of their top results, at a gap of 0.10. Semantic and hybrid search surface unrated results most. judy judge rates them (see the LLM judge).

Text
ndcg@10    0.594
judged@10  0.865

A query with no relevant result in its judgements gets no relevance score. judy counts it (480 (479 scorable)). It leaves the query out of the means.

judy computed the metrics on the same index, queries and judgements as Elasticsearch's own _rank_eval API. The mean nDCG@5 is 0.9237767155100333 in judy and 0.923776715535 in Elasticsearch. The difference is in the eleventh decimal place.