EnsembleRetriever
A class in LangChain that combines the results of several retrievers into a single list. The foundation of hybrid search.
Why
One retriever catches the meaning (semantic search), the other — exact words (BM25). Individually, each is weak, together — strong.
How It Works
from langchain.retrievers import EnsembleRetriever
ensemble = EnsembleRetriever(
retrievers=[bm25_retriever, vector_retriever],
weights=[0.4, 0.6], # who to trust more
)
Role in Pipeline
EnsembleRetriever returns the Top-20 candidates, which are then re-ranked by a reranker and the Top-3 are left for LLM.