FAQ Bot – ChromaDB + MCP-style Tool
This project implements a simple FAQ bot that answers questions about a machine learning course.
The bot uses:
- ChromaDB to store and retrieve FAQ documents.
- Ollama embeddings (
nomic-embed-text) for vectorization. - LangChain to build an agent that routes queries to the appropriate tool.
- MCP-style HTTP tool (
fetch_course_meta) that returns course metadata from a local JSON file.
Project Structure
.
├── chroma_faq/ # Persisted Chroma vector store
├── data/
│ ├── faq1.md
│ ├── faq2.md
│ ├── faq3.md
│ └── course_meta.json
├── src/
│ ├── __init__.py
│ ├── agent.py
│ ├── cli.py
│ ├── main.py
│ └── tools.py
├── requirements.txt
└── README.md
Setup
-
Install Ollama
Download and install Ollama from https://ollama.ai/.
Pull the required models:ollama pull nomic-embed-text ollama pull llama3 -
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install Python dependencies:
pip install -r requirements.txt
Running the Bot
Preset Questions
Run the script without arguments to execute three preset questions (two for the FAQ tool, one for the metadata tool):
python -m src.main
You should see output similar to:
Running preset questions:
Q1: What is the deadline for Assignment 1?
A1: The deadline for Assignment 1 is August 31, 2026. source: chroma
Q2: How many lectures are there in the course?
A2: There are 12 lectures in the course. source: chroma
Q3: What is the course schedule for next week?
A3: The course schedule for next week is:
- 2026-09-01: Lecture 1 – Introduction to ML (Room 101)
- 2026-09-08: Lecture 2 – Data Preprocessing (Room 102)
- 2026-09-15: Lecture 3 – Linear Regression (Room 103)
source: mcp_meta
Interactive Mode
Start an interactive session:
python -m src.main --interactive
You can type any question, and the bot will answer using the appropriate tool. Type exit or Ctrl+C to quit.
How It Works
-
Data Loading
src/tools.pycontainsload_faq_to_chroma()which reads all.mdfiles indata/, chunks them, embeds them withnomic-embed-text, and persists the vector store inchroma_faq/. -
Tools
search_course_docs(query, k)– searches the Chroma vector store for relevant FAQ snippets.fetch_course_meta(query)– readsdata/course_meta.jsonand returns schedule or instructor information based on the query.
-
Agent
src/agent.pybuilds a LangChain agent that:- Uses a system prompt to decide which tool to call.
- Adds a
source:tag to the final answer indicating whether the answer came from the FAQ (chroma) or the metadata tool (mcp_meta).
-
CLI
src/cli.pyprovides a simple command‑line interface to run preset questions or an interactive session.
Extending the Bot
- Add more FAQ documents – Place additional
.mdfiles indata/and re‑run the script to rebuild the vector store. - Add more metadata – Update
data/course_meta.jsonor modifyfetch_course_metato call a real HTTP endpoint. - Change the LLM – Replace
Ollamawith another LLM provider insrc/agent.py.
License
This project is provided as-is for educational purposes. Feel free to adapt and extend it for your own use cases.