133 lines
3.3 KiB
Markdown
133 lines
3.3 KiB
Markdown
# FAQ Bot – ChromaDB + Ollama
|
||
|
||
This project implements a simple FAQ bot that answers user queries using a vector store backed by **ChromaDB** and embeddings generated by **Ollama**. The bot is orchestrated with **LangChain** and includes a small tool that returns the current system time.
|
||
|
||
## Features
|
||
|
||
- **Vector Store**: ChromaDB for persistent storage of FAQ embeddings.
|
||
- **Embeddings**: Generated with Ollama (e.g., `llama3`).
|
||
- **LLM**: Ollama LLM for generating responses.
|
||
- **RetrievalQA**: LangChain chain that retrieves relevant FAQ answers.
|
||
- **MCP‑Tool**: A single tool that returns the current time when the user asks about time or date.
|
||
- **CLI**: Simple command‑line interface to ask questions or ingest data.
|
||
- **Web API**: FastAPI endpoint (`POST /ask`) for programmatic access.
|
||
|
||
## Prerequisites
|
||
|
||
- Python 3.10+
|
||
- Docker (optional, for running Ollama locally)
|
||
- Ollama server running locally (default port 11434)
|
||
|
||
## Installation
|
||
|
||
```bash
|
||
# Clone the repository
|
||
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-faq-bot-chromadb-odin.git
|
||
cd povtornyy-ekzamen-faq-bot-chromadb-odin
|
||
|
||
# Create a virtual environment
|
||
python -m venv .venv
|
||
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
|
||
|
||
# Install dependencies
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
## Environment Variables
|
||
|
||
Create a `.env` file in the project root (a template is provided):
|
||
|
||
```
|
||
OLLAMA_MODEL=llama3
|
||
CHROMA_DB_PATH=./chromadb
|
||
```
|
||
|
||
- `OLLAMA_MODEL`: Name of the Ollama model to use (e.g., `llama3`).
|
||
- `CHROMA_DB_PATH`: Directory where ChromaDB will store its data.
|
||
|
||
## FAQ Data
|
||
|
||
Place your FAQ data in `data/faq.csv`. The file must contain two columns:
|
||
|
||
| question | answer |
|
||
|----------|--------|
|
||
|
||
A sample file is included in the repository.
|
||
|
||
## Usage
|
||
|
||
### CLI
|
||
|
||
```bash
|
||
# Ingest FAQ data (if not already ingested)
|
||
python -m src.main ask "What is the return policy?" --init
|
||
|
||
# Ask a question
|
||
python -m src.main ask "How do I track my order?"
|
||
```
|
||
|
||
The `--init` flag forces re‑ingestion of the FAQ data. If the vector store is empty, it will be ingested automatically.
|
||
|
||
### Web API
|
||
|
||
```bash
|
||
# Start the server
|
||
python -m src.main serve
|
||
|
||
# Send a request
|
||
curl -X POST http://localhost:8000/ask \
|
||
-H "Content-Type: application/json" \
|
||
-d '{"question":"What payment methods are accepted?"}'
|
||
```
|
||
|
||
The response will be a JSON object:
|
||
|
||
```json
|
||
{
|
||
"answer": "We accept credit cards, debit cards, and PayPal."
|
||
}
|
||
```
|
||
|
||
### Adding New FAQ Entries
|
||
|
||
1. Append new rows to `data/faq.csv`.
|
||
2. Re‑index the vector store:
|
||
|
||
```bash
|
||
python -m src.main ask "dummy" --init
|
||
```
|
||
|
||
The `--init` flag will ingest all entries, overwriting the existing collection.
|
||
|
||
## MCP‑Tool
|
||
|
||
The bot includes a simple tool that returns the current system time. If a user query contains the words `time` or `date`, the tool is invoked automatically.
|
||
|
||
Example:
|
||
|
||
```bash
|
||
python -m src.main ask "What time is it?"
|
||
```
|
||
|
||
Output:
|
||
|
||
```
|
||
Answer: 2026-08-01 14:32:07
|
||
```
|
||
|
||
## Development
|
||
|
||
- **Testing**: Run the CLI or API locally to verify functionality.
|
||
- **Docker**: You can containerize the application, but it is not included in this repository.
|
||
|
||
## Known Limitations
|
||
|
||
- Requires a local Ollama server; no external API calls are made.
|
||
- ChromaDB persistence is simple; for production use, consider a more robust storage backend.
|
||
- The MCP‑tool is minimal; replace or extend it as needed.
|
||
|
||
## License
|
||
|
||
MIT License
|
||
---
|
||
Happy coding! |