Ranking — TF-IDF and BM25, the Math of Relevance
Finding the documents that contain your words is the easy part; putting the best one first is where search lives or dies. For decades, the answer to "how relevant is this document to this query?" has come from two intuitions made precise: a word matters more in a document that uses it often, and matters less if it's common across all documents. TF-IDF and BM25 turn those intuitions into the scoring functions that rank most of the world's text search — and understanding them demystifies why search returns what it does.
Finding matches is easy; putting the best first is where search lives. Two intuitions — a word matters more when frequent in a document, less when common across all — become TF-IDF and then BM25, the decades-long default (and the keyword score in hybrid RAG). Its lexical ceiling is the vocabulary gap.