102 lines
2.3 KiB
Markdown
102 lines
2.3 KiB
Markdown
# FAQ Bot – ChromaDB + LangChain
|
||
|
||
This project implements a simple FAQ bot that uses **ChromaDB** for vector storage and **LangChain** as the single MCP‑tool to retrieve and generate answers.
|
||
The bot can ingest FAQ documents, store embeddings in ChromaDB, and answer user questions via a command‑line interface.
|
||
|
||
## Features
|
||
|
||
- **Vector storage** – ChromaDB (DuckDB + Parquet backend)
|
||
- **Embedding model** – OpenAI embeddings (`text-embedding-3-small`)
|
||
- **LLM** – OpenAI Chat (`gpt-4o-mini` by default)
|
||
- **MCP‑tool** – LangChain (only one MCP‑tool used)
|
||
- **CLI** – `python -m src.main ingest|ask`
|
||
- **Unit tests** – `pytest`
|
||
|
||
## Setup
|
||
|
||
1. **Clone the repository**
|
||
|
||
```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
|
||
|
||
### 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.
|
||
```
|
||
|
||
Run:
|
||
|
||
```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
|
||
```
|
||
|
||
## Project Structure
|
||
|
||
```
|
||
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
|
||
```
|
||
|
||
## Notes
|
||
|
||
- 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.
|
||
|
||
---
|
||
|
||
Happy coding! |