feat: solution for 'Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool'
This commit is contained in:
@@ -1,71 +1,42 @@
|
||||
# FAQ Bot – ChromaDB + MCP-tool
|
||||
|
||||
This repository contains a lightweight FAQ bot that uses **ChromaDB** as the vector store and a single **MCP-tool** for generating embeddings.
|
||||
The bot loads FAQ documents, stores them in ChromaDB, and answers user questions by retrieving the most relevant documents.
|
||||
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.
|
||||
|
||||
## Features
|
||||
## Stack
|
||||
|
||||
- **Single vector store stack** – ChromaDB
|
||||
- **One MCP-tool** for embeddings (OpenAI or deterministic fallback)
|
||||
- Interactive command‑line interface
|
||||
- Easy to add new FAQ documents
|
||||
- **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.
|
||||
|
||||
## Requirements
|
||||
## How it works
|
||||
|
||||
- Python 3.10+
|
||||
- An OpenAI API key (optional – a deterministic dummy embedding is used if not provided)
|
||||
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.
|
||||
|
||||
## Installation
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## Running the bot
|
||||
|
||||
```bash
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-faq-bot-chromadb-odin.git
|
||||
cd povtornyy-ekzamen-faq-bot-chromadb-odin
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
||||
pip install -r requirements.txt
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
## Configuration
|
||||
Type a question and press Enter. Type `exit` to quit.
|
||||
|
||||
Create a `.env` file in the project root with your OpenAI key:
|
||||
## Notes
|
||||
|
||||
```
|
||||
OPENAI_API_KEY=sk-...
|
||||
```
|
||||
- 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.
|
||||
|
||||
If the key is missing, the bot will use a deterministic dummy embedding.
|
||||
|
||||
## Usage
|
||||
|
||||
Place your FAQ documents as plain text files in the `data/` directory (one file per FAQ).
|
||||
|
||||
```bash
|
||||
python src/faq_bot.py
|
||||
```
|
||||
|
||||
You will see a prompt:
|
||||
|
||||
```
|
||||
FAQ Bot is ready. Type your question (or 'exit' to quit).
|
||||
Q:
|
||||
```
|
||||
|
||||
Type a question and press Enter. The bot will display the top 3 most relevant answers.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
src/
|
||||
├── faq_bot.py # Main entry point
|
||||
├── vector_store.py # Wrapper around ChromaDB
|
||||
└── mcp_tool.py # Embedding generation
|
||||
```
|
||||
|
||||
## Extending
|
||||
|
||||
- **Adding new documents** – drop new `.txt` files into `data/` and restart the bot.
|
||||
- **Changing the embedding model** – modify `mcp_tool.get_embedding` to use a different provider.
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
---
|
||||
Reference in New Issue
Block a user