All labs Animated labs The chapter Course home

Lab 06Retrieval ranker

A retrieval system has to rank documents for a query before a model reads anything. Edit the documents or the query and watch BM25 rescore them term by term. Then merge two rankings that disagree. Every number is computed the way the chapter does it, and matches the worked tables in the book.

1. BM25, term by term

Try:

Saturation: what the k1 slider does to a repeated word

What to look for

  • Query the moon. Documents d1 and d3 tie at the top, and the still adds a little to d2, because BM25 gives a very common word a small positive weight where tf-idf gave exactly zero.
  • Slide b to 0 and edit d1 into a long sentence. Length stops mattering. Slide it back to 1 and the long document is penalised.
  • Slide k1 to 0 and every word counts once however often it occurs. Slide it up and repeats start to count, but with diminishing returns.
  • Query satellite. A word that is in no document scores nothing. A dense retriever could still match it by meaning, which is why systems run both.

2. Merging two rankings

BM25 scores and cosine similarities live on different scales, so they cannot simply be added. Reciprocal rank fusion uses only the ranks: each list gives a document 1/(k + rank). Use the arrows to reorder either list.

Dense ranking

    Keyword ranking

      Fused

      Where this fits

      This is Retrieval-Augmented Generation. BM25 is the keyword half of a hybrid retriever, and reciprocal rank fusion is how its ranking is merged with a dense one. The same scoring is the retriever you build in Project 8.