BM25, or Best Match 25, is a ranking function that scores a document's relevance to a query based on the frequency of matching terms, but with two critical controls: term saturation and document length normalization. Term saturation prevents a single keyword from dominating the score simply by being repeated excessively, while length normalization corrects the bias that longer documents naturally have a higher chance of containing a query term, ensuring a fair comparison between a short abstract and a lengthy manual.
Glossary
BM25

What is BM25?
BM25 is a probabilistic, bag-of-words retrieval function that ranks documents by estimating the relevance of term frequencies while accounting for document length normalization and term saturation, serving as the standard baseline for sparse lexical search.
As the foundational algorithm for sparse retrieval, BM25 relies on an inverted index for computationally efficient, exact keyword matching, making it highly interpretable and effective for queries where precise terminology is critical. In modern hybrid retrieval strategies, BM25's lexical precision is combined with the semantic understanding of dense vector search—a pairing often merged using algorithms like Reciprocal Rank Fusion (RRF)—to maximize both recall and precision in systems like Retrieval-Augmented Generation (RAG).
Core Characteristics of BM25
BM25 is a bag-of-words retrieval function that ranks documents by estimating the relevance of term frequencies while accounting for document length normalization and term saturation, serving as the standard baseline for sparse lexical search.
Term Frequency Saturation
Unlike linear TF-IDF weighting, BM25 applies a non-linear saturation curve to term frequency. The formula tf / (tf + k1) ensures that the fifth occurrence of a term contributes far less than the first. This prevents keyword stuffing from artificially inflating relevance scores.
- k1 parameter (typically 1.2–2.0): Controls the slope of the saturation curve
- A higher k1 means term frequency has a more linear, prolonged impact
- A lower k1 means rapid saturation after the first few occurrences
- This reflects the empirical observation that relevance does not increase linearly with term repetition
Document Length Normalization
BM25 compensates for the fact that longer documents naturally contain more words and higher term frequencies by applying a length normalization factor. The parameter b (typically 0.75) controls the strength of this correction.
- b = 1: Full normalization—document length is fully accounted for
- b = 0: No normalization—long documents have an unfair advantage
- The normalization uses the ratio of document length to average corpus length
- This ensures a short, highly relevant document can outrank a long, marginally relevant one
Inverse Document Frequency Component
BM25 incorporates an IDF-like term specificity weight that penalizes common words and rewards rare, discriminative terms. The standard formulation uses log((N - df + 0.5) / (df + 0.5)) where N is the total document count and df is the number of documents containing the term.
- Rare terms that appear in few documents receive high IDF weights
- Common stopwords that appear in most documents approach zero weight
- This component is computed once per term across the entire corpus
- Unlike TF-IDF, BM25's IDF is derived from a probabilistic relevance framework
Probabilistic Relevance Framework
BM25 is grounded in the Probability Ranking Principle, which states that documents should be ranked by their probability of relevance given the query. It is derived from the Binary Independence Model using a 2-Poisson approximation for term distributions.
- The scoring function estimates
P(relevant | document, query) - Term independence is assumed (bag-of-words model)
- The formula balances term frequency evidence against document length
- This probabilistic foundation provides theoretical justification for the heuristic components
BM25F: Multi-Field Extension
BM25F extends the base algorithm to handle structured documents with multiple fields (title, body, anchor text) by computing a weighted, length-normalized term frequency across all fields before applying the standard BM25 formula.
- Each field receives its own boost weight and length normalization parameter
- Title matches can be weighted more heavily than body matches
- The combined pseudo-term-frequency is fed into the standard BM25 equation
- This is the foundation for search in systems like Elasticsearch and Apache Lucene
BM25L: Long Document Correction
BM25L addresses a known deficiency where BM25 unfairly penalizes very long documents that contain relevant information distributed across many sections. It modifies the term frequency component to prevent the score from asymptotically approaching zero for long documents.
- Introduces an additional parameter
δto adjust the saturation curve - Prevents excessively long documents from being systematically demoted
- Particularly useful for book-length documents or technical manuals
- Maintains the core probabilistic framework while fixing edge-case behavior
Frequently Asked Questions
Clear, technical answers to the most common questions about the BM25 algorithm, its role in modern hybrid search, and how it compares to dense vector retrieval.
BM25 is a probabilistic, bag-of-words retrieval function that ranks documents by estimating the relevance of term frequencies while accounting for document length normalization and term saturation. It operates on a sparse inverted index, meaning it only considers exact token matches between the query and documents.
At its core, BM25 calculates a score for each matching term and sums them. The formula has three critical components:
- Term Frequency (TF) Saturation: Unlike simple TF, BM25 applies a non-linear saturation function (
tf / (k1 + tf)). The parameterk1(typically 1.2–2.0) controls how quickly additional occurrences stop adding value. A word appearing 100 times isn't 100x more relevant than one appearing 10 times. - Inverse Document Frequency (IDF): This dampens common words. A term that appears in nearly every document gets a weight near zero, while a rare term gets a high weight. The standard formula is
log((N - df + 0.5) / (df + 0.5)). - Document Length Normalization: The
bparameter (typically 0.75) controls how much document length matters. Abof 1.0 fully normalizes by length; abof 0 ignores length entirely. This prevents longer documents from having an unfair advantage simply because they contain more words.
The final score for a document D given a query Q is the sum over each query term t: IDF(t) * (tf(t, D) * (k1 + 1)) / (tf(t, D) + k1 * (1 - b + b * |D|/avgdl)).
BM25 vs. Dense Retrieval vs. Learned Sparse Retrieval
A technical comparison of three core retrieval paradigms for modern answer engines, contrasting their indexing mechanisms, matching logic, and operational trade-offs.
| Feature | BM25 | Dense Retrieval | Learned Sparse Retrieval |
|---|---|---|---|
Core Mechanism | Probabilistic term frequency with TF saturation and document length normalization | Bi-encoder neural network encoding text into dense vectors for cosine similarity search | Neural model predicting term importance weights for vocabulary tokens, generating sparse vectors |
Index Type | Inverted index with term-level postings lists | Vector index using ANN algorithms like HNSW or IVF-PQ | Inverted index with learned term weights instead of raw TF |
Matching Paradigm | Exact lexical token matching | Semantic similarity in latent embedding space | Learned lexical matching with contextual term weighting |
Out-of-Vocabulary Handling | |||
Zero-Shot Domain Transfer | |||
Exact Term Matching Precision | |||
Query Latency (Relative) | < 10 ms | 10-50 ms | < 15 ms |
Index Size (Relative to Raw Text) | 10-30% | 200-500% | 15-40% |
Training Data Required | Large-scale query-document pairs or contrastive data | Training corpus for term importance prediction | |
Explainability | High — scores directly attributable to term frequencies | Low — scores are opaque latent space distances | Medium — weights are vocabulary-grounded but learned |
Synonym and Paraphrase Handling | |||
Document Length Sensitivity | Normalized via pivot length parameter | Minimal — fixed-size vector output | Minimal — learned term weighting adapts |
Typical Recall@1000 on BEIR | ~0.85 | ~0.95 | ~0.92 |
Typical MRR@10 on BEIR | ~0.30 | ~0.42 | ~0.38 |
Fusion Compatibility | Requires score normalization for RRF or weighted sum | Native cosine similarity scores; easily fused | Scores are sparse but require normalization for fusion |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
BM25 serves as the standard sparse lexical baseline in modern retrieval pipelines. The following concepts define the ecosystem of algorithms and techniques that interact with, extend, or contrast with BM25 in hybrid search architectures.
TF-IDF
The foundational predecessor to BM25. TF-IDF weights terms by their term frequency in a document multiplied by their inverse document frequency across the corpus. Unlike BM25, TF-IDF lacks term saturation and document length normalization, making it less effective at handling long documents and common terms. BM25's non-linear term frequency component—where additional occurrences yield diminishing returns—directly addresses TF-IDF's tendency to over-weight repetitive terms.
Dense Passage Retrieval (DPR)
A bi-encoder architecture that encodes queries and documents into dense vector representations for semantic similarity search. DPR represents the opposite end of the retrieval spectrum from BM25: while BM25 excels at exact lexical matching and rare term identification, DPR captures paraphrastic equivalence and conceptual similarity. In production, these two systems are typically combined via hybrid retrieval to maximize both precision and recall.
Learned Sparse Retrieval
A technique that uses neural models—such as SPLADE or uniCOIL—to predict term importance weights for vocabulary tokens, generating sparse vector representations. This approach bridges BM25 and dense retrieval by:
- Maintaining inverted index compatibility like BM25
- Learning contextual term weights beyond simple frequency
- Supporting term expansion through model-inferred synonyms Learned sparse retrieval often outperforms BM25 while preserving its computational efficiency and interpretability.
Inverted Index
The fundamental data structure that enables BM25's efficiency. An inverted index maps each unique term to a postings list containing document IDs and term frequency data. BM25 leverages this structure to:
- Rapidly look up which documents contain query terms
- Access pre-computed document lengths and average field lengths
- Calculate scores using stored term frequency statistics Without the inverted index, BM25's ability to search millions of documents in milliseconds would be impossible.
Cross-Encoder Reranking
A re-ranking methodology where a transformer model processes the concatenated query and candidate document simultaneously to produce a fine-grained relevance score. In a multi-stage pipeline, BM25 often serves as the first-pass retriever generating candidate documents, which are then re-ranked by a cross-encoder. This architecture combines BM25's speed and recall with the cross-encoder's deep semantic precision, though at increased computational cost for the re-ranking stage.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us