Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 5 · 4. Embeddings & Vector Stores
Lesson 37 of 68

Hybrid Search Concepts

The best of both worlds. Reciprocal Rank Fusion.

Derpx0610 Jan · 1 min read
LangChain Mastery
Embeddings: What Matters in PracticeEmbedding Models in LangChainVector Stores: FAISS, ChromaPersisting & Reloading IndexesMetadata FilteringDense vs Sparse (BM25 Overview)Hybrid Search Concepts
Contents
1. Why Choose?2. Theoretical Workflow3. Reciprocal Rank Fusion (RRF)4. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
Embeddings: What Matters in PracticeEmbedding Models in LangChainVector Stores: FAISS, ChromaPersisting & Reloading IndexesMetadata FilteringDense vs Sparse (BM25 Overview)Hybrid Search Concepts
Contents
1. Why Choose?2. Theoretical Workflow3. Reciprocal Rank Fusion (RRF)4. Summary

1. Why Choose?

We saw that Dense Search (Vectors) and Sparse Search (Keywords) have opposite strengths. Hybrid Search runs both and combines the results.

2. Theoretical Workflow

  1. User Query: "Error 501 on login page."
  2. Dense Retriever: Finds docs about "Login Issues" (Concepts).
  3. Sparse Retriever: Finds docs containing "Error 501" (Exact Match).
  4. Ensemble: Combine the two lists.

3. Reciprocal Rank Fusion (RRF)

How do you combine the lists? You can't just add the scores (Cosine Similarity score 0.8 is not comparable to BM25 score 15.0). We use Rank Fusion.

We look at the rank, not the score.

  • Doc A: Rank 1 in Dense, Rank 5 in Sparse.
  • Doc B: Rank 10 in Dense, Rank 1 in Sparse.

RRF gives points for being high on either list.

hybrid_search.py
from langchain.retrievers import EnsembleRetriever

ensemble_retriever = EnsembleRetriever(
  retrievers=[bm25_retriever, vector_retriever],
  weights=[0.5, 0.5]
)

docs = ensemble_retriever.get_relevant_documents("query")

4. Summary

Hybrid Search is the current state-of-the-art for production RAG. It provides the "Safety" of keywords with the "Magic" of vectors.

Key Intuition: "Don't put all your eggs in one index."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonDense vs Sparse (BM25 Overview)Next lesson →The Retriever Interface