All problems
Weighted RRF Hybrid Fusion
Problem
Fuse a dense ranking and a sparse ranking with weighted reciprocal rank fusion. Each document scores weight_dense / (k + dense_rank) plus weight_sparse / (k + sparse_rank) when it appears, with ranks starting at 1.
Return document ids sorted by descending fused score, breaking ties alphabetically.
Hint
Accumulate contributions from both lists into one score dictionary before sorting.
Test cases
case 1
in: [["a","b"],["b","c"],1,1,60]
expected: ["b","a","c"]
case 2
in: [[],["x","y"],1,1,60]
expected: ["x","y"]
case 3
in: [["a"],["a"],2,3,60]
expected: ["a"]
case 4
in: [[],[],1,1,60]
expected: []
case 5
in: [["x","y"],["y","x"],0.5,2,10]
expected: ["y","x"]
Starter codePython
def weighted_rrf(dense_ranking, sparse_ranking, weight_dense, weight_sparse, k=60):
# Your code here
pass5 test cases · run your code against them in the editor