Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-249

RRF Score for a Document

Problem

Return the reciprocal rank fusion score of a single document: the sum over rankings of 1 / (k + rank) for every list where doc appears, with ranks starting at 1.

Return 0.0 when doc appears in none of the rankings.

Hint

Scan every ranking and only add the lists that contain doc.

Test cases

case 1
in: [[["a","b"],["b","a"]],"a",60]
expected: 0.03252247488101534
case 2
in: [[["a"]],"b",60]
expected: 0
case 3
in: [[],"a",60]
expected: 0
case 4
in: [[["x","y","z"]],"z",1]
expected: 0.25
case 5
in: [[["a","b"],["c","a"]],"a",0]
expected: 1.5
Starter codePython
def rrf_document_score(rankings, doc, k=60):
    # Your code here
    pass

5 test cases · run your code against them in the editor