Code lab 8.3 – Hybrid search with LangChain’s EnsembleRetriever to replace our custom function
The file you need to access from the GitHub repository is titled CHAPTER8-3_HYBRID-ENSEMBLE.ipynb
.
We continue this code from the last lab starting with the CHAPTER8-2_HYBRID-CUSTOM.ipynb
file. The complete code for this code lab is CHAPTER8-3_HYBRID-ENSEMBLE.ipynb
. First, we need to import the retriever from LangChain; add this to your imports:
from langchain.retrievers import EnsembleRetriever
This adds EnsembleRetriever
from LangChain to be used as a third retriever that combines the other two retrievers. Note that previously, in Code lab 8.2, we added k=10
to each of the two retrievers to make sure we got enough responses to be similar to the other response.
In the past, we just had one set of documents that we defined as documents
, but here we want to change the name of those documents to dense_documents
, and then add a second set of documents called sparse_documents...