learning-it by example

Back to the video

Reranking With a Cross-Encoder: Does It Help? Python Test

My search found the right page but did not put it first. Can a reranker fix that?

Video #42 ยท RAG and vector search

Steps in the video

  1. 0:00 The right page was in the top five, but not first
  2. 0:26 The idea
  3. 0:56 Setup
  4. 1:20 Pages and questions
  5. 1:47 Two first stages and a reranker
  6. 2:08 Count what changes
  7. 3:00 What this does not show
  8. 3:28 Mistakes to avoid
  9. 3:57 My take and next steps
  10. 4:25 Recap

Files

  • compare.py (15 lines)
  • docs.py (38 lines)
  • search.py (31 lines)

Download the code (zip)

Tested with

Python 3.12.15 | fastembed==0.9.1

What this does not show

Twelve made-up pages and twenty questions that I wrote, one small reranker, one small embedding model, one run on a laptop. A reranker can only reorder what the first stage found. A larger collection may give different numbers.

Sources

Learning IT by Example.