Keyword search and semantic search are good at different questions. Combining them sounds easy until the two give scores that cannot be compared.
01 · Two strengths
One finds the exact words. The other finds the meaning.
Keyword search, such as BM25, rewards documents that contain the query's rare words. It is excellent for names, codes and exact phrases, and blind to a synonym.
Semantic search compares embeddings, numeric summaries of meaning. It finds a passage that says the same thing in different words, and it can miss an exact identifier that has no real meaning to the model.
02 · The obstacle
Their scores are on different scales.
A keyword score might run from 0 to 30 and depend on the size of the collection. A cosine similarity runs from -1 to 1 and bunches near the middle. Adding them, or even normalising them, is fragile: a small change in the data shifts the balance.
What both methods do reliably is put results in an order. The rank is comparable even when the score is not.
03 · The method
Give each result 1 / (k + rank) from every list, and add.
In reciprocal rank fusion, a document at rank 1 in a list earns 1 / (k + 1), at rank 2 earns 1 / (k + 2), and so on. A document's final score is the sum across all the lists it appears in. A common choice is k = 60, from the paper that introduced the method.
The constant k softens the top. Without it, rank 1 would be worth twice rank 2. With k = 60 the gap is small, so a document that is good in both lists beats one that is first in only one.
Agreement between methods counts for more than a single method's enthusiasm.
04 · In practice
Simple, with a few things to watch.
It will not rescue a poor index. Fusion combines good lists well; it cannot create a good list from bad chunks.
- No tuning of scoresThere are no weights to calibrate between methods, which is much of the appeal.
- Fuse enough depthTake the top thirty or so from each list. Fusing only the top three discards the documents that both methods liked moderately.
- Keep varietyAfter fusing, limit how many results can come from one page or source, so one long document does not fill the answer.
05 · Worked example
Three documents, two lists, k = 60.
Suppose document A is ranked first by keyword search and third by semantic search. Document B is ranked second by keyword search and not at all by semantic search. Document C is ranked first by semantic search only.
A scores 1/61 + 1/63, about 0.0323. C scores 1/61, about 0.0164. B scores 1/62, about 0.0161. The fused order is A, C, B: the document both methods liked comes first, and the two that only one method liked follow, in almost a tie.
06 · Pitfalls
Mistakes that weaken the fusion.
- Fusing too fewTake the top thirty or so from each list. If you fuse only the top three, documents both methods rated moderately are lost.
- Different units in each listIf one list ranks chunks and the other ranks whole pages, convert them to the same unit first, or the same page is counted twice.
- No test setCompare keyword alone, semantic alone and fused on the same questions. Fusion should win on the set, not just on a favourite example.
- Judging only the top resultLook at where the right passage lands. Moving it from rank six to rank two matters even if it is not first.
What I took away
- Combine ranks, not scores, when the scales differ.
- Sum 1 / (k + rank) across lists; k = 60 is a common default.
- Fusion helps good retrieval. It does not repair bad chunking.