Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

BM25

A fast, simple, and high-level Python API and CLI for BM25, powered by bm25s.

💻 GitHub 📦 bm25s 🏠 Homepage

BM25 is a wrapper package that installs bm25s with its optional core dependencies, providing a simple, high-level API and a command-line interface for fast and effective text retrieval.

Installation

Install BM25 using pip:

pip install BM25

This will automatically install the highly optimized bm25s backend, alongside necessary dependencies for stemming (PyStemmer), parallelization, and CLI (rich).

High Level API

If you want to quickly search on a local file, you can use the BM25 module:

import BM25

# Load a file (csv, json, jsonl, txt)
# For csv/jsonl, you can specify the column/key to use as document text
corpus = BM25.load("tests/data/dummy.csv", document_column="text")
# Index the corpus
retriever = BM25.index(corpus)

# Search
results = retriever.search(["your query here"], k=5)
for result in results[0]:
    print(result)

The load function handles file reading, while index handles tokenization, indexing, and provides a simple search interface.

Command-Line Interface

The package provides a terminal-based CLI for quick indexing and searching without writing Python code.

Indexing Documents

Create an index from a CSV, TXT, JSON, or JSONL file:

# Index a CSV file (uses first column by default)
bm25 index documents.csv -o my_index

# Index with a specific column
bm25 index documents.csv -o my_index -c text

# Index a text file (one document per line)
bm25 index documents.txt -o my_index

# Index a JSONL file
bm25 index documents.jsonl -o my_index -c content

If you don't specify an output directory with -o, the index will be saved to <filename>_index.

User Directory

You can save indices to a central user directory (~/.bm25s/indices/) using the -u flag:

# Save index to ~/.bm25s/indices/my_docs
bm25 index documents.csv -u -o my_docs

# Search using the user directory
bm25 search -u -i my_docs "your query"

Searching

Search an existing index with a query using -i (or --index):

# Basic search (returns top 10 results)
bm25 search -i my_index "what is machine learning?"

# Search with full path
bm25 search -i ./path/to/my_index "your query here"

# Return more results
bm25 search -i my_index "your query here" -k 20

# Save results to a JSON file
bm25 search -i my_index "your query here" -s results.json

Interactive Index Picker

When using -u without specifying an index name, an interactive picker is displayed (requires bm25s[cli] which is installed by default with BM25):

# Interactive picker will show available indices
bm25 search -u "your query"

Example Workflow

Basic usage (index saved to current directory):

# 1. Create a simple text file with documents
echo -e "Machine learning is a subset of AI\nDeep learning uses neural networks\nNatural language processing handles text" > docs.txt

# 2. Index the documents
bm25 index docs.txt -o my_index

# 3. Search the index
bm25 search -i my_index "what is AI?"

With user directory (indices saved to ~/.bm25s/indices/):

# Index to user directory
bm25 index docs.txt -u -o ml_docs

# Search from user directory
bm25 search -u -i ml_docs "what is AI?"

# Or use the interactive picker
bm25 search -u "what is AI?"

Flexibility

For more advanced use cases, including memory mapping, customized tokenization, hugging face integration, or using different BM25 variants, please use the underlying bm25s API directly.

See the bm25s documentation for full details.

Metadata

Release files for BM25 0.3.0rc5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BM25 0.3.0rc5
File Size Uploaded Provenance Actions
bm25-0.3.0rc5.tar.gz 6.0 kB With provenance Details for bm25-0.3.0rc5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for BM25 0.3.0rc5
File Interpreter ABI Platform Actions
bm25-0.3.0rc5-py3-none-any.whl Python 3 none any Details for bm25-0.3.0rc5-py3-none-any.whl

Total release size: 12.0 kB

Release files / bm25-0.3.0rc5.tar.gz

Download URL bm25-0.3.0rc5.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b818b5ab0ea8e70bea3af37adedf08323638edfb8d33a6d03e5fa0b0ff176ec7
BLAKE2b-256 checksum
How to use checksums
49e6d35f21d58f4b752a5c1079e9a445c301f0b69d3b0ed03a01d1adda22c950
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 6, 2026.

Transparency log

Release files / bm25-0.3.0rc5-py3-none-any.whl

Download URL bm25-0.3.0rc5-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e9787c91a168421d918b0884ef489380b4ac685ede6b263ba0480dcb2cd5359
BLAKE2b-256 checksum
How to use checksums
8ee95700a58f037ae5d26bd17768e7506ae03cb568eb2520ffe1eceb7fbf1230
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 6, 2026.

Transparency log

Security for BM25 0.3.0rc5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bm25-0.3.0rc5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page