RankFuse
Hybrid retrieval (dense + sparse + RRF fusion + optional reranking) for RAG pipelines.
Plug it in with two method calls — ingest() and search() — and your pipeline gets keyword-aware hybrid search with Reciprocal Rank Fusion on top of your existing dense embeddings.
Install
pip install rankfuse
Requires Python 3.10+. You'll need a Gemini API key for embeddings.
Quickstart
from rankfuse import Retriever, RetrieverConfig
config = RetrieverConfig(
embedder_provider="gemini",
api_key="your-gemini-api-key", # or set GEMINI_API_KEY env var
persist_dir="./my_index",
reranker_type="cross_encoder", # or "llm_judge", or "none"
)
retriever = Retriever(config)
retriever.ingest([
{"id": "doc1", "text": "Refunds are processed within 5-7 business days.", "metadata": {"source": "faq"}},
{"id": "doc2", "text": "To reset your password, go to Settings > Security.", "metadata": {"source": "faq"}},
{"id": "doc3", "text": "Check order status by logging into your dashboard.", "metadata": {"source": "faq"}},
])
results = retriever.search("what is the refund policy?", top_k=5)
for r in results:
print(r.doc_id, r.score, r.text[:80])
Run the full working example:
GEMINI_API_KEY=your-key python examples/quickstart.py
What it does
Standard RAG pipelines search with dense embeddings only. Dense embeddings are good at semantic similarity but miss exact keyword matches — a query for "RFC 7231" won't reliably surface a document that only contains the literal text "RFC 7231" unless the embedding space happens to capture it.
RankFuse adds a BM25 sparse index alongside the dense index, runs both in parallel, and merges the results using Reciprocal Rank Fusion (RRF). RRF works on rank position rather than raw scores, so it doesn't require normalization between the two score scales — it's simple and robust.
Optionally, a reranker (local cross-encoder or Gemini LLM-judge) does a precision pass over the fused top-N candidates before returning the final results.
Reranker options
reranker_type |
What it uses | Cost |
|---|---|---|
"cross_encoder" |
ms-marco-MiniLM-L-12-v2 (local, no API) |
Free, ~200MB model download on first use |
"llm_judge" |
Gemini (API call per candidate) | API quota cost |
"none" |
No reranking, returns RRF-fused results directly | Free |
Benchmark
Evaluated on 30 queries over the full FastAPI documentation corpus (154 documents). Hybrid search with stopword-filtered BM25 closes the candidate recall gap versus dense-only search — hybrid RRF-only matches dense-only at Recall@5 (0.90) while also providing exact-term coverage dense alone misses.
The standard equal-weight RRF configuration doesn't improve Recall@1 on this particular corpus — the release notes document causes keyword concentration that inflates BM25 scores for non-tutorial results. See benchmarks/results.md for the full methodology, diagnostic breakdown, and honest discussion of where hybrid search helps and where it doesn't.
Swap in your own embedder or store
from rankfuse.embeddings.base import Embedder
class MyEmbedder(Embedder):
def embed(self, texts: list[str]) -> list[list[float]]:
# your embedding logic here
...
retriever = Retriever(config, embedder=MyEmbedder())
See examples/custom_embedder.py for a full working example.
Docs
- Architecture — how the components connect
- API Reference — full config fields and method signatures
- Benchmark Results — methodology and findings
- FastAPI integration example
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rankfuse-0.1.0.tar.gz.
File metadata
- Download URL: rankfuse-0.1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4c3f0bb1954bb69ca5d7d4900872e1b231909846716b955f4252657a12a3745
|
|
| MD5 |
8c23560a260d3ea830c5c57be5cbb7d3
|
|
| BLAKE2b-256 |
14e5b0434010312b72850d0d29ef8df8cb20a6d0c9849d0544df49b51242db28
|
Provenance
The following attestation bundles were made for rankfuse-0.1.0.tar.gz:
Publisher:
publish.yml on GauravFrr/RankFuse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rankfuse-0.1.0.tar.gz -
Subject digest:
a4c3f0bb1954bb69ca5d7d4900872e1b231909846716b955f4252657a12a3745 - Sigstore transparency entry: 2530755725
- Sigstore integration time:
-
Permalink:
GauravFrr/RankFuse@5d6eba1b28fbad019aade9564d1bc3da78bb6854 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/GauravFrr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5d6eba1b28fbad019aade9564d1bc3da78bb6854 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rankfuse-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rankfuse-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17bb00ee485eba8e6f3c64573d87fe7e6c76535f72f993cf591b91f8c97f09f8
|
|
| MD5 |
dff7694ad552485e6de60da4ecee94e0
|
|
| BLAKE2b-256 |
c3280a62022fac49774f293e9ba0f85d09876102b36b66c023f1503465a5676e
|
Provenance
The following attestation bundles were made for rankfuse-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on GauravFrr/RankFuse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rankfuse-0.1.0-py3-none-any.whl -
Subject digest:
17bb00ee485eba8e6f3c64573d87fe7e6c76535f72f993cf591b91f8c97f09f8 - Sigstore transparency entry: 2530755820
- Sigstore integration time:
-
Permalink:
GauravFrr/RankFuse@5d6eba1b28fbad019aade9564d1bc3da78bb6854 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/GauravFrr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5d6eba1b28fbad019aade9564d1bc3da78bb6854 -
Trigger Event:
release
-
Statement type: