What Is BM25 (Best Matching 25)? How Lexical Scoring Powers Search & RAG
BM25 (Best Matching 25)—also known as Okapi BM25—is a probabilistic information retrieval algorithm that scores how relevant a document is to a search query using exact-match term frequency, inverse document frequency, and document-length normalization. Today, it serves as the lexical backbone of hybrid search alongside dense vector embeddings.
How BM25 Improves on Classic TF-IDF
Before neural embeddings existed, TF-IDF was the standard way search engines measured lexical relevance. However, TF-IDF had two major flaws: repeating a keyword 50 times kept linearly inflating a page's score (rewarding keyword stuffing), and long documents naturally accumulated more term occurrences than concise answers.
BM25 solves both problems using two tunable parameters:
- Term Frequency Saturation (
k1): The first few occurrences of a query term strongly boost relevance, but additional repetitions yield diminishing returns and eventually plateau. Mentioning "SOC 2 compliance software" 4 times naturally beats stuffing it 40 times. - Document Length Normalization (
b): BM25 penalizes bloated pages where a target term is diluted across thousands of off-topic words, rewarding focused, high-signal pages and semantic chunks. - Inverse Document Frequency (IDF): Rare, specific terms (e.g., "NetSuite webhook idempotency") carry dramatically more scoring weight than common words ("software" or "platform").
Why BM25 Still Matters in the Era of LLM & Vector Search
A common misconception in Generative Engine Optimization (GEO) is that vector embeddings made exact-match lexical search obsolete. In production, dense vector search frequently fails on exact acronyms, API endpoints, brand names, version numbers, and niche B2B SaaS jargon.
That is why modern search engines and RAG systems run BM25 and dense vector retrieval in parallel, then merge both ranked lists using Reciprocal Rank Fusion (RRF).
| Query Type | BM25 (Lexical) Strength | Dense Vector Strength |
|---|---|---|
| Exact Acronyms & Error Codes (e.g., "HTTP 429 Stripe") | Very High — exact token match | Low — embeddings blur rare tokens |
| Brand & Competitor Names (e.g., "Linear vs Jira") | Very High — high IDF weight | Moderate — can confuse similar entities |
| Conceptual / Synonym Queries (e.g., "reduce SaaS churn") | Low — misses synonyms | Very High — captures semantic intent |
How to Optimize B2B SaaS Content for BM25 + Vector Retrieval
To rank in both traditional SERPs and AI answer engines powered by hybrid retrieval, your pages must satisfy BM25's lexical precision without tripping over-optimization filters:
- Use Exact Buyer Terminology in Headings & First Paragraphs: Place exact category names, integration names, compliance standards (HIPAA, ISO 27001, SOC 2), and feature strings cleanly in H1s, H2s, and opening sentences.
- Eliminate Fluff to Protect Length Normalization: Tight, scannable sections keep your term-to-length ratio healthy both at the full-page level and when pages are split into RAG chunks.
- Pair Exact Terms with Semantic Context: Immediately define acronyms and connect them to related entities so dense vector retrievers and BM25 retrievers both surface your page at the top of the candidate pool.
Frequently Asked Questions
Does Google still use BM25?
While Google's modern ranking stack relies heavily on neural models like RankBrain, BERT, MUM, and NavBoost, lexical matching signals rooted in BM25/TF-IDF principles remain foundational for initial candidate retrieval and exact-match queries (especially brand names, codes, and technical specs).
What are the default k1 and b parameters in BM25?
In most search engines like Elasticsearch and Lucene, the default parameters are k1 = 1.2 (controlling term-frequency saturation) and b = 0.75 (controlling document length normalization).
How does BM25 relate to Reciprocal Rank Fusion (RRF)?
Because BM25 outputs unbounded lexical scores while vector search outputs cosine similarity scores between 0 and 1, hybrid search pipelines use Reciprocal Rank Fusion (RRF) to combine their rank positions cleanly without complex score calibration.
Does BM25 reward keyword stuffing?
No. Unlike naive keyword density or basic TF-IDF, BM25's k1 saturation parameter flattens the score curve after just a few occurrences, making repetition ineffective while penalizing bloated, unfocused pages.