Skip to main content
Deep DiveSearch AlgorithmsTrade-Off Analysis· 5 min read· in Content Types

Evaluating BM25 Against TF-IDF: The Saturation Function That Solved Keyword Stuffing in Search

By introducing a mathematical cap on how much a single repeated word can influence a document's relevance score, the BM25 probabilistic model fundamentally shifted search engines away from linear keyword counting. The algorithm's term saturation and length normalization parameters remain the industry baseline that modern neural search models must compete against.

By Sergei Orlov

Information Retrieval Researchers 40%Enterprise Search Engineers 40%Algorithm Historians 20%
Information Retrieval Researchers
Focus on the theoretical bounds and probabilistic frameworks underlying search algorithms.
Enterprise Search Engineers
Focus on implementation defaults, parameter tuning, and computational efficiency in production systems.
Algorithm Historians
Trace the evolution of search mechanics from early vector space models to modern implementations.

Perspectives this story doesn't cover

  • SEO Practitioners
  • Vector Database Developers
1.2 - 2.0
Standard k1 saturation parameter range
0.75
Default b length normalization parameter
2.2x
Maximum term weight multiplier (at k1=1.2)

When a user searches for a specific technical error, the top result is no longer a page that repeats the error code 500 times, but rather a document containing the code alongside related diagnostic terms. That shift in retrieval quality stems from a specific mathematical boundary introduced by the Okapi BM25 algorithm. Before its widespread adoption, search engines relying on Term Frequency-Inverse Document Frequency (TF-IDF) rewarded repetition linearly: a document with 50 instances of a word was scored significantly higher than one with five. BM25 altered that baseline by introducing a saturation curve, capping the value of repeated terms and forcing retrieval systems to prioritize documents that match multiple different words from a user's query.[4]

The foundation of both models rests on the Inverse Document Frequency (IDF) metric, formalized by Karen Spärck Jones in 1972. IDF operates on a simple premise: words that appear in nearly every document, like "the" or "algorithm," carry very little informational weight. Conversely, a rare term like "saturation" carries high weight. "Understanding inverse document frequency: on theoretical arguments for IDF," notes the Journal of Documentation, establishes that a term's specificity is inversely proportional to the number of documents containing it.[2][3]

Where the models diverge is in how they handle the first half of the equation: Term Frequency (TF). In standard TF-IDF, the calculation is often a straightforward count. If document A contains the word "database" three times and document B contains it 30 times, document B receives a significantly higher term score. This unbounded linear scaling created a massive vulnerability in early web search, allowing publishers to manipulate rankings simply by hiding hundreds of invisible keywords at the bottom of a webpage.[4][5]

The Okapi BM25 model, introduced by Stephen Robertson and his team at City University London for the 1994 Text Retrieval Conference (TREC-3), approached the problem probabilistically rather than geometrically. Instead of asking "how many times does this word appear," BM25 asks "what is the probability that this document is relevant to the user's information need, given the term frequencies?"[1]

To answer that, BM25 introduced a non-linear saturation parameter known as k1. Typically calibrated between 1.2 and 2.0, k1 dictates how quickly the value of an additional keyword match diminishes. The first time a query term appears in a document, it contributes heavily to the score. The second appearance adds less. By the time the term appears for the sixth or seventh time, the score approaches a hard mathematical asymptote.[4][6]

Unlike TF-IDF's linear growth, BM25's k1 parameter forces the relevance score to saturate, neutralizing keyword stuffing.
To answer that, BM25 introduced a non-linear saturation parameter known as k1.

As the Stanford NLP Group notes in its analysis of the algorithm, "Okapi BM25: a non-binary model," the saturation curve effectively caps the term frequency component. If k1 is set to 1.2, the maximum possible multiplier for term frequency—even if the word appears a million times—is 2.2. This saturation function instantly neutralized basic keyword stuffing, as a spam document repeating one word 100 times would be outranked by a legitimate document containing three different words from the user's query just once each.[4]

The second major structural flaw in TF-IDF was its bias toward long documents. A 10,000-word technical manual is statistically far more likely to contain any given search term than a 500-word abstract, simply by virtue of having a larger vocabulary. Standard TF-IDF would routinely bury concise, highly relevant documents beneath massive, sprawling texts that happened to accumulate more raw term matches.[1][5]

BM25 solved this through a document length normalization parameter called b. Usually set at a default of 0.75, the b parameter adjusts the term frequency based on the length of the specific document relative to the average document length across the entire corpus. If a document is longer than average, the algorithm mathematically shrinks its term frequency counts, demanding more occurrences of the word to achieve the same relevance score as a shorter document.[1][5]

"Comparing full text search algorithms," software engineer Evan Schwartz notes that modern database systems have almost universally migrated to BM25. Postgres, for instance, utilizes BM25 for its full-text search capabilities, while enterprise search giants Elasticsearch and Lucene officially deprecated TF-IDF in favor of BM25 as their default scoring algorithm in versions 5.0 and 6.0, respectively.[5]

Despite being over three decades old, BM25 remains the benchmark against which all modern AI-driven search models are measured. While dense vector embeddings and neural search models excel at semantic matching—understanding that "sneakers" and "running shoes" are related—they often struggle with exact keyword matching for rare nouns or serial numbers.[6]

Google Cloud researchers exploring the transition "from BoW to BM25" highlight that the algorithm's lack of semantic understanding is actually a feature in specific contexts. Because it relies purely on exact token matches weighted by corpus rarity, BM25 does not hallucinate connections or drift from the user's explicit query constraints.[6]

The shift from TF-IDF to BM25 represents a transition from a naive counting mechanism to a calibrated probabilistic framework. By mathematically enforcing the reality that a word's 50th appearance is not 50 times more informative than its first, BM25 established the baseline mechanics of modern information retrieval that even billion-parameter neural networks are still forced to compete against.[1]

Different angles

The BM25 Probabilistic Model

The industry standard for sparse keyword retrieval, utilizing term saturation and length normalization.

For: Caps the influence of keyword stuffing through the k1 parameter (typically capping term weight at 2.2x its initial value) and prevents long documents from dominating short ones via the b parameter. Against: Requires parameter tuning (k1 and b) which can be corpus-dependent, and computation is slightly more expensive than basic TF-IDF. Evidence: Adopted as the default scoring algorithm in Elasticsearch 5.0 and Lucene 6.0, replacing TF-IDF. Fits well when: Ranking full-text documents of varying lengths where keyword spam is a risk. Does not fit when: The corpus consists of uniformly short, highly structured records where exact frequency matters more than normalization.

The TF-IDF Baseline

The foundational vector space model that scales term frequency linearly.

For: Computationally lightweight, requires zero parameter tuning out of the box, and provides a highly interpretable baseline for term importance. Against: Linear term frequency scaling means a document repeating a query term 100 times will mathematically crush a document using it 5 times, making it highly vulnerable to spam. It also lacks native document length normalization, inherently biasing results toward longer texts. Evidence: Theoretical arguments for IDF established in the 1970s remain valid, but pure TF-IDF has been largely deprecated in web-scale search. Fits well when: Processing controlled, non-adversarial datasets of similar-length documents, or serving as a feature extraction step for downstream machine learning classifiers. Does not fit when: Searching across heterogeneous web pages or user-generated content where document length varies wildly.

Sources

Source coverage

7 outlets

3 viewpoints surfaced

Information Retrieval Researchers 40%Enterprise Search Engineers 40%Algorithm Historians 20%
  1. [1]Foundations and Trends® in Information RetrievalInformation Retrieval Researchers

    The Probabilistic Relevance Framework: BM25 and Beyond

    Read on Foundations and Trends® in Information Retrieval
  2. [2]City, University of LondonInformation Retrieval Researchers

    The Spärck Jones / Robertson IDF page

    Read on City, University of London
  3. [3]Journal of DocumentationInformation Retrieval Researchers

    Understanding inverse document frequency: on theoretical arguments for IDF

    Read on Journal of Documentation
  4. [4]Stanford NLP GroupInformation Retrieval Researchers

    Okapi BM25: a non-binary model

    Read on Stanford NLP Group
  5. [5]Evan SchwartzEnterprise Search Engineers

    Comparing full text search algorithms: BM25, TF-IDF, and Postgres

    Read on Evan Schwartz
  6. [6]Google CloudEnterprise Search Engineers

    Exploring Information Retrieval from BoW to BM25

    Read on Google Cloud
  7. [7]Factlen Editorial Team

    Synthesis by Factlen editorial team

    Read on Factlen Editorial Team

Comments

Stay informed

Every angle. Every day.

Get Content Types stories with full source coverage and perspective breakdowns delivered to your inbox.