How to use Exa’s integration with LangChain to perform RAG.
Pre-requisites and installation
OPENAI_API_KEY
and EXA_API_KEY
for OpenAI and Exa keys respectively. Use Exa Search to power a LangChain Tool
ExaSearchRetriever
. This is a retriever that connects to Exa Search to find relevant documents via semantic search. First import the relevant libraries and instantiate the ExaSearchRetriever.Create a prompt template (optional)
Parse the URL and content from Exa results
Join Exa results and content for retrieval
Set up the rest of the toolchain including OpenAI for generation
Running the full RAG toolchain
Optionally, stream the output of the chain