Skip to main content

BM25 Score Calculator

Ranks a few pasted documents against a query with Okapi BM25 and shows each term's IDF, frequency and score contribution.

For anyone tuning k1 and b or checking the lexical half of a hybrid search or RAG pipeline.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

How the score is built

For each distinct query term t and document D, the tool computes IDF(t) × f × (k1 + 1) / (f + k1 × (1 − b + b × |D| / avgdl)), then sums over terms. f is the count of t in D, |D| is the document's token count and avgdl is the mean token count across the pasted documents. A term that is absent contributes exactly zero.

  • IDF rewards rare terms. With 3 documents, a term in 1 of them gets ln(1 + 2.5/1.5) = 0.9808; a term in 2 gets ln(1 + 1.5/2.5) = 0.4700.
  • TF factor grows with frequency but flattens out toward k1 + 1, so repeating a word ten times does not make a document ten times more relevant.
  • Length normalisation shrinks the factor for documents longer than average and raises it for shorter ones, scaled by b.

Each document card lists frequency, TF factor and contribution per term, so you can see which term produced the score.

Worked example with the default inputs

Query: rag retrieval. Three documents of 5, 7 and 6 tokens, so the average length is 6.0000. Document 1 (RAG retrieval uses relevant documents) contains both terms once.

  • IDF: rag appears in 1 document, IDF 0.9808; retrieval appears in 2, IDF 0.4700.
  • Document 1: at 5 tokens it is shorter than average, so its TF factor is 2.2 / 2.05 = 1.0732 for each term, giving a score of 1.5570.
  • Document 2: contains only retrieval, at 7 tokens. Score 0.4400.
  • Document 3: contains retrieve but neither query word, so it scores 0.0000 despite being topically close.

Ties are broken by original line order. Try setting b to 0 and k1 to 0 to see how the ranking collapses toward pure term presence weighted by IDF.

Limits and sources

  • Small-collection statistics: IDF and average length come only from the pasted lines, so scores are not comparable to scores from a real index.
  • No text analysis beyond lowercasing: no stemming, stop-word removal, phrase matching or field weights. Engines such as Lucene and Elasticsearch analyse text differently, so exact numbers will differ.
  • Caps: query up to 1,000 characters, documents up to 100 lines and 100,000 characters in total.

Sources: Robertson, S. and Zaragoza, H. (2009), The Probabilistic Relevance Framework: BM25 and Beyond, Foundations and Trends in Information Retrieval 3(4), 333-389. Robertson, S. et al. (1994), Okapi at TREC-3, for the original BM25 weighting.

Frequently Asked Questions

Common questions about the BM25 Score Calculator

It is a lexical relevance score: how well the words in a document match the words in the query. Each distinct query term contributes IDF times a saturating term-frequency factor, and the contributions are summed. It says nothing about meaning. A document that uses a synonym or a different word form scores zero for that term, which is why it is usually paired with embeddings.

From the same team

Stop paying per token — route AI requests to your own GPU

Wide Area AI is a local-first AI gateway: repeated requests hit an edge cache, the rest run free on your own hardware, and the cloud is only a failover. OpenAI-compatible endpoint, free tier.

Start routing — free

Explore More Tools

Explore these related tools for your next step.

ai
ai
ai
ai
ai
ai