03. EnsembleRetriever
Ensemble Retriever
EnsembleRetriever Is LangChain's ability to combine multiple searchers to provide stronger search results. This searcher can take advantage of various search algorithms to achieve better performance than a single algorithm.
Main features One. Integrating multiple searchers: Receive different types of searchers as input to combine results. 2. Resorting results: Reciprocal Rank Fusion Use algorithms to rank results. 3. Hybrid search: mainly sparse retriever (E.g. BM25) and dense retriever (E.g. embedding similarity) is used in combination.
Advantages -Sparse retriever: effective for keyword-based search -Dense retriever: effective for semantic similarity based searches
Due to these complementary characteristics EnsembleRetriever Can provide improved performance in various search scenarios.
More details LangChain official document See.
# API A configuration file for managing keys as environment variables.
from dotenv import load_dotenv
# API Load key information
load_dotenv()True# LangSmith Set up tracking. https://smith.langchain.com
# !pip install langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("CH11-Retriever")EnsembleRetrieverBy initializingBM25RetrieverWowFAISSCombine the finder. Each searcher is weighted.
ensemble_retriever Object get_relevant_documents() Search for relevant documents by calling the method.
Change of runtime Config
You can change the properties of retriever even at runtime. This is ConfigurableField It is possible using classes. - weights parameter ConfigurableField Defined as an object. -The field's ID is set to "ensemble_weights".
Search City
configSpecify search settings through parameters.ensemble_weightsBy setting the weight of the option to [1, 0] Weight of all search results gives BM25 retriever more Be sure to be.
This time, the weight of all search results when searching More to FAISS retriever Be sure to be.
Last updated