Specify the scoring formula explicitly
Positive smoothed IDF and length correction. N and df count documents; document and average lengths count consistently tokenized indexing tokens.[1][2]
First, the variant with numerator factor k1+1. Q here is a set of distinct query terms without additional query weights; absent terms contribute zero.[1]
f counts occurrences of the term within the document. df instead counts corpus documents containing it. Average length and the individual document length must use matching field and tokenization definitions. The calculator permits k1≥0 and 0≤b≤1. An absent term explicitly contributes zero even when k1=0; a present term then retains only its IDF weight.[2]
Older Robertson IDF without the outer +1 inside the logarithm can become negative for common terms. The positive variant chosen here is different. An implementation may also omit constant factor k1+1. These are identifiable conventions rather than automatically incorrect calculations. Record the exact variant before comparing numbers from different libraries.[1][4]
Understand saturation and document length separately
With the length factor fixed, f(k1+1)/(f+KD) does not grow linearly. A second occurrence adds less contribution than the first. For positive KD the factor formally approaches k1+1; larger k1 delays saturation. This is a function comparison holding other quantities fixed. In a real document, f cannot exceed its token length.[2]
Additional occurrences have diminishing benefit
Free with a Quanta account. Your download stays ready after registration.
b controls a different effect. With b=0, KD=k1 and length normalization disappears. With positive b, a longer document has a larger denominator for the same f. This does not mean every short document must outrank every long one: IDF, occurrence counts, other query terms and possible boosts also matter. Common values k1=1.2 and b=0.75 are documented software defaults, not universally optimal parameters.[3][2]
Two examples using the same corpus
Calculate one term’s complete contribution
- Given
- N=100, df=10, f=3, L=100, average length 100, k1=1.2 and b=0.75. Use positive IDF and numerator factor k1+1.
- Find
- Evaluate term rarity and the saturation factor separately.
Positive IDF uses document counts, not f.
At average document length, KD equals k1.
The saturation factor equals 6.6/4.2.
Result: The single-term contribution is about 3.5573. A query with multiple distinct terms would require adding their correspondingly defined contributions.
Check: Without the constant numerator factor, the result is 3.55731398/2.2≈1.61696090. The calculator offers this second convention as a separate mode.
The same count in documents of different lengths
- Given
- In the same corpus, keep N=100, df=10, average length 100, f=3, k1=1.2 and b=0.75. Compare document A with L=50 and document B with L=200.
- Find
- Compare only the effect of length correction.
For the shorter document, the length factor is 0.625.
For the longer document, the length factor is 1.75.
Use the same positive IDF from example 1.
Result: In this controlled comparison, the shorter document has the larger term contribution. Different occurrence counts or additional terms could change overall ranking.
Check: Setting b=0 makes both denominators 3+1.2 and both contributions about 3.5573, isolating the length effect.
Recall the method later with the formula’s flashcards.
11 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Why libraries return different numbers
OpenSearch documents removal of the earlier constant factor k1+1 from its native BM25 path starting with version 3.0. With the same k1=1.2, corresponding contributions are therefore smaller by a factor of 2.2. If every contribution in an evaluation loses the same positive factor, ordering stays unchanged. This is not a general promise for mixed fields with different parameters, boosts or statistical definitions.[4]
Field statistics, tokenization, synonym handling and encoded length norms also affect real library scores. This calculator is a transparent numerical model with explicitly supplied lengths, so it does not promise bit-for-bit reproduction of an Elasticsearch or OpenSearch index. TF-IDF and cosine similarity use different weighting and normalization steps. Semantic embeddings can provide complementary features, but do not remove the need to evaluate retrieval quality on actual tasks.[3][4]
Five exercises with solutions
Calculate · Foundation
N=100, df=10, f=1, L=average length=100, k1=1.2 and b=0.75. Calculate the positive BM25 contribution including k1+1.
Show hint
The saturation factor is 2.2/(1+1.2).
Learning goal: Recognize the normalized single-occurrence case.
Show solution and calculation
At average length, KD=1.2.
The saturation factor is exactly 1.
Hence s=IDF=ln(202/21)≈2.263745.
Further occurrences change the factor.
Rearrange · Application
For L=average length and k1=1, contribution divided by positive IDF is exactly 1.5. What f gives this under the k1+1 convention? The document is sufficiently long.
Show hint
Solve 1.5=2f/(f+1) for f.
Learning goal: Invert the saturation function for frequency.
Show solution and calculation
From 1.5(f+1)=2f follows 1.5=0.5f and f=3.
This is an admissible integer frequency if L is at least 3.
Inversion here is an algebra exercise; the page calculator computes the score forward.
Interpret · Application
Two documents from the same corpus have equal f and IDF for one term, but different lengths. Do their term contributions differ when b=0 and k1 is the same?
Show hint
Substitute b=0 into KD.
Learning goal: Isolate the effect of b=0.
Show solution and calculation
No.
KD=k1(1−0+0·L/average length)=k1.
The document’s particular length drops out of this term contribution.
Additional query terms, other IDF values or boosts would be separate influences.
Error analysis · Application
With L=average length and k1=1.2, a solution claims that increasing f from 1 to 2 doubles the contribution. Check this with unchanged positive IDF.
Show hint
Compare 2.2/2.2 with 4.4/3.2.
Learning goal: Test a linear-frequency assumption against BM25.
Show solution and calculation
At f=1 the factor is 1.
At f=2 it is 4.4/3.2=1.375.
Contribution rises by 37.5%, not 100%.
This diminishing increment is the saturation modeled here.
Transfer · Challenge
Two total scores computed with the same convention and k1=1.2 are 4.4 and 2.2. Every term contribution now loses only factor k1+1. What scores and ordering result?
Show hint
Divide both totals by the same positive factor 2.2.
Learning goal: Distinguish constant score normalization from ranking changes.
Show solution and calculation
The new scores are 2 and 1.
Ordering is unchanged because both are divided by the same positive constant.
This implies neither a loss of quality nor general comparability with other indexes.
Different field-specific k1 values would not automatically supply one common constant.
Check your understanding with the formula’s reference test.
7 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Sources for this explanation
Quanta · Updated November 1, 2026
- Elastic: Similarity in Elasticsearch, explicitly named BM25 IDF and numerator convention
- Elastic: Practical BM25, algorithm variables, saturation and length normalization
- Elasticsearch documentation: similarity settings and current documented defaults
- OpenSearch documentation: keyword search and BM25 normalization change from version 3.0
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Added a positive IDF variant, original saturation and length-normalization examples, and explicitly separate score conventions.
Cite this reference page
Quanta. Okapi BM25 ranking. Updated November 1, 2026. https://quanta-study.de/en/formula-sheet/bm25-ranking
When citing a specific scientific statement, also cite the specialist source linked to that statement.