BM25 Score Calculator (Okapi BM25)
Score a query against a corpus and see exactly why each document ranks where it does. The tool shows every term's IDF, term frequency and contribution — the same Okapi BM25 formula Lucene, Elasticsearch and OpenSearch use. Runs in your browser, no signup.
How it works
BM25 (“Best Matching 25”), also called Okapi BM25, is the ranking function that decides which documents a keyword search returns first. For a query Q and a document D drawn from a corpus of N documents, the score is the sum of a per-term contribution over each distinct query term qᵢ(Robertson & Zaragoza, 2009):
BM25(D,Q) = Σᵢ IDF(qᵢ) · f(qᵢ,D)·(k1+1)
───────────────────────────────
f(qᵢ,D) + k1·(1 − b + b·|D|/avgdl)Here f(qᵢ,D) is how many times the term appears in the document (term frequency), |D|is the document's length in tokens, and avgdl is the average document length across the corpus. Two parameters tune the behaviour:
- k1 (default 1.2) sets term-frequency saturation. A term appearing twice does not score twice as high as once — the denominator grows with each occurrence, so extra repeats add less and less. This is BM25's signature difference from plain TF-IDF.
- b (default 0.75) sets length normalization. At b=0 length is ignored; at b=1 a document twice the average length is penalised in full, stopping long documents from winning just by containing more words.
The inverse document frequency IDF(qᵢ) rewards rare terms. With n(qᵢ) the number of documents containing the term, this tool offers two forms. The default Lucene variant, ln(1 + (N − n + 0.5)/(n + 0.5)), is always non-negative and is what Elasticsearch and OpenSearch ship. The classic Robertson–Spärck-Jones variant, ln((N − n + 0.5)/(n + 0.5)), goes slightly negative for terms in more than half the corpus — which is why a BM25 score can be negative.
The tool tokenizes the query and every document identically: lowercase (unless case sensitivity is on) then split on runs of non-alphanumeric characters. There is no stemming or stop-word removal, so results stay reproducible and “cat” is a different term from “cats”. It then counts term frequencies, computes each term's IDF, sums the contributions per document, and sorts descending. Every number in the breakdown is the exact value that feeds the total.
Worked examples
Frequently asked questions
Sources & references
- Robertson & Zaragoza (2009) — The Probabilistic Relevance Framework: BM25 and Beyond
- Robertson et al. — Okapi at TREC-3 (1994), the original Okapi weighting
- Apache Lucene — BM25Similarity (non-negative IDF variant, k1=1.2, b=0.75 defaults)
The formula, IDF variants and parameter defaults on this page were last cross-checked against these sources on 2026-07-10. The worked examples are reconciled by hand to four decimal places.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.