How dorianbrown/rank_bm25 works
Rank-BM25 is a small in-process Python retrieval library. A caller supplies tokenized documents (or a tokenizer), the BM25 base class builds corpus statistics and delegates inverse-document-frequency calculation to a selected variant; queries are scored across the corpus or a document subset, and top-N results map scores back to caller-provided documents. The README also documents Okapi, BM25L and BM25+; preprocessing remains caller-owned. The single implementation file was excerpted, so no separate runtime modules or external services are represented.
Main entry points: rank_bm25.py BM25 base
Components 11
Corpus indexing
- BM25 base
rank_bm25.py - Corpus tokenizer
rank_bm25.py - Corpus statistics
rank_bm25.py
BM25 ranking
- BM25Okapi
rank_bm25.py - BM25L
rank_bm25.py - BM25Plus
rank_bm25.py - Document scores
rank_bm25.py - Top documents
rank_bm25.py
Other components
- Library caller
- Tokenized corpus
- Tokenized query
Connections 19
- Library caller → Tokenized corpus: provides
README.md - Library caller → Tokenized query: provides
README.md - Tokenized corpus → BM25 base: initializes
rank_bm25.py - BM25 base → Corpus tokenizer: tokenizes via
rank_bm25.py - BM25 base → Corpus statistics: builds
rank_bm25.py - BM25 base → BM25Okapi: delegates IDF
rank_bm25.py - BM25 base → BM25L: delegates IDF
rank_bm25.py - BM25 base → BM25Plus: delegates IDF
rank_bm25.py - Tokenized query → BM25Okapi: scores with
README.md - Tokenized query → BM25L: scores with
README.md - Tokenized query → BM25Plus: scores with
README.md - BM25Okapi → Document scores: returns
rank_bm25.py - BM25L → Document scores: returns
rank_bm25.py - BM25Plus → Document scores: returns
rank_bm25.py - BM25Okapi → Corpus statistics: reads
rank_bm25.py - BM25L → Corpus statistics: reads
rank_bm25.py - BM25Plus → Corpus statistics: reads
rank_bm25.py - Document scores → Top documents: selects top
rank_bm25.py - Library caller → Top documents: receives
README.md