Chatbot with web and proprietary data retrieval using LangChain
Before You Get Started
To use the You.com Search API, you will need an API key. Please visit api.you.com for more details.
Creating a chatbot that retrieves data from the web and a proprietary data source
Follow this guide to create basic chatbots in LangChain that retrieve context from proprietary data sources and the web using the You.com API. You will need to have
the environment variables YDC_API_KEY
and OPENAI_API_KEY
set up to follow this guide.
Installation
These are the packages and associated versions that need to be installed to follow this guide.
Creating a chatbot using Chains in LangChain
Instantiate the You.com Retriever in LangChain
Proprietary Datasource Retriever
In this example, a CSV file is being loaded, split into chunks, the chunks are being vectorized, stored in a Facebook AI Similarity Search (FAISS) vector store, and a LangChain retriever is being created from the vector store. You can check out various the document loaders and retrievers in the LangChain docs.
Creating an Ensemble Retriever in LangChain
An ensemble retriever that can ensemble the results of both the FAISS vector store retriever and the You.com retriever.
Create chains
This block demonstrates how to create basic chains without chat history. This assumes that you have created a LangChain ChatPromptTemplate and stored it in a variable called qa_prompt
.
To add chat history to your chatbot, you can check out the LangChain documentation on adding chat history to Q & A applications.
Creating a chatbot using Agents in LangChain
Instantiate the You.com Tool in LangChain
Proprietary Datasource Retrieval Tool
Convert the proprietary datasource LangChain retriever we defined above into a tool.
Creating a LangGraph Agent
The FAISS vector store retriever tool and the You.com tool can be passed as tools to the LangGraph agent. LangGraph agents come with built-in persistence, so we can add memory to the chatbot to engage in back-and-forth conversations. In this example, an in-memory checkpointer is being utilized to track chat history.