Practical overview
When it fits
Use Bm25S when a Python application needs lexical BM25 ranking over its own document collection, or when an agent needs retrieval access to an existing BM25 index through MCP.
Who it is for
- Python developers adding keyword-based document retrieval to an application.
- RAG builders who need a lexical ranking stage for a document collection.
- Developers who want to expose BM25 retrieval to LLMs or agents through MCP.
Documented uses
- Index document text and return the top-ranked documents for a query.
- Keep corpus values such as document dictionaries associated with retrieved IDs.
- Save and reload a BM25 index for reuse.
- Expose retrieval and index information as MCP tools.
Requirements & limits
The project is publicly available on GitHub and lists an MIT license. The README documents pip installation; the MCP server requires the `mcp` extra.
- The library ranks by BM25 lexical matching, so it is suited to term-based retrieval rather than serving as a complete search or RAG application.
- NumPy is the core documented dependency; Numba, stemming, JSON loading, and progress-bar support are available through optional extras.
- The MCP integration is a separate setup path that requires the
mcpextra and an index directory. - The README documents string and dictionary corpus entries and lets developers select text fields for indexing.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Build and query a local BM25 index
Tokenize a document collection, retrieve its top-ranked matches for a query, and save the index.
Before you start
- Python environment with NumPy and bm25s installed; the README gives
pip install bm25sas the installation command. - A collection of document strings, or dictionaries with the text fields selected for indexing.
Steps
Pass the corpus text to
bm25s.tokenize().Create a
bm25s.BM25()retriever and callindex()with the tokenized corpus.Tokenize a query and call
retrieve()with a top-k value to get document IDs and scores; associate original corpus values by supplying the corpus.Call
save()to store the index, optionally with the corpus.
Expected outcome
A BM25 index that returns ranked document matches and scores, and can be saved for later loading.
Guide limitations
- Stemming is optional and requires a stemmer dependency such as PyStemmer.
- The guide covers library-level indexing and retrieval, not a complete search application.
Expose an existing index through MCP
Launch the documented MCP server against a BM25 index so an LLM or agent can request retrieval.
Before you start
- A Python environment and an existing bm25s index directory.
- Bm25S installed with the
mcpextra; the README recommends managing the environment with uv.
Steps
Create and activate a virtual environment as shown in the README.
Install
bm25s[mcp]in that environment.Launch
bm25 mcp launchwith a port and the index directory.Use the exposed
retrievetool for top-k query results orget_infofor index details.
Expected outcome
An MCP server exposing retrieval and index-information tools for the loaded collection.
Guide limitations
- This setup requires an index directory; the guide does not cover building one.
- The README's launch example uses a local environment and a specified port.
Compare options for Retrieval-augmented applications
These projects document a common task and share a project role. This is a source-based comparison, not an execution benchmark or a guarantee of interchangeability.
| Project | Documented purpose | Platform | Access and requirements |
|---|---|---|---|
| Bm25S | Index document text and return the top-ranked documents for a query. | Linux, macOS, Windows | The project is publicly available on GitHub and lists an MIT license. The README documents pip installation; the MCP server requires the `mcp` extra. |
| Langsearch | Crawl website or local data for a knowledge base. | CLI, Self-hosted, Server | |
| Hybrid Search Rag | Combine document retrieval and language-model generation in a configurable workflow. |
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 8 October 2026
- Original website title
- xhluca/bm25s · Official homepage title · retained in its source language

