bm25s
An ultra-fast implementation of BM25 based on sparse matrices.
What it is and what it does
BM25S is a pure-Python implementation of the BM25 ranking algorithm, a widely-used text retrieval function that scores how relevant documents are to a query. It uses sparse matrices to precompute and store token scores, enabling very fast retrieval at query time. The package is designed for simplicity—it requires only Numpy and can be installed and used within minutes, with no Java or PyTorch dependencies.
You tokenize a corpus of documents, index them with the BM25 model, then query against the index to retrieve ranked results. The library supports optional stemming via PyStemmer and optional JIT compilation via Numba for additional speedup on larger datasets. It also provides a command-line interface for indexing and searching without writing Python code, and a high-level API for quick file-based indexing.
Use it for:
- Build a search engine over a local document collection (CSV, JSON, JSONL, or text files) without external infrastructure
- Rank documents by relevance to user queries in a Python application or web service
- Prototype information retrieval systems before scaling to Elasticsearch or similar production systems
- Index and search large corpora (millions of documents) with fast query-time performance
- Combine BM25 ranking with other retrieval methods in a hybrid search pipeline
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
BM25S implements the BM25 ranking algorithm in pure Python with Numpy, enabling fast document retrieval and ranking based on text queries.
Yes. BM25S is actively maintained, has no security vulnerabilities, installs with minimal friction, and is licensed permissively. It solves a real problem—fast lexical search—with a simple, dependency-light design. Install it if you need to rank documents by text relevance in Python without external services.
Install
bm25s on PyPI
pip
pip install bm25suv
uv add bm25spoetry
poetry add bm25sInstalling bm25s
Before you install
Installation is straightforward with low friction—the package is a pure Python wheel with only Numpy as a required dependency. The project is actively maintained with a recent release and steady commit activity.
License in practice
Licensed under MIT (permissive), so you can use, modify, and distribute the package freely in commercial and private projects without restriction.
Quickstart
pip install bm25s
import bm25s
corpus = ["a cat is a feline", "a dog is friendly"]
corpus_tokens = bm25s.tokenize(corpus, stopwords="en")
retriever = bm25s.BM25()
retriever.index(corpus_tokens)
query_tokens = bm25s.tokenize("cat")
results, scores = retriever.retrieve(query_tokens, k=2)
Verify before relying
- Whether optional dependencies (PyStemmer, numba) are truly optional or recommended for typical use cases
- Performance comparison claims against Elasticsearch and rank-bm25 (benchmarks cited but not included in fact sheet)
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — numpy |
| Maintenance | actively maintained — 23 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,923,766/month — #3,428 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: bm25s-0.3.10-py3-none-any.whl
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
rank-bm25Implements BM25 ranking algorithms (Okapi BM25,…
permissive · top 5,000 on PyPI
sqlite-fts4Registers custom SQLite functions for ranking…
permissive · top 5,000 on PyPI
llama-index-retrievers-bm25Integrates BM25 full-text search retrieval into…
permissive · top 15,000 on PyPI
pinecone-textProvides sparse and dense text encoders for…
unclear · top 15,000 on PyPI
colbert-aiColBERT is a BERT-based retrieval model that…
unclear · top 15,000 on PyPI
WhooshWhoosh is a pure-Python full-text search and…
permissive · top 5,000 on PyPI
milvus-liteMilvus Lite is a pure-Python local vector…
permissive · top 5,000 on PyPI
langchain-graph-retrieverRetrieves documents from a graph structure…
permissive · top 15,000 on PyPI
graph-retrieverCombines vector similarity search with graph…
permissive · top 15,000 on PyPI
py-rust-stemmersProvides fast, parallel word stemming using…
unclear · top 5,000 on PyPI