The best of both worlds. Reciprocal Rank Fusion.
We saw that Dense Search (Vectors) and Sparse Search (Keywords) have opposite strengths. Hybrid Search runs both and combines the results.
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.
RRF gives points for being high on either list.
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")
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."