rank-bm25
Various BM25 algorithms for document ranking
What it is and what it does
Rank-BM25 provides implementations of the BM25 family of ranking algorithms—Okapi BM25, BM25L, and BM25+—for scoring how relevant documents are to a search query. It takes a corpus of pre-tokenized documents, builds an index, and then scores or ranks documents against tokenized queries using probabilistic relevance models. The package is intentionally minimal: it does not handle text preprocessing like lowercasing, stemming, or stopword removal, leaving those decisions to the caller.
The typical workflow is to tokenize your document corpus and query using your chosen preprocessing pipeline, initialize a BM25 class with the tokenized corpus, then call get_scores() to retrieve relevance scores or get_top_n() to retrieve the highest-ranking documents. It's commonly used to build search engines or to rank candidate documents in information retrieval pipelines.
Use it for:
- Build a lightweight full-text search engine for a document collection without external infrastructure.
- Rank candidate documents in a retrieval-augmented generation (RAG) pipeline before passing to a language model.
- Score document relevance in a question-answering system to find the most relevant passages.
- Implement search functionality in a web application where you control the preprocessing and indexing.
- Benchmark BM25 variants against each other on your own corpus to evaluate ranking quality.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements BM25 ranking algorithms (Okapi BM25, BM25L, BM25+) to score and rank documents by relevance to a query.
Yes. Low install friction, no security vulnerabilities, permissive license, active maintenance, and a focused, well-documented implementation of a standard algorithm. Install if you need BM25 ranking and want to control preprocessing yourself; skip if you need a full-featured search engine with built-in text processing.
Install
rank-bm25 on PyPI
pip
pip install rank-bm25uv
uv add rank-bm25poetry
poetry add rank-bm25Installing rank-bm25
Before you install
Low friction install with a single runtime dependency (numpy). Repository is active with recent commits and steady maintenance since 2019.
License in practice
Apache2.0 permissive license allows commercial and private use with minimal restrictions.
Quickstart
pip install rank-bm25
from rank_bm25 import BM25Okapi
corpus = ["Hello there good man!", "It is quite windy in London"]
tokenized_corpus = [doc.split(" ") for doc in corpus]
bm25 = BM25Okapi(tokenized_corpus)
query = "windy London"
tokenized_query = query.split(" ")
scores = bm25.get_scores(tokenized_query)
Package expects pre-tokenized input (list of token lists); you must handle text preprocessing (lowercasing, stopword removal, stemming) yourself before passing to BM25.
Verify before relying
- Whether BM25-Adpt and BM25T algorithms mentioned as unimplemented are planned for future releases.
- Current test coverage and benchmarking against other ranking libraries.
- Performance characteristics on large corpora (memory usage, query latency).
Package facts
| License | Apache2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — numpy |
| Maintenance | actively maintained — 1,640 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 8,915,190/month — #1,578 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: rank_bm25-0.2.2-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
bm25sBM25S implements the BM25 ranking algorithm in…
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
voyageaiProvides Python access to Voyage AI's embedding…
permissive · top 5,000 on PyPI
rouge-scoreComputes ROUGE scores (ROUGE-N, ROUGE-L,…
permissive · top 5,000 on PyPI
colbert-aiColBERT is a BERT-based retrieval model that…
unclear · top 15,000 on PyPI
lunrLunr is a lightweight, in-memory full-text…
permissive · top 15,000 on PyPI
ir-measuresProvides a unified Python interface to compute…
permissive · top 15,000 on PyPI
implicitImplicit provides fast Python implementations…
permissive · top 15,000 on PyPI
mrmr-selectionImplements the mRMR (minimum Redundancy -…
unclear · top 15,000 on PyPI