Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

Information Retrieval

Finds and ranks the documents that best match a query.

The idea

A search engine builds an inverted index from word to documents, then ranks matches. TF-IDF scores a word higher if it is frequent in the document but rare across the collection; BM25 refines this. Modern systems add vector search and learned re-rankers.

tf-idf(t, d) = tf(t, d) · log(N / df(t))

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

startthe0.33cat0.17sat0.17on0.17mat0.17
  • TF
  • IDF
  • TF-IDF

Document 1: "the cat sat on the mat". Which of its words best describe it? Common words like "the" appear everywhere, so they say little.

1/4

Try the slider to score a different document.

Step by step

  1. 1Build an inverted index of the documents.
  2. 2Turn the query into terms.
  3. 3Find the documents containing them.
  4. 4Score each by TF-IDF or BM25 and sort.
  5. 5Optionally re-rank the top results with a neural model.

Where it is used

Web and enterprise search, retrieval for chatbots (RAG).

Watch out for

Keyword matching misses synonyms; pure semantic matching can miss exact terms such as part numbers.

Related