learning-it by example

Back to the video

Hybrid Search: BM25 Plus Vectors, Tested

Keyword search and vector search fail in opposite ways. I merged them and scored all three on twelve questions.

Video #41 ยท RAG and vector search

Steps in the video

  1. 0:00 Two ways to fail
  2. 0:25 The idea
  3. 0:55 Setup
  4. 1:13 BM25, the index
  5. 1:36 BM25, the score
  6. 2:09 Two ways to merge
  7. 2:25 Four searches
  8. 3:26 Which one got worse?
  9. 3:59 What this does not show
  10. 4:29 Mistakes to avoid
  11. 4:51 My take and next steps
  12. 5:15 Recap

Files

  • bm25.py (30 lines)
  • check_bm25.py (13 lines)
  • compare.py (53 lines)
  • corpus.py (42 lines)
  • hybrid.py (22 lines)
  • lost.py (30 lines)

Download the code (zip)

Tested with

Python 3.12.15 | ollama==0.6.3, rank_bm25==0.2.2, numpy==2.5.3

What this does not show

24 made-up articles and 12 questions I wrote, in three kinds on purpose, so the table shows what each method is good at, not how often it wins. One question is 8 points. No stemming, no reranker, k not tuned. One small embedding model.

Sources

Learning IT by Example.