Skip to main content

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

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

rankfuse-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rankfuse-0.1.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

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

Hashes for rankfuse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a4c3f0bb1954bb69ca5d7d4900872e1b231909846716b955f4252657a12a3745
MD5 8c23560a260d3ea830c5c57be5cbb7d3
BLAKE2b-256 14e5b0434010312b72850d0d29ef8df8cb20a6d0c9849d0544df49b51242db28

See more details on using hashes here.

Provenance

The following attestation bundles were made for rankfuse-0.1.0.tar.gz:

Publisher: publish.yml on GauravFrr/RankFuse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for rankfuse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17bb00ee485eba8e6f3c64573d87fe7e6c76535f72f993cf591b91f8c97f09f8
MD5 dff7694ad552485e6de60da4ecee94e0
BLAKE2b-256 c3280a62022fac49774f293e9ba0f85d09876102b36b66c023f1503465a5676e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rankfuse-0.1.0-py3-none-any.whl:

Publisher: publish.yml on GauravFrr/RankFuse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page