Skip to main content

llama-index-retrievers-whoosh

A pure-Python BM25 (lexical) retriever for LlamaIndex, powered by Whoosh.

LlamaIndex pipelines usually reach for a vector index, but dense retrieval has a well-known blind spot: it can quietly miss the exact tokens that matter most — product SKUs, function names, error codes like ERR_2043, gene symbols, ticket IDs. A lexical BM25 retriever is the classic complement, and Whoosh gives you one in pure Python: no server, no native wheels, and an index that is just a folder on disk.

Install

pip install llama-index-retrievers-whoosh

This pulls in llama-index-core and whoosh3 (the maintained Whoosh fork).

Quick start

from llama_index.retrievers.whoosh import WhooshRetriever

retriever = WhooshRetriever.from_texts(
    texts=[
        "Whoosh is a pure-Python full-text search library.",
        "BM25 ranks documents by term rarity and frequency.",
    ],
    ids=["a", "b"],
    metadatas=[{"src": "readme"}, {"src": "docs"}],
    k=4,
)

nodes = retriever.retrieve("pure python search")
for n in nodes:
    print(n.score, n.node.metadata["id"], n.node.text)

Every result is a standard LlamaIndex NodeWithScore, so it drops straight into any query engine or router.

Persist to disk

Pass a path to build an on-disk index once, then reopen it later:

WhooshRetriever.from_texts(texts=texts, ids=ids, path="./whoosh_index")
retriever = WhooshRetriever.from_index("./whoosh_index", k=8)

The index is just a directory — copy it, commit it, ship it in a container.

Combine this retriever with any vector retriever using LlamaIndex's QueryFusionRetriever, which does Reciprocal Rank Fusion for you:

from llama_index.core.retrievers import QueryFusionRetriever

fusion = QueryFusionRetriever(
    [whoosh_retriever, vector_retriever],
    similarity_top_k=8,
    num_queries=1,          # set >1 to also fuse query rewrites
    mode="reciprocal_rerank",
)
nodes = fusion.retrieve("ERR_2043 timeout after upgrade")

Lexical retrieval catches the exact ERR_2043 token; the vector retriever catches the paraphrases. Fusing them is consistently stronger than either alone.

Why Whoosh?

  • Pure Python — no Java, no C extensions, no server to run.
  • BM25F ranking out of the box.
  • The index is a folder — trivial to build in CI, cache, or ship.

License

BSD-2-Clause, matching Whoosh. See the Whoosh repository for the underlying library and its history.

Metadata

Release files for llama-index-retrievers-whoosh 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-retrievers-whoosh 0.1.0
File Size Uploaded
llama_index_retrievers_whoosh-0.1.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-retrievers-whoosh 0.1.0
File Interpreter ABI Platform
llama_index_retrievers_whoosh-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / llama_index_retrievers_whoosh-0.1.0.tar.gz

Download URL llama_index_retrievers_whoosh-0.1.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
11a47b915b23ba32a39281f92df329e8a8e77e5f46c92a68e3359151288f041f
BLAKE2b-256 checksum
How to use checksums
2784e98537eacaa408fa14254c95b59d4821e5626df024f59e329bb1585af7a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / llama_index_retrievers_whoosh-0.1.0-py3-none-any.whl

Download URL llama_index_retrievers_whoosh-0.1.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
602100c18fab9c8c9fccf8bbd15d82b1e94221da8780012155d1fc3eb7ddda8c
BLAKE2b-256 checksum
How to use checksums
f15a284aaf103ca78e97f9eb94b6a259298e76bce5d4426703f274da4c87db79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page