This repo is an implementation of a locally hosted chatbot specifically focused on question answering over the LangChain documentation. Built with LangChain and FastAPI.
The app leverages LangChain's streaming support and async API to update the page in real time for multiple users.
This is a fork of the original ChatLangChain project. It provides a good example of using LangChain to solve a "semantic search" problem over specific content. The following changes have been made:
- To run any of the code you will want to create a
.env
file at the root of the repo. This file should have the following contents:OPENAI_API_KEY=<Vantiq OpenAI key>
. The location of this key has been sent to the Vantiq AI teams channel. ingest.py
has been changed to ingest therules.md
file from our documentation. The code assumes that this repo was cloned as peer to our docs repo. It creates a file calledrules.pkl
that is used by the app. This file is not checked in, but a pointer to a copy was sent to the Teams channel (generation of the file does cost money, though I'm not sure how much at this point).- Some of the code has been changed to address API changes since this was originally published.
We recommend the use of a virtual environment for running this code (or any python project really). There are a few ways to do this, so if you'd like some setup help please reach out to the Vantiq AI team. The instructions below rely on make
, but you can also just run main.py
from your IDE if you prefer.
- Install dependencies:
pip install -r requirements.txt
- Run
ingest.sh
to ingest LangChain docs data into the vectorstore (only needs to be done once).- You can use other Document Loaders to load your own data into the vectorstore.
- Run the app:
make start
- To enable tracing, make sure
langchain-server
is running locally and passtracing=True
toget_chain
inmain.py
. You can find more documentation here.
- To enable tracing, make sure
- Open localhost:9000 in your browser.
Deployed version (to be updated soon): chat.langchain.dev
Hugging Face Space (to be updated soon): huggingface.co/spaces/hwchase17/chat-langchain
Blog Posts:
There are two components: ingestion and question-answering.
Ingestion has the following steps:
- Pull html from documentation site
- Load html with LangChain's ReadTheDocs Loader
- Split documents with LangChain's TextSplitter
- Create a vectorstore of embeddings, using LangChain's vectorstore wrapper (with OpenAI's embeddings and FAISS vectorstore).
Question-Answering has the following steps, all handled by ChatVectorDBChain:
- Given the chat history and new user input, determine what a standalone question would be (using GPT-3).
- Given that standalone question, look up relevant documents from the vectorstore.
- Pass the standalone question and relevant documents to GPT-3 to generate a final answer.