feat: solution for 'Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool'
This commit is contained in:
@@ -1,42 +1,85 @@
|
||||
# FAQ Bot – ChromaDB + MCP-tool
|
||||
|
||||
This project implements a simple FAQ bot that uses **ChromaDB** as the sole vector store and a single **Minimal Context‑Aware Prompt (MCP) tool** for prompt generation.
|
||||
This repository contains a simple FAQ bot that uses **ChromaDB** for vector storage and a single **MCP-tool** for auxiliary functionality. The bot answers user questions by retrieving relevant FAQ documents and generating responses with OpenAI’s LLM.
|
||||
|
||||
## Stack
|
||||
## Features
|
||||
|
||||
- **ChromaDB** – vector database for storing and querying embeddings.
|
||||
- **MCP-tool** – a lightweight function that creates a prompt from a user question.
|
||||
- **Node.js** – runtime environment.
|
||||
- **readline-sync** – simple CLI input.
|
||||
- **Vector search** with ChromaDB (persisted locally).
|
||||
- **OpenAI embeddings** (`text-embedding-ada-002`) for document indexing.
|
||||
- **OpenAI function calling** to invoke a single MCP-tool (`get_current_utc_time`).
|
||||
- Interactive command‑line interface.
|
||||
|
||||
## How it works
|
||||
## Setup
|
||||
|
||||
1. **Vector Store**
|
||||
- `src/vectorStore.js` wraps ChromaDB.
|
||||
- Documents are embedded using a deterministic 768‑dimensional vector derived from word hashes.
|
||||
- The collection is created (or fetched) on startup.
|
||||
1. **Clone the repository**
|
||||
|
||||
2. **MCP-tool**
|
||||
- `src/bot.js` contains `generatePrompt` which formats the user question into a prompt.
|
||||
- The prompt is embedded and queried against the vector store.
|
||||
```bash
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-faq-bot-chromadb-odin.git
|
||||
cd povtornyy-ekzamen-faq-bot-chromadb-odin
|
||||
```
|
||||
|
||||
3. **Bot Loop**
|
||||
- `src/index.js` loads a small FAQ dataset, populates the collection, and starts a REPL loop.
|
||||
- User input is processed, the best matching FAQ answer is returned.
|
||||
2. **Create a virtual environment**
|
||||
|
||||
## Running the bot
|
||||
```bash
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
||||
```
|
||||
|
||||
3. **Install dependencies**
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
4. **Set environment variables**
|
||||
|
||||
Create a `.env` file in the project root:
|
||||
|
||||
```dotenv
|
||||
OPENAI_API_KEY=your_openai_api_key
|
||||
FAQ_FILE=data/faq.jsonl # optional, defaults to data/faq.jsonl
|
||||
```
|
||||
|
||||
5. **Prepare FAQ data**
|
||||
|
||||
Place your FAQ documents in `data/faq.jsonl`. Each line should be a JSON object:
|
||||
|
||||
```json
|
||||
{"id": "1", "text": "What is ChromaDB?", "metadata": {"category": "database"}}
|
||||
{"id": "2", "text": "How to use the MCP-tool?", "metadata": {"category": "tool"}}
|
||||
```
|
||||
|
||||
If the file is missing, the bot will start without pre‑loaded documents.
|
||||
|
||||
## Running the Bot
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm start
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
Type a question and press Enter. Type `exit` to quit.
|
||||
You will see:
|
||||
|
||||
## Notes
|
||||
```
|
||||
FAQ Bot (ChromaDB + MCP-tool). Type 'exit' to quit.
|
||||
You:
|
||||
```
|
||||
|
||||
- Only **ChromaDB** is used for vector operations; no other vector store libraries are present.
|
||||
- Only **one MCP-tool** (`generatePrompt`) is integrated.
|
||||
- The code is fully self‑contained and can be extended with real embeddings or a larger dataset.
|
||||
Type a question, e.g.:
|
||||
|
||||
---
|
||||
```
|
||||
You: What is the current time?
|
||||
```
|
||||
|
||||
The bot may invoke the MCP-tool and return the current UTC time.
|
||||
|
||||
## Testing
|
||||
|
||||
The repository includes no automated tests, but you can manually verify:
|
||||
|
||||
- The bot can answer FAQ questions.
|
||||
- The MCP-tool is invoked when the model requests it.
|
||||
- ChromaDB persists data between runs (check the `chromadb/` directory).
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
Reference in New Issue
Block a user