This repo is an implementation of a locally hosted chatbot specifically focused on question answering over my docs (markdown files). 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 (like ChatGPT)
-
Install dependencies:
pip install -r requirements.txt
-
set
MARKDOWN_FILES
env var with the path to your source filesexport MARKDOWN_FILES="<path to your source files>
-
Run
make ingest
ormake ingest-openai
to ingest markdown docs into the vectorstore (only needs to be done once). -
Run the app:
make run
or justmake
-
Open localhost:9000 in your browser.
This project is based on the original LangChain chat client example
Blog Posts:
There are two components: ingestion and question-answering.
Ingestion has the following steps:
- Load markdown files with LangChain's UnstructuredMarkdownLoader
- Split documents with LangChain's TextSplitter
- Create a vectorstore of embeddings, using LangChain's vectorstore wrapper (with local embeddings or OpenAI's embeddings and FAISS vectorstore) to provide a mapping between documents and their corresponding embeddings, which can be used to retrieve the most relevant documents based on a similarity search using the embeddings.
Question-Answering has the following steps, all handled by ConversationalRetrievalChain:
- Given the chat history and new user input, determine what a standalone question would be (using GPT-3.5).
- 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.