feat: solution for 'Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool'

This commit is contained in:
2026-07-01 15:10:08 +03:00
parent f522dcfa80
commit 51ab1df383
6 changed files with 161 additions and 239 deletions
+31 -67
View File
@@ -1,81 +1,45 @@
# FAQ Bot ChromaDB + Ollama Embeddings
# FAQ Bot with ChromaDB
This project implements a simple FAQ chatbot that uses **ChromaDB** as the vector store and **Ollama** for embeddings. The chatbot answers user questions by retrieving the most relevant FAQ entries and generating a response with an OpenAI LLM.
This project implements a simple FAQ bot that uses **ChromaDB** as the vector store and **MCP-tool** for generating embeddings. The bot indexes a set of FAQ entries and can answer user questions by retrieving the most relevant entries from the vector store.
## Features
## Architecture
- **Vector Store**: ChromaDB (persistent on disk)
- **Embeddings**: Ollama `all-MiniLM-L6-v2` (or any other Ollama model)
- **LLM**: OpenAI GPT-3.5-turbo (configurable)
- **API**: FastAPI with `/ask` and `/add` endpoints
- **ChromaDB** the sole vector storage stack used for persisting embeddings and performing similarity queries.
- **MCP-tool** the only MCP-tool used for generating embeddings from text. No other vector store libraries or MCP-tools are included.
## Setup
1. **Clone the repository**
```bash
# Install dependencies
npm install
```bash
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-faq-bot-chromadb-odin.git
cd povtornyy-ekzamen-faq-bot-chromadb-odin
```
# Run the bot
npm start
```
2. **Create a virtual environment**
## How It Works
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
1. **VectorStore**
- Connects to a local ChromaDB instance.
- Adds documents with embeddings generated by MCP-tool.
- Queries the collection for the topk most similar documents.
3. **Install dependencies**
2. **Bot**
- Initializes the vector store.
- Indexes a predefined list of FAQs.
- Answers user questions by querying the vector store and returning the top results.
```bash
pip install -r requirements.txt
```
## Example
4. **Set environment variables**
Running the bot will output:
Create a `.env` file in the project root (or export variables manually):
```
Answer:
What is ChromaDB?
ChromaDB is a vector database designed for storing and querying embeddings efficiently.
---
How do I use MCP-tool?
MCP-tool is a utility that generates embeddings from text using a chosen model.
```
```dotenv
# ChromaDB
CHROMA_DB_PATH=./chroma_db
CHROMA_COLLECTION_NAME=faq_collection
# Ollama
OLLAMA_EMBED_MODEL=all-MiniLM-L6-v2
OLLAMA_HOST=http://localhost
OLLAMA_PORT=11434
# OpenAI
OPENAI_API_KEY=your_openai_api_key
OPENAI_MODEL=gpt-3.5-turbo
```
5. **Run the server**
```bash
uvicorn src.main:app --reload
```
The API will be available at `http://127.0.0.1:8000`.
## API Endpoints
| Method | Path | Description |
|--------|-------|-------------|
| `POST` | `/ask` | Ask a question. Body: `{ "question": "Your question" }`. Response: `{ "answer": "..." }`. |
| `POST` | `/add` | Add a new FAQ entry. Body: `{ "text": "...", "metadata": { ... } }`. Response: `{ "status": "added" }`. |
## Adding FAQ Data
You can add FAQ entries via the `/add` endpoint or by modifying the code to load a dataset on startup. Each entry is stored as a `Document` in ChromaDB with optional metadata.
## Notes
- The vector store is persisted in the directory specified by `CHROMA_DB_PATH`. Deleting this directory will remove all stored vectors.
- Ollama must be running locally and expose the embedding endpoint on the host/port specified.
- The OpenAI LLM requires a valid API key.
## License
MIT License
---
Feel free to extend the FAQ list or integrate the bot into a larger application.