# Reciprocal Rank Fusion: Formula, k Tuning, and When It Loses

> Reciprocal rank fusion merges BM25 and vector rankings in hybrid search without mixing score scales. See the formula, k sweep, measured failures, Python code.

Reciprocal rank fusion (RRF) is often the default answer to hybrid search: retrieve with BM25 and vectors, then fuse with `k=60`. In our 8 November 2026 run, that default scored below vector search alone on nDCG@10 for both SciFact and NFCorpus. I measured it because “just use RRF” skips the decision that matters: whether the second retriever improves your own relevant results.

**The short answer:** RRF adds `1 / (k + rank)` for each ranked list that contains a document. It avoids comparing incompatible BM25 and cosine scores, but it also throws away score gaps and treats each list equally unless you add weights. Start with the formula below, then compare it with each single-retriever baseline on labeled queries before shipping.

## What is the reciprocal rank fusion formula?

For a document `d`, RRF sums its reciprocal rank contribution across each retriever:

```text
score(d) = Σᵢ 1 / (k + rankᵢ(d))
```

Ranks start at 1. A document missing from a list contributes 0 from that list. The final order is descending score. A weighted version multiplies each list's contribution by its weight: `Σᵢ wᵢ / (k + rankᵢ(d))`.

BM25 scores depend on term and corpus statistics; cosine similarity commonly sits on a different scale. RRF uses only the order inside each list, so it needs no score normalization. The cost: a rank-1 result contributes the same amount whether it barely beat rank 2 or led it by a large margin. The method comes from a 2009 paper by Cormack, Clarke and Büttcher, which [LanceDB's docs](https://lancedb.github.io/lancedb/python/python/) cite as the source of the familiar `k=60` default; that default wasn't chosen for modern BM25-plus-embedding search.

## How does k change the ranking?

`k` controls how quickly rank contributions fall. With low `k`, the first positions matter much more. With high `k`, deep candidates receive contributions closer to the top ranks, so agreement across lists matters more than a single strong position. [LanceDB's API docs (2026)](https://lancedb.github.io/lancedb/python/python/), citing the original paper for their default, say "k = 60 was near-optimal, but that the choice is not critical" in those experiments.

BM25 returns A at rank 1 and B at rank 2; vectors return C at rank 1 and B at rank 50. The shared document B benefits from the second list’s deep rank.

| document | BM25 rank | vector rank |             RRF at k=60 |            RRF at k=1 |
| -------- | --------: | ----------: | ----------------------: | --------------------: |
| A        |         1 |           — |         `1/61` = 0.0164 |        `1/2` = 0.5000 |
| B        |         2 |          50 | `1/62 + 1/110` = 0.0252 | `1/3 + 1/51` = 0.3529 |
| C        |         — |           1 |         `1/61` = 0.0164 |        `1/2` = 0.5000 |

At `k=60`, B ranks first because appearing on both lists outweighs either list’s rank-1 result. At `k=1`, B falls behind A and C. The `k` sweep shows the same direction in our run: smaller values retained more nDCG@10 than `k=60`, although the dense-only baseline still matters.

## Measured: RRF against BM25 and vector search

On both measured sets, plain RRF at `k=60` lost to vectors alone on nDCG@10. It did improve SciFact Recall@100, while lowering NFCorpus Recall@100. Min-max score fusion led on SciFact; both min-max fusion and weighted RRF with a 0.3 BM25 weight came close to the dense baseline on NFCorpus. Those are results from this setup, not a claim that those settings transfer to your corpus.

![nDCG@10 for BM25, vectors, score fusion, and RRF variants on SciFact and NFCorpus](/blog/reciprocal-rank-fusion/rrf-ndcg-by-method.svg)

_Source: author’s BEIR SciFact and NFCorpus measurement log, checked 8 November 2026._

| Method                       | SciFact nDCG@10 | NFCorpus nDCG@10 |
| ---------------------------- | --------------: | ---------------: |
| BM25                         |          0.6519 |           0.3070 |
| Vectors                      |          0.7318 |           0.3852 |
| Raw score sum                |          0.6575 |           0.3344 |
| Min-max score sum            |      **0.7466** |           0.3820 |
| RRF, k=60                    |          0.7163 |           0.3601 |
| RRF, k=5                     |          0.7392 |           0.3736 |
| Weighted RRF, k=60, BM25 0.3 |          0.7285 |           0.3806 |

The raw sum barely moved SciFact above BM25 alone: 0.6575 versus 0.6519. In that run, BM25 top scores ranged from 10.174 to 132.963 on SciFact, while cosine ranged from 0.366 to 0.832. Adding those values directly let the larger BM25 scale dominate. RRF avoids that scale mismatch, but the better-looking min-max result on SciFact shows normalization can work when the score distribution is useful. [Bruch, Gai & Ingber (2022), “An Analysis of Fusion Functions for Hybrid Retrieval”](https://arxiv.org/abs/2210.11934) also found convex score combinations ahead of RRF in its tested settings; that is evidence for evaluating alternatives, not a substitute for your own query labels.

The source benchmark matters. These were two biomedical/scientific BEIR sets (5,183 SciFact documents and 3,633 NFCorpus documents), one embedding model (`text-embedding-3-small`), top 100 from each retriever, and `rank_bm25` with lowercase `\w+` tokenization and no stemming. The [BEIR paper (Thakur et al., 2021)](https://arxiv.org/abs/2104.08663) ran BM25 through Anserini with Lucene defaults and indexed title and passage as separate fields, so its BM25 numbers aren't directly comparable with ours.

## k=60 lost to smaller k on both datasets

No. In this run, RRF nDCG@10 declined as `k` rose from 5 toward 60 on both datasets, and then flattened. SciFact RRF stayed above its vector-only baseline at `k=1` through `k=10`, then fell below it from `k=20` on. NFCorpus RRF stayed below its vector-only baseline at every tested `k`. Use this sweep to pick candidates for validation, not to call one value optimal for another corpus.

![nDCG@10 for RRF k values from 1 to 1000, with vector-only reference lines](/blog/reciprocal-rank-fusion/rrf-k-sweep.svg)

_Source: author’s BEIR SciFact and NFCorpus measurement log, checked 8 November 2026; x positions are log-spaced by k._

The retrievers’ top-10 lists overlapped by only 3.33 documents on SciFact and 2.92 on NFCorpus, on average. Equal-weight fusion therefore promoted many BM25-only candidates even though vectors were stronger overall in these test sets. Per query, `k=60` beat both single retrievers on 17 of 300 SciFact queries and 52 of 323 NFCorpus queries; it scored below the better single retriever on 80 and 157 queries, respectively. That “better single” is a per-query oracle, not a system you can choose in advance, but the gap is a reason to inspect query slices.

## When should I use weighted RRF in hybrid search?

Weight the retriever that wins more often on the relevant query class, and learn the weights from labeled queries. Exact identifiers, error codes, and symbol names often favor keyword matching; natural-language paraphrases can favor vectors. Treat that as a hypothesis to check against your own labels, not a rule about every search system.

For example, our code search tool, octocode, leans on BM25 for identifier- and symbol-like queries, while keeping its default weights for natural-language queries. It does this from query shape without an additional model call. Our memory and knowledge search tool, octobrain, uses LanceDB hybrid BM25 and vector search with RRF at `k=60`. [The Octocode code-search overview](/blog/octocode-mcp-semantic-code-search) shows the tool in context. I build Octomind and its search tools, so weigh that example as an implementation choice, not independent evaluation evidence.

For the measured 0.3 BM25 weight, `k=60`, nDCG@10 was 0.7285 on SciFact and 0.3806 on NFCorpus. That nearly recovered NFCorpus’s vector score of 0.3852; on SciFact it remained below vectors at 0.7318. A global weight is still a compromise when query classes behave differently. If enough labels exist per class, compare class-specific routing or weights on held-out queries.

## How do I implement reciprocal rank fusion?

A 10-line Python function is enough for two or more ranked lists. It expects document IDs in best-to-worst order and uses 1-based ranks, matching the formula above.

```python
def rrf(rankings, k=60, weights=None):
    if weights is None:
        weights = [1.0] * len(rankings)
    if len(weights) != len(rankings):
        raise ValueError("weights must match rankings")
    scores = {}
    for ranking, weight in zip(rankings, weights):
        for rank, doc_id in enumerate(ranking, start=1):
            scores[doc_id] = scores.get(doc_id, 0.0) + weight / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)

fused = rrf([bm25_ids, vector_ids], k=60, weights=[0.3, 0.7])
```

Keep the candidate depth fixed while comparing methods. This sample assumes each retriever returns unique document IDs; if yours can return duplicates, deduplicate each list before fusion. Tie-breaking follows Python dictionary insertion order, so define an explicit secondary key if reproducible tie order matters to your application.

Several engines expose hybrid fusion, but their defaults differ. Checked in November 2026:

| Engine          | Built-in path                                          | RRF `k` behavior                                                                      |
| --------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------- |
| Elasticsearch   | `rrf` retriever combines retriever result sets         | `rank_constant` defaults to 60; configurable                                          |
| OpenSearch      | Hybrid query with RRF search pipeline                  | `rank_constant` defaults to 60; configurable                                          |
| LanceDB         | Hybrid query defaults to `RRFReranker()`               | RRF default is 60                                                                     |
| Qdrant          | Server-side `RrfQuery` for prefetch results            | Default is 2; supports weights and custom `k`                                         |
| Weaviate        | Hybrid fusion options                                  | Relative Score Fusion is default since v1.24; it is not RRF and has no `k`            |
| Azure AI Search | Hybrid and parallel queries fuse automatically         | Docs describe an example `k=60`, but do not document a configurable default           |
| pgvector        | Combine PostgreSQL full-text and vector ranked queries | No built-in RRF operator or default; the pgvector example supplies `k` as a parameter |

See the [Elasticsearch Reference (2026)](https://www.elastic.co/docs/reference/elasticsearch/rest-apis/reciprocal-rank-fusion), [OpenSearch RRF docs (2026)](https://docs.opensearch.org/latest/vector-search/ai-search/hybrid-search/rrf/), [LanceDB API (2026)](https://lancedb.github.io/lancedb/python/python/), [Qdrant hybrid-query docs (2026)](https://qdrant.tech/documentation/search/hybrid-queries/), [Weaviate hybrid-search docs (2026)](https://docs.weaviate.io/weaviate/search/hybrid), [Azure AI Search ranking docs (2026)](https://learn.microsoft.com/en-us/azure/search/hybrid-search-ranking), and the [pgvector hybrid-search example (2026)](https://github.com/pgvector/pgvector-python/blob/master/examples/hybrid_search/rrf.py). Confirm rank indexing and candidate depth when porting: Qdrant’s documented positions start at zero, while the formula and Python example here use one-based positions.

## When should I skip RRF?

Skip it when one retriever already wins for the queries you care about, when input lists are nearly duplicates, or when useful score gaps disappear under rank-only fusion. Compare plain RRF, at least one weighted setting, and a score-normalization method against the best single retriever. Use a relevance metric that matches your result window, such as nDCG@10 for a top-10 answer context and Recall@100 when candidate coverage matters.

Start with 50–100 labeled queries and split the set before tuning: choose `k` and weights on one part, then report results on held-out queries. Include exact identifiers, paraphrases, and the ambiguous cases that cause production misses. Keep candidate depth, chunking, filters, and relevance judgments fixed across runs. If no fusion variant beats your best single retriever on held-out queries, ship the single retriever and preserve the fusion experiment for later.

RRF is a compact way to combine ranked lists, not evidence that both retrievers deserve equal influence. The practical choice is the one that beats your strongest single retriever on the queries your users actually ask. For a repeatable evaluation process, see the [LLM evaluation workflow](/blog/llm-evaluation-workflow); for how persistent search fits an agent’s memory, see [Octobrain and Octomind integration](/blog/octobrain-octomind-integration).
