This project is a chat application that uses a local FAISS vector store to answer questions about documents in the docs
directory.
mini_chat/
├── .env
├── .gitignore
├── cool-chatbot/
│ ├── .git/
│ └── arduino
├── docs/
│ ├── project_info.txt
│ └── sample.txt
├── faiss_index/
│ ├── index.faiss
│ └── index.pkl
├── README.md
├── setup_env.py
└── src/
├── api.py
├── chat.py
├── ingest.py
├── prompts/
│ └── qa.yaml
├── prompt_registry.py
├── __init__.py
└── __pycache__/
.env
: This file stores environment variables, including the OpenAI API key.cool-chatbot/
: This directory contains a Git repository and an Arduino project.docs/
: This directory contains the text files that the chat application will use to answer questions.faiss_index/
: This directory contains the FAISS index, which is a vector store that allows for efficient similarity search.setup_env.py
: This script creates the.env
file and checks if the OpenAI API key is set.src/
: This directory contains the source code for the chat application.
The chat application has two main components:
- Ingestion: The
ingest.py
script reads all the text files in thedocs
directory, creates a FAISS index from them, and saves the index to thefaiss_index
directory. This is done by using OpenAI'stext-embedding-3-small
model to create embeddings for each document. - Chat: The
chat.py
script uses the FAISS index to answer questions. When a user asks a question, the script first retrieves the most relevant documents from the index. Then, it uses thegpt-4o-mini
model to generate an answer based on the retrieved documents.
The api.py
script creates a FastAPI server that exposes a /chat
endpoint for handling user queries and a /
endpoint for serving the chat interface.
-
Set up the environment: Run the
setup_env.py
script to create the.env
file and check if the OpenAI API key is set. -
Ingest the documents: Run the
ingest.py
script to create the FAISS index. -
Start the chat server: Run the
api.py
script to start the chat server. -
Open the chat interface: Open a web browser and go to
http://localhost:8000
to open the chat interface.
This project includes a feature flag system to safely test experimental changes without breaking the stable demo.
Stable Mode (Default):
EXPERIMENTAL=0 python -m uvicorn src.api:app --reload --port 8000
# or simply:
python -m uvicorn src.api:app --reload --port 8000
Experimental Mode:
EXPERIMENTAL=1 python -m uvicorn src.api:app --reload --port 8000
The project includes a Makefile with convenient shortcuts:
# Start in stable mode
make start:stable
# Start in experimental mode
make start:exp
# Run smoke test against stable app
make smoke
# Run smoke test against experimental app
make smoke:exp
# Show all available commands
make help
Run smoke tests to verify the app is working correctly:
Bash (Linux/macOS):
./scripts/smoke.sh
PowerShell (Windows):
.\scripts\smoke.ps1
Using Make:
make smoke # Test stable mode
make smoke:exp # Test experimental mode
The smoke test:
- Waits for the app to start
- Checks the
/health
endpoint - Tests the root endpoint
- Reports success/failure
- Keep demo stable: Always run in stable mode for demos
- Test experimental: Use
EXPERIMENTAL=1
for testing new features - Verify with smoke: Run smoke tests before and after changes
- Toggle safely: Switch between modes without restarting
langchain
: This project uses thelangchain
library to create the FAISS index and to interact with the OpenAI API.fastapi
: This project uses thefastapi
library to create the chat server.uvicorn
: This project uses theuvicorn
library to run the chat server.faiss
: This project uses thefaiss
library to create the FAISS index.openai
: This project uses theopenai
library to interact with the OpenAI API.dotenv
: This project uses thedotenv
library to load environment variables from the.env
file.langgraph
: This project uses thelanggraph
library to create the chat graph.
The user can upgrade the agent to be more potent by:
- Using a different language model: The
chat.py
script uses thegpt-4o-mini
model by default. The user can change this to a different model by modifying thellm
variable in thechat.py
script. - Using a different vector store: The
ingest.py
script uses the FAISS vector store by default. The user can change this to a different vector store by modifying thebuild_index
function in theingest.py
script. - Using a different prompt: The
chat.py
script uses theqa
prompt by default. The user can change this to a different prompt by modifying theask
function in thechat.py
script. - Adding more documents: The user can add more documents to the
docs
directory to improve the chat application's knowledge base. - Improving the chat interface: The user can improve the chat interface by modifying the
chat_interface
function in theapi.py
script. - Adding more features: The user can add more features to the chat application, such as the ability to save chat history, by modifying the source code.
- Improving the Arduino project: The user can improve the Arduino project in the
cool-chatbot/
directory to add more features to the chat application.
To get started, please follow the instructions in the "How to use" section.