core practice · coding problem

Calculate a BM25 score by hand

Given tf, df, N, document length, average document length, k1=1.2 and b=0.75, compute the BM25 score of a query term for a document.

The mechanism

BM25 fixes TF-IDF's two flaws: term frequency saturates (the 10th occurrence adds little via the k1 parameter) and document length is normalized (the b parameter). It is still the strongest single keyword ranker and the lexical half of hybrid search.

Study BM25

Expected evidence

A numeric score; verify TF saturation by checking the 10th occurrence adds little.

Try this drill in the practice workspace →

Hints when you need them
  • Score = IDF · (tf·(k1+1)) / (tf + k1·(1 - b + b·dl/avgdl)).
  • b controls length normalization; k1 controls TF saturation.

Watch for these mistakes

  • Believing embeddings make BM25 obsolete — they are complementary
  • Leaving k1/b at defaults without tuning on your corpus
  • Skipping document length normalization
  • Not building search evals to compare against vector retrieval

Check the sources

Practice the same mechanism

Browse all practice briefs