All projects
Personal project · 2026

RRF (Reciprocal Rank Fusion)

A Python library implementing various Reciprocal Rank Fusion strategies for RAG systems.

PythonRAGInformation RetrievalFusion Algorithms
Source on GitHubLast updated April 2026

What it solves

RAG systems often search two ways at once, by keywords and by meaning, and then merge the two ranked lists. Reciprocal Rank Fusion is the usual way to merge them: each result scores 1 / (k + rank), and the scores add up.

But retrievers return chunks, not documents. A long document can appear several times in one list, and if every chunk counts, it can beat a short document that both retrievers ranked first:

Keyword search
  1. 1Rotation guide
  2. 2Platform handbook · part 3
  3. 3Platform handbook · part 9
  4. 4other result
  5. 5Platform handbook · part 14
Semantic search
  1. 1Rotation guide
  2. 2other result
  3. 3other result
  • Rotation guide: short, on topic
  • Platform handbook: long, mentions keys in passing

Count every chunk

  1. 10.0474
  2. 20.0328

The handbook wins on volume.

Count each document once per list

  1. 10.0328
  2. 20.0161

The guide wins on relevance.

This library fuses at the document level and offers five strategies for handling those repeats.

Where it fits

Keyword search
BM25
Semantic search
embeddings
Fusion
this library
Reranker
cross-encoder or LLM
Generation
LLM answers

Fusion is cheap and needs no training, and it decides which candidates the more expensive reranker gets to see.

Try it

Two retrievers have answered the same question. Pick a strategy and watch the fused ranking change; hover a document to see where its chunks came from.

Every hit adds 1 / (k + rank), and repeats add up. At the default k, B wins on volume: four low-ranked keyword hits.

Lower k makes the top ranks count for more.

What each retriever returned

Query: How do I rotate API keys without downtime?

Keyword search (BM25)
  1. Glossary: API key
  2. Key rotation runbook
  3. REST API reference
  4. Zero-downtime deploys
  5. Credential lifecycle guide
  6. REST API reference
  7. REST API reference
  8. REST API reference
Semantic search (embeddings)
  1. Credential lifecycle guide
  2. Credential lifecycle guide
  3. Key rotation runbook
  4. Key rotation runbook
  5. Zero-downtime deploys
  6. Credential lifecycle guide
  7. REST API reference
  8. Security FAQ

Fused ranking

Top result: REST API reference

  1. 3
    Key rotation runbook0.0476
    3 chunks
  2. 1
    REST API reference0.0756
    5 chunks
  3. 5
    Glossary: API key0.0164
    1 chunk
  4. 6
    Security FAQ0.0147
    1 chunk
  5. 2
    Credential lifecycle guide0.0631
    4 chunks
  6. 4
    Zero-downtime deploys0.0310
    2 chunks

The five strategies

One document, found at ranks 1, 3 and 8 in the same list. How much each hit counts:

  • Diminishing returns

    Recommended

    Every hit counts, each less than the last.

    At the default α = 0.5, all the repeats together add less than the best hit alone, so depth helps but never outweighs it.

    λ · Σ α^j / (k + r_j)
    rank 1
    × 1
    rank 3
    × 0.5
    rank 8
    × 0.25
  • Standard RRF

    Every hit counts in full.

    Σ 1 / (k + r)
    rank 1
    × 1
    rank 3
    × 1
    rank 8
    × 1
  • Best rank

    One vote per list, at its best rank.

    Σ_lists 1 / (k + r_best)
    rank 1
    × 1
    rank 3
    not counted
    rank 8
    not counted
  • Max + bonus

    The best hit counts in full; the rest add a bonus.

    1 / (k + r_best) + λ · Σ_rest 1 / (k + r)
    rank 1
    × 1
    rank 3
    × 0.3
    rank 8
    × 0.3
  • Soft dedup

    Every hit counts, but repeats are pushed down their list first.

    r′ = r · (1 + β · j)
    rank 1
    × 1
    rank 3
    → 3.3 · × 0.995
    rank 8
    → 9.6 · × 0.98

Library defaults: k = 60, α = 0.5, λ = 0.3, β = 0.1. Diminishing returns also scales the total by λ.

🎵 My AI-generated music [AI in 2026] is playing. Toggle it on/off in the header.