LeepCast
Subscribe
All posts
AI & ML

Hybrid Search Explained: Combining BM25 and Vector Results With Reciprocal Rank Fusion

Keyword search and embedding search fail on different queries. Here is how reciprocal rank fusion merges their result lists, why k = 60 is the usual constant, and when score normalization is the better choice.

LeepCast7 min read

Most retrieval systems that sit behind a search box or a RAG pipeline end up running two searches for every query. A lexical search such as BM25 finds documents that contain the words the user typed. A dense vector search finds documents whose embeddings sit close to the embedding of the query, even when they share no words with it. Each one is good at exactly the queries the other one fumbles, so the obvious next step is to run both and merge the results. The merge is where most of the design decisions hide.

This explainer walks through why the two retrievers disagree, why you cannot simply add their scores together, how reciprocal rank fusion (RRF) sidesteps that problem by looking only at positions, and when a score-based fusion method is the better tool.

Why keyword and vector search fail on different queries

BM25 rewards exact term overlap, weighted so that rare terms count more than common ones. That makes it strong on queries containing identifiers, error codes, product SKUs, function names and proper nouns. A user who pastes ERR_CERT_DATE_INVALID wants the page that contains that exact string, and BM25 will usually rank it first. It is weak when the user describes a problem in different words than the document uses: a query about a lost phone will not match an article titled Account recovery unless the words overlap.

Embedding search has the opposite profile. It handles paraphrase, synonyms and loosely worded questions well, because the model has learned that lost phone and account recovery are related ideas. It is often weak on rare tokens: an unfamiliar part number or a short code may be split into fragments the model has never meaningfully learned, so the nearest neighbours end up being documents that are generally about the same topic rather than the one document that contains the code.

Running both and fusing the lists gives you a retriever that degrades gracefully on both kinds of query. The question is how to fuse.

The problem with adding raw scores

The tempting approach is to add the BM25 score and the cosine similarity for each document and sort by the sum. This breaks because the two numbers live on unrelated scales. BM25 scores are unbounded and depend on the query length, the corpus statistics and the field lengths; a strong match might score 14 on one query and 40 on another. Cosine similarity from a typical embedding model is bounded and often clustered in a narrow band, so the gap between the best and fifth-best neighbour might be a few hundredths.

Add those together and BM25 dominates almost every time, because its spread is hundreds of times larger. You could multiply the cosine score by a constant to compensate, but the right constant changes from query to query, so any fixed value is wrong most of the time.

How reciprocal rank fusion works

RRF throws the scores away and keeps only the rank each retriever assigned. Cormack, Clarke and Buettcher introduced it at SIGIR 2009 as a simple baseline for combining rankings from multiple retrieval systems. For every document, you add up one term per result list it appears in, where each term is 1 divided by the sum of a constant k and the document's rank in that list (rank 1 is the top result). Documents missing from a list contribute nothing for that list. Then you sort by the total.

Two properties fall out of that formula. First, it is scale-free: a retriever that returns scores between 0 and 1 and one that returns scores in the hundreds are treated identically, because only positions matter. Second, it rewards agreement. A document that both retrievers place in their top few will beat a document that one retriever loves and the other never returned, unless that single ranking is very high.

What the constant k does

The constant k controls how quickly credit decays as you move down a list. With a small k, the gap between rank 1 and rank 2 is large, so a single retriever's top result can carry the fused ranking on its own. With a large k, the curve flattens and appearing in several lists matters more than being first in one. The paper fixed k at 60 after a pilot study and reported that the value was near-optimal but not critical: in its table of pilot results, mean average precision barely moved for k anywhere from about 20 to 100. That is why 60 shows up as the default in so many systems, including the rank_constant setting in Elasticsearch and the ranked fusion formula Weaviate describes.

A worked example in Python

Here is a complete RRF implementation with optional per-retriever weights, applied to an invented query against a support knowledge base. The BM25 list favours articles that contain the literal words; the vector list surfaces a related article about losing a phone that BM25 missed entirely.

python
from collections import defaultdict

def rrf(rankings, k=60, weights=None):
    """Fuse ranked lists of doc IDs. Best result first in each list."""
    weights = weights or [1.0] * len(rankings)
    scores = defaultdict(float)
    for ranking, w in zip(rankings, weights):
        for rank, doc_id in enumerate(ranking, start=1):
            scores[doc_id] += w / (k + rank)
    return sorted(scores.items(), key=lambda item: item[1], reverse=True)

# Query: "reset 2FA on account" over a support knowledge base
bm25   = ["kb-2fa-reset", "kb-login-errors", "kb-sms-codes", "kb-billing"]
vector = ["kb-lost-phone", "kb-2fa-reset", "kb-account-recovery", "kb-sms-codes"]

for doc_id, score in rrf([bm25, vector]):
    print(f"{doc_id:22s} {score:.5f}")

Running it prints the fused order below. The document ranked first by BM25 and second by vector search wins, scoring 1/61 + 1/62. The SMS codes article was only third and fourth in the two lists, yet it climbs to second place because both retrievers returned it, while the lost-phone article that topped the vector list lands third on a single contribution of 1/61.

text
kb-2fa-reset           0.03252
kb-sms-codes           0.03150
kb-lost-phone          0.01639
kb-login-errors        0.01613
kb-account-recovery    0.01587
kb-billing             0.01562

Passing weights=[1, 2] doubles every vector contribution. The top two stay the same, but kb-account-recovery jumps from fifth to fourth, ahead of kb-login-errors, because semantic matches now count twice as much. Weighting is the simplest knob for biasing a hybrid system toward one retriever without abandoning rank fusion.

Score normalization: the main alternative

The other family of fusion methods keeps the scores but rescales each list before combining. OpenSearch's normalization processor offers min_max (the default), l2 and z_score normalization, followed by a weighted combination such as arithmetic_mean. Weaviate's relativeScoreFusion, which became its default in version 1.24, does a min-max rescale of each result set so the best hit becomes 1 and the worst becomes 0, then adds the two using an alpha weight.

Normalization preserves information that RRF discards: how much better the top result was than the runner-up. If BM25 finds one document with an overwhelming exact match, a score-based method can let that lead survive, whereas RRF only sees that it was first. Weaviate's own comparison shows exactly this, with a document that had a large keyword lead finishing first under relative score fusion but not under ranked fusion.

Normalization has its own trap. Min-max stretches whatever gaps exist to fill the 0 to 1 range, including meaningless ones. Suppose the vector scores for four results are 0.83, 0.81, 0.79 and 0.78. After min-max they become 1.0, 0.6, 0.2 and 0.0, so a difference of 0.05 in cosine similarity now looks as decisive as a BM25 gap of 14.2 against 3.1. When every candidate is about equally relevant, normalization manufactures confidence that is not there.

RRF versus score normalization at a glance

  • Inputs: RRF needs only ranks; normalization needs comparable raw scores from each retriever.
  • Tuning: RRF works acceptably with k = 60 and no labelled data; normalization usually needs a tuned weight per corpus.
  • Score gaps: RRF ignores them; normalization keeps them, which helps with dominant exact matches and hurts with flat distributions.
  • Adding a third retriever: RRF just appends another list; normalization requires deciding how the new scores scale against the others.
  • Explainability: RRF scores are easy to recompute by hand from positions; normalized scores depend on the min and max of each result set.
  • Pagination: both depend on how many candidates each retriever returned, so the window size must stay fixed for stable paging.

Common mistakes when fusing results

  1. Fusing too few candidates. If each retriever returns only ten results, a document ranked twelfth by both never gets a chance. Retrieve a wider window, such as 50 to 100 per retriever, then fuse and truncate. Elasticsearch exposes this as rank_window_size.
  2. Expecting deep pages to work. In Elasticsearch, a request whose from plus size exceeds rank_window_size returns no results, and paging stays consistent only while the window size is unchanged.
  3. Treating the fused score as a relevance probability. An RRF total of 0.032 says nothing absolute; it is only meaningful relative to other documents for the same query, so do not use it as a fixed cut-off threshold.
  4. Tuning k before measuring anything. The original paper found the constant was not critical. Changing retriever weights or the candidate window usually matters more, and either change should be checked against a set of labelled queries.
  5. Skipping the reranker question. Fusion decides which candidates to keep; a cross-encoder reranker can then reorder the fused top results with much better precision, at extra latency.

When not to bother with hybrid search

Hybrid retrieval doubles the query work and adds a second index to keep in sync. If your queries are almost entirely exact lookups, such as order numbers, log lines or code symbols, BM25 alone may be enough. If your documents and queries are short natural-language passages with few rare identifiers, a good embedding model alone may perform just as well. The honest way to decide is to build a small evaluation set of real queries with known relevant documents and compare recall at your chosen cut-off for BM25, vector search and the fused result.

A practical default

For most new systems, a sensible starting point is to retrieve around 50 candidates from each retriever, fuse them with RRF at k = 60 and equal weights, and pass the top 10 to 20 to a reranker or straight to the model. Measure, then adjust the weights if one retriever is consistently more reliable for your queries. Move to score normalization only when your evaluation shows that strong exact matches are being buried, because that is the specific failure RRF's rank-only view creates.

Share

Enjoyed this?

Get the next deep dive in your inbox. No spam — just the stories worth reading.

Subscribe to the newsletter

Comments