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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_whoosh-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

langchain_whoosh-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_whoosh-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_whoosh-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for langchain_whoosh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eea44e480002914f9dd08632b5c7133e23e89fd5e12a71a539547c526f4585b0
MD5 a5708fe7f1ef8ecb43b330f4dc48d9a0
BLAKE2b-256 a10e323bb909873cf69b231e66f6af6e99e2658e552e97a3cf90e1df478e442c

See more details on using hashes here.

File details

Details for the file langchain_whoosh-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_whoosh-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6c72cd6ea936235e747ca48a194ca5e7226286df946b20127928ae41caa5bb7
MD5 f131af6b9cf3b4886929e6ff17147e13
BLAKE2b-256 6f0837d5f97eb114d7258823cfc25ee84365fb6a6a480969612178c8c0cf7511

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 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