Skip to main content

BM25

Why the name BM25?

BM means Best Match which is a family of retrieval functions. 25 is just the version that worked well and became the standard.

BM25 is a ranking algorithm which ranks each document relative to the query. It doesn't filter the result. Just returns all documents (or we can ask to return top K) and its corresponding scores. It's up to the application layer to consider or ignore the returned files based on the ranking.

BM25 isn't about semantic search

It's confusing since BM25 is also used in the context of AI. Still, BM25 isn't about semantic search. It does only lexical search which means exact word search.

BM25 with pre-processing

Even though BM25 is lexical search, usually there is a preprocessing step that comes before the BM25 search. This step usually extends the search with different words and then the lexical search is performed using all the words.

bm25-search
implementation in RAG Databases

In case of Neo4J, when a FULL_TEXT index is created, all queries on this index are performed using BM25 by default.

These indexes are inverted indexes which means the index stores the words and the documents that contain those words. Therefore, it already has all the information necessary for performing BM25.