Source: Lù 2024: BM25S
Technical report and library for a pure-Python BM25 that precomputes scores into sparse matrices at index time, claiming up to 500x speedups over popular Python BM25.
Contents
- What: technical report (arXiv:2407.03618) plus the MIT-licensed
bm25slibrary - Author: Xing Han Lù
- Date: 2024-07-04 (README read 2026-11-14)
- Original: arXiv:2407.03618 · GitHub: xhluca/bm25s
Summary
BM25S does “eager” scoring: since a BM25 term score depends only on the term and the document, it computes every non-zero (term, document) score at indexing time and stores them in a sparse matrix. A query then reduces to summing a few rows. It depends only on NumPy and SciPy, with optional Numba and JAX backends.
Key claims
- Up to a 500x speedup over the most popular Python BM25 framework, and large speedups over Java-based engines used in commercial products (paper abstract).
- Reproduces five BM25 variants from Kamphuis et al. 2020: Robertson, ATIRE, BM25L, BM25+ and Lucene; non-sparse variants (BM25L, BM25+) handled with a score-shifting method. The default method is
lucene. - README single-threaded queries per second (bm25s vs Elasticsearch vs rank-bm25): SciFact 952.92 / 20.81 / 47.6; NQ 41.85 / 12.16 / 0.1; MS MARCO 12.2 / 11.88 / 0.07. The margin over Elasticsearch narrows on the largest corpus.
mmap=Trueloading on NQ (2M+ docs) cut post-index RAM from 4.36 GB to 0.49 GB at similar retrieval time.- Ships a tokenizer with stopwords and optional PyStemmer stemming, and Hugging Face Hub save/load (
BM25HF).