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.
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.
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.