BM25 Explained

I already wrote a blog post about TF-IDF. I highly recommend reading it before this one. The goal of TF-IDF is to give us a matching score between two documents. Using this score, given a query and a bunch of documents, we can compute how well the query matches each document in our database and return the most relevant results. Here’s the gist of what TF-IDF does: It asks: how much do these two documents overlap on informative keywords? ...

July 3, 2026 · 12 min · Dariush

TF-IDF Explained

Search feels like magic until you build one yourself. Type in a few words, and somehow the right document floats to the top of the list. Under the hood, even the simplest version of this magic relies on an elegant, decades-old idea: TF-IDF. In this post, we’ll build a tiny search engine from scratch, using nothing but Python’s standard library, and use it to find the most relevant document for a query. ...

June 24, 2026 · 9 min · Dariush