Fuse candidate rankings
Implement reciprocal_rank_fusion(rankings, k=60, limit=10). Rankings contain string document identifiers. Deduplicate each ranking while preserving first occurrence, assign compact ranks starting at 1, and sum 1/(k+rank). Return identifiers ordered by descending sum and ascending identifier for ties. Reject negative k or limit. This lab receives rankings as input; it does not create embeddings or contact a database.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
EXAMPLE 1
Input[[A,B,C],[B,D,A]], k=2
Output[B,A,D,C]
EXAMPLE 2
Input[[a,a,b],[b]], k=0
Output[b,a]
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor