03. EnsembleRetriever

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.

Copy

# API A configuration file for managing keys as environment variables.
from dotenv import load_dotenv

# API Load key information
load_dotenv()

Copy

True

Copy

# 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")

Copy

  • EnsembleRetriever By initializing BM25Retriever Wow FAISS Combine the finder. Each searcher is weighted.

Copy

ensemble_retriever Object get_relevant_documents() Search for relevant documents by calling the method.

Copy

Copy

Copy

Copy

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".

Copy

  • Search City config Specify search settings through parameters.

  • ensemble_weights By setting the weight of the option to [1, 0] Weight of all search results gives BM25 retriever more Be sure to be.

Copy

Copy

This time, the weight of all search results when searching More to FAISS retriever Be sure to be.

Copy

Copy

Last updated