
Fuse two ranked lists
mediumFuse two ranked lists
Hugging Face RAG Interview Question
Hybrid search runs a keyword query and a vector query and gets back two ranked lists with no comparable scores. Reciprocal rank fusion combines them using only the positions, counting the top of a list as rank 1.
Write a function fuse(lists, k) that returns every document id ordered by its total score, highest first. Break ties by id in alphabetical order.
Note
Asked of
- AI Engineer
- ML Engineer
- Data Scientist
Example 1
Input
lists = [["a", "b"], ["b", "c"]], k = 60
Output
["b", "a", "c"]
Example 2
Input
lists = [["x"], ["x"]], k = 60
Output
["x"]
Explanation
With k = 60, "b" scores 1/61 from the first list and 1/61 from the second, which is more than "a" gets from its single first place. A document near the top of both lists beats one that is first in only one.
Submit also runs 2 hidden test cases that check edge cases.
- Ranking
Similar questions
Company
Hugging Face
Difficulty
medium
Topic
RAG
Language
Python
Your code
Loading Python in the background. You can start writing.