RAG

BM25

BM25 is a sparse ranking function based on term frequency, document frequency, and length normalization.

"refund""policy"scoredoc A417.2doc B022.1Scores exact words: rare words count more; repeats level off.
BM25 is a sparse ranking function based on term frequency, document frequency, and length normalization. Values shown in the worked visual are illustrative unless the labels state otherwise.

How it works

It rewards query terms that are frequent in a document but rare across the collection. Saturation prevents repeated terms from increasing score without bound.

A concrete example

Illustrative: a rare term appearing 3 times contributes more than a common term appearing 3 times.

Do not confuse it with TF-IDF

BM25 adds term saturation and tunable document-length normalization.

Study the full lesson