
A troubleshooting search page needs one answer quickly. A relevant result at the first position has more practical value than one buried after several distractors. The reciprocal depends only on the earliest known relevant result. Later relevant material does not change this query’s score.
Audit the inputs first
These fixtures model a small index or a short ranked list. They deliberately make it possible to inspect individual tokens and documents. A production evaluation should preserve the query, corpus revision and candidate list that generated each score.
def evaluate(v):
return next((1/i for i,k in enumerate(v[0],1) if k in set(v[1])),0.0)
for sample in [[['x', 'guide', 'y'], ['guide']], [['guide', 'x'], ['guide']], [['x', 'y'], ['guide']]]:
print(evaluate(sample))Check the operating boundary
| Example input | Calculated output |
|---|---|
| [["x", "guide", "y"], ["guide"]] | 0.5 |
| [["guide", "x"], ["guide"]] | 1.0 |
| [["x", "y"], ["guide"]] | 0.0 |
For [["x", "guide", "y"], ["guide"]], the observed output is 0.5. With [["guide", "x"], ["guide"]], it becomes 1.0. If a second implementation produces a different answer, begin with these small inputs. They allow a reviewer to trace the expression without reconstructing the entire application or replaying a production workload.
The value for [["x", "y"], ["guide"]] is 0.0. Record the unit or indexing convention next to that expectation. A second implementation can return the same type and still disagree about where a boundary falls or which observations enter the calculation.
The second case changes the reported quantity by 0.5 compared with the first. That is an absolute difference in the reported scale. Calling it a relative percent change would require dividing by an appropriate starting value and handling a baseline of zero.
Where this calculation stops
For a research workflow needing multiple sources, pair this measure with coverage at a specified result depth.
For a repeatable comparison, retain one counterexample as well as one ordinary success. In this fixture, [["guide", "x"], ["guide"]] makes a useful starting point: its reference result is 1.0. A changed result is a prompt to inspect the inputs, dependency version and chosen policy before accepting a new baseline.
A reproduction of reciprocal rank should keep the corpus revision with the case. Here the original first input is [["x", "guide", "y"], ["guide"]]. In a production note, include the text snapshot, vocabulary and relevance judgements used for this run. This makes it possible to tell a code regression apart from a document added or removed from the index when the same evaluation is run again.
Stanford Introduction to Information Retrieval · Python numeric types
Sources and further reading
Cover photograph: Laptop on a desk (Unsplash) by Aleksi Tappura a. CC0. Cropped and typeset for this cover. The photograph illustrates the topic.
