skillfed

bm25s

An ultra-fast implementation of BM25 based on sparse matrices.

bm25s v0.3.10 1.9M downloads/30d#3,428 on PyPI1,763
Permissive license Active released

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 bm25s

uv

uv add bm25s

poetry

poetry add bm25s

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

BM25 ranking implementationdocument retrieval and scoringtext search rankingsparse matrix searchlexical search libraryinformation retrievalquery-based document ranking
information-retrievalsearch-rankingsparse-matrices

More Text Processing packages