Skip to main content
QUICK REVIEW

[Paper Review] BM25S: Orders of magnitude faster lexical search via eager sparse scoring

Xing Lü|arXiv (Cornell University)|Jul 4, 2024
Text and Document Classification TechnologiesComputer Science7 citations
TL;DR

BM25S is a Python-based BM25 implementation that uses eager sparse scoring and sparse matrices to achieve up to 500x speedups over common Python frameworks, enabling fast retrieval with minimal dependencies.

ABSTRACT

We introduce BM25S, an efficient Python-based implementation of BM25 that only depends on Numpy and Scipy. BM25S achieves up to a 500x speedup compared to the most popular Python-based framework by eagerly computing BM25 scores during indexing and storing them into sparse matrices. It also achieves considerable speedups compared to highly optimized Java-based implementations, which are used by popular commercial products. Finally, BM25S reproduces the exact implementation of five BM25 variants based on Kamphuis et al. (2020) by extending eager scoring to non-sparse variants using a novel score shifting method. The code can be found at https://github.com/xhluca/bm25s

Motivation & Objective

  • Motivate faster lexical search using BM25 in Python with minimal dependencies.
  • Propose an eager index-time scoring approach to precompute token scores.
  • Leverage sparse matrix representations to accelerate query-time scoring and top-k retrieval.
  • Present tokenizer and preprocessing choices that improve performance while maintaining accuracy.
  • Demonstrate scalability across multiple BM25 variants and benchmarks.

Proposed method

  • Reformulate BM25 scoring to allow eager computation of TF and IDF during indexing.
  • Store precomputed scores in a sparse V x C matrix and slice/sum to obtain document scores for a query.
  • Use a compressed sparse column (CSC) representation for efficient token-indexing and retrieval operations.
  • Implement a simple Python tokenizer and optional Snowball stemming to improve speed and accuracy.
  • Apply top-k retrieval via average-case O(n) partitioning (e.g., NumPy argpartition or JAX top-k).
  • Extend sparsity to non-occurrence adjustments and show compatibility with multiple BM25 variants.

Experimental results

Research questions

  • RQ1Can eager index-time scoring with sparse matrices yield substantial speedups over Python-based BM25 implementations?
  • RQ2How does BM25S perform relative to Lucene-based and other BM25 variants across standard benchmarks (BEIR)?
  • RQ3What tokenizer and preprocessing choices most affect BM25S performance and accuracy?
  • RQ4Can the approach be extended to multiple BM25 variants without sacrificing speed or accuracy?

Key findings

  • BM25S achieves up to 500x speedup compared to popular Python-based frameworks.
  • Across BEIR datasets, BM25S outperforms Rank-BM25 by over 100x throughput on 10 of 14 datasets and is fastest in many cases.
  • BM25S demonstrates substantial speedups even against optimized Java-based implementations used by commercial products.
  • Tokenization choices (stemming) improve average performance, while stopword handling has variable effects by dataset.
  • The approach enables exact replication of five BM25 variants with a general sparse-scoring framework.
  • Top-k retrieval is achieved in average O(n) time, with practical performance benefits from both NumPy and JAX implementations.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.