BM25

BM25 (Best Matching 25) is the default ranking function of most search engines. It keeps the idea of TF-IDF but fixes its two weaknesses: repeated words count less and less, and document length is compared to the average.

IDFrare words count more
×
TF saturationrepeats have diminishing returns
×
Length normalizationlong documents are toned down

1. Query & Documents

Try repeating cat many times in D1: its score grows less and less.

2. Parameters

How fast repeated words saturate. 0 = only presence counts.

How much length matters. 0 = ignore length, 1 = fully normalize.

Weight of a word vs. how many times it appears (for an average-length document)
Learn more

For each query word: IDF × tf × (k1 + 1) / (tf + k1 × (1 − b + b × length / avg_length)), summed over the query words.

The curve flattens toward k1 + 1: a document can't win just by repeating a word. Common defaults are k1 = 1.2 and b = 0.75.

BM25's IDF, log((N − DF + 0.5) / (DF + 0.5) + 1), behaves like TF-IDF's but never drops to zero or below.

3. Ranking

Per-word details