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

This commit is contained in:
2026-06-30 17:14:45 +03:00
parent 25b3afdfed
commit 2cf8df92ed
7 changed files with 343 additions and 52 deletions
+78 -22
View File
@@ -1,46 +1,102 @@
# FAQ Bot ChromaDB + LangChain
This project implements a simple FAQ bot that answers user questions based on a predefined FAQ dataset.
The bot uses **ChromaDB** for vector storage and **LangChain** as the single MCPtool to process queries.
This project implements a simple FAQ bot that uses **ChromaDB** for vector storage and **LangChain** as the single MCPtool to retrieve and generate answers.
The bot can ingest FAQ documents, store embeddings in ChromaDB, and answer user questions via a commandline interface.
## Features
- Persistent vector store (ChromaDB) data is saved to disk and reused across runs.
- Retrievalbased QA using LangChains `RetrievalQA` chain.
- Simple commandline interface.
- Unit tests covering vector store creation, bot answering, and unknownquestion handling.
- **Vector storage** ChromaDB (DuckDB + Parquet backend)
- **Embedding model** OpenAI embeddings (`text-embedding-3-small`)
- **LLM** OpenAI Chat (`gpt-4o-mini` by default)
- **MCPtool** LangChain (only one MCPtool used)
- **CLI** `python -m src.main ingest|ask`
- **Unit tests** `pytest`
## Setup
```bash
# Create a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
1. **Clone the repository**
# Install dependencies
pip install -r requirements.txt
```
```bash
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-faq-bot-chromadb-odin-.git
cd povtornyy-ekzamen-faq-bot-chromadb-odin-
```
2. **Create a virtual environment**
```bash
python3 -m venv .venv
source .venv/bin/activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Set OpenAI API key**
```bash
export OPENAI_API_KEY="sk-..."
```
## Usage
```bash
python src/main.py
### Ingest FAQ file
Prepare a text file with FAQ pairs in the following format:
```
Q: What is Python?
A: Python is a programming language.
Q: What is ChromaDB?
A: ChromaDB is a vector database.
```
You will be prompted to type a question. The bot will reply with the best answer from the FAQ dataset.
Run:
## Running Tests
```bash
python -m src.main ingest path/to/faq.txt --collection faq_collection
```
### Ask a question
```bash
python -m src.main ask "What is Python?" --collection faq_collection
```
The bot will print the generated answer.
## Testing
Run the test suite:
```bash
pytest
```
All tests should pass.
## Project Structure
## FAQ Dataset
```
src/
├── main.py # CLI entry point
├── ingest.py # Ingestion logic
└── retriever.py # Retrieval & answer generation
tests/
├── test_ingest.py
└── test_retrieval.py
requirements.txt
README.md
```
The dataset is embedded in the code (3 entries). Feel free to extend it in `src/vector_store.py`.
## Notes
## License
- The bot uses the default OpenAI embeddings and LLM.
If you want to change the model, edit the `OpenAIEmbeddings()` and `OpenAIChat()` calls in `src/ingest.py` and `src/retriever.py`.
- ChromaDB data is persisted in the `chromadb/` directory relative to the project root.
- The deadline for the assignment is **31.08.2026**. All code is committed to the specified Git repository.
MIT License
---
Happy coding!