Hybrid Search (BM25 + Vectors)

16 min read

A RAG system is only as good as the passages that its search finds. Keyword search is good at exact words, and vector search is good at meaning. Hybrid search runs both and merges the results, so each one covers the weak spots of the other.

New words

RAG
An AI that first searches your documents, then writes an answer from what it found.
BM25
A classic formula that ranks documents by the keywords they contain.
Vector
A list of numbers, where similar meanings get vectors that are close together.
Embedding
The vector that a model makes from a text to capture its meaning.
Cosine similarity
A score that shows how close the meanings of two vectors are.
RRF
Reciprocal Rank Fusion: a way to merge ranked lists using only the ranks.
Recall
The share of the right passages that appear in the top results.

What you will learn

  1. The problem: two kinds of question
  2. BM25: keyword search done well
  3. Vector search: matching by meaning
  4. Where each one fails
  5. Combining them: Reciprocal Rank Fusion
  6. Try it: fuse two rankings
  7. Trade-offs: what can go wrong?
  8. Production practices: what real teams do
  9. In code
  10. In a real system
  11. Interview tip
  12. Key takeaways

10 quiz questions at the end.

Start this lesson

The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.

All lessons · Back to the roadmap