<!-- llms-explorer concept facts · https://llms-explorer.com/tree/bm25-idf-corpus-statistics/ · pack 2026-10-23 · ~1539 tokens -->

# BM25 IDF corpus statistics

> Source-anchored research for BM25 IDF corpus statistics. Run status: COMPLETED.

Parent: [Atlas Hybrid Fusion and BM25 Diagnostics](https://llms-explorer.com/tree/mongodb-atlas-hybrid-fusion-bm25-frontier-20261001/) · 3 facets · 15 facts · page: https://llms-explorer.com/tree/bm25-idf-corpus-statistics/

## How it works

- For a fixed N, a term found in fewer documents receives greater IDF. Thus the same query-document match can receive a different score when other documents change the corpus statistics. (high confidence) — [source](https://www.mongodb.com/company/blog/engineering/same-query-same-score-consistent-ranking-with-stabletfl-atlas-search)
- Corpus statistics can differ across replicas because indexing and deletion cleanup progress independently. Even unchanged query text and matching documents can receive changed scores; rank changes across pagination boundaries can duplicate or skip results. (high confidence) — [source](https://www.mongodb.com/company/blog/engineering/same-query-same-score-consistent-ranking-with-stabletfl-atlas-search)
- Elasticsearch uses shard-local statistics by default. Its dfs_query_then_fetch option gathers and combines statistics across participating shards before scoring, at the cost of an extra round trip. This is an Elasticsearch mechanism; these sources do not establish an equivalent Atlas Search option. (high confidence) — [source](https://www.elastic.co/blog/practical-bm25-part-1-how-shards-affect-relevance-scoring-in-elasticsearch)
- BM25 does not identify one universal IDF formula. The original Robertson form can be negative when a term appears in more than half the corpus; Lucene adds 1 inside the logarithm, keeping its IDF positive for valid document-frequency counts. (high confidence) — [source](https://cs.uwaterloo.ca/~jimmylin/publications/Kamphuis_etal_ECIR2020_preprint.pdf)
- Algebraic consequence of the documented formula: at fixed N, rarer terms have greater IDF. At fixed n, increasing N raises IDF. For 0 <= n <= N, Lucene's smoothed expression stays positive, including when the term occurs in every field-bearing document. (high confidence) — [source](https://raw.githubusercontent.com/apache/lucene/main/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java)
- BM25 scores can change for an unchanged document when the surrounding corpus changes. MongoDB documents that independently maintained Search indexes can produce different scores for the same documents on different nodes. (high confidence) — [source](https://www.mongodb.com/company/blog/engineering/same-query-same-score-consistent-ranking-with-stabletfl-atlas-search)
- Shard-local scoring is not inherently inconsistent: Elastic says it works well when shard statistics are similar. Distributed statistics gathering adds a round trip and can be costly for queries with many terms, fields, or fuzzy expansions. (low confidence) — [source](https://www.elastic.co/docs/solutions/search/full-text/search-relevance/consistent-scoring)

## Comparisons and alternatives

- For sparse fields, use the field's document count rather than the collection's live-document count as N. Lucene explicitly chooses docCount instead of numDocs to avoid sparse-field skew and keep its statistics compatible with docFreq. (high confidence) — [source](https://raw.githubusercontent.com/apache/lucene/main/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java)

## Facts and statements

- MongoDB Search and Lucene compute IDF as ln(1 + (N - n + 0.5)/(n + 0.5)). N counts documents with the queried field; n counts documents containing the term. Document frequency counts presence per document, not total occurrences. (high confidence) — [source](https://www.mongodb.com/docs/search/query/score/get-details.md)
- Deleted documents can remain in Lucene index statistics until segment merges reclaim them. Different merge histories can therefore give primary and replica copies different statistics and relevance scores. (high confidence) — [source](https://www.elastic.co/docs/solutions/search/full-text/search-relevance/consistent-scoring)
- For Atlas diagnostics, enable scoreDetails in $search and project {$meta: 'searchScoreDetails'}. Compare the IDF explanation's n and N values between discrepant results; Lucene labels them as term-document frequency and field-bearing document count. (high confidence) (verified as of 2026-10-23) — [source](https://www.mongodb.com/docs/search/query/score/get-details.md)
- MongoDB's engineering account scopes score drift to the environment: BM25 is deterministic on a fixed corpus. Pinning requests to one replica reduces cross-replica differences but does not freeze that replica's statistics while updates and merges continue. (high confidence) — [source](https://www.mongodb.com/company/blog/engineering/same-query-same-score-consistent-ranking-with-stabletfl-atlas-search)
- The 2020 reproducibility study found no statistically significant effectiveness differences among eight BM25 variants on three newswire collections. This result scopes claims that a different IDF formula necessarily improves relevance; it does not test live Atlas replica drift. (low confidence) — [source](https://cs.uwaterloo.ca/~jimmylin/publications/Kamphuis_etal_ECIR2020_preprint.pdf)
- Document frequency counts documents containing a term, not its total occurrences. Repeating a term inside one document does not add documents to n; that repetition belongs to a separate scoring input. (high confidence) — [source](https://raw.githubusercontent.com/apache/lucene/main/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java)
- Elasticsearch normally scores with shard-local statistics. Small datasets, custom routing, or searches spanning indices can expose differences; dfs_query_then_fetch gathers and merges query-relevant statistics across participating shards before scoring. This is an Elasticsearch option, not evidence of an Atlas API. (low confidence) (verified as of 2026-10-22) — [source](https://www.elastic.co/docs/solutions/search/full-text/search-relevance/consistent-scoring)
