Skip to main content

langchain-whoosh

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

LangChain pipelines usually reach for a vector store, 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 langchain-whoosh

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

Quick start

from langchain_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,
)

docs = retriever.invoke("pure python search")
for d in docs:
    print(d.metadata["score"], d.page_content)

Each result is a standard langchain_core.documents.Document; the original id, the BM25 score, and any metadata you supplied are attached under Document.metadata.

Persist an index to disk

# Build once …
WhooshRetriever.from_texts(texts=texts, ids=ids, path="./my_index")

# … reopen later without re-indexing.
retriever = WhooshRetriever.from_index("./my_index", k=8)

Hybrid search (lexical + vector)

Drop this retriever and your vector retriever into LangChain's EnsembleRetriever; it does Reciprocal Rank Fusion for you:

from langchain.retrievers import EnsembleRetriever

hybrid = EnsembleRetriever(
    retrievers=[whoosh_retriever, vector_retriever],
    weights=[0.5, 0.5],
)

License

BSD-2-Clause, matching Whoosh. See the Whoosh repository for the full project, docs, and issue tracker.

Metadata

Release files for langchain-whoosh 0.1.1

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

Source distribution (sdist)

Source distribution for langchain-whoosh 0.1.1
File Size Uploaded Provenance Actions
langchain_whoosh-0.1.1.tar.gz 4.2 kB Without provenance Details for langchain_whoosh-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-whoosh 0.1.1
File Interpreter ABI Platform Actions
langchain_whoosh-0.1.1-py3-none-any.whl Python 3 none any Details for langchain_whoosh-0.1.1-py3-none-any.whl

Total release size: 8.4 kB

Release files / langchain_whoosh-0.1.1.tar.gz

Download URL langchain_whoosh-0.1.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
37cf8f4b5d13614df2ad757e5e3eeb1015233661c4645f2f3e77de7d283a6ef6
BLAKE2b-256 checksum
How to use checksums
94116565050527971d7ec02c16425922fcf92265431d0770b7903cde8ace6fd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / langchain_whoosh-0.1.1-py3-none-any.whl

Download URL langchain_whoosh-0.1.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e157db13199d48e97a8e403bf02b5e53bd6d0d3bd76527204b9c572f1800ae3
BLAKE2b-256 checksum
How to use checksums
23262e8917620144462911fc73e93d8dc5f2c42be140a10327f440ec77ed6677
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for langchain-whoosh 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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