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
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)
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.