feat: solution for 'Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool'
This commit is contained in:
@@ -1,92 +1,87 @@
|
||||
# FAQ Bot – ChromaDB + Ollama
|
||||
|
||||
This project implements a simple FAQ bot that uses **ChromaDB** as the vector store and **Ollama** for embeddings and language generation.
|
||||
The bot is built with **LangChain** and relies on a single **MCPTool** to retrieve relevant documents and generate answers.
|
||||
This repository contains a simple FAQ chatbot that uses:
|
||||
|
||||
- **Ollama** for embeddings (`nomic-embed-text`) and text generation.
|
||||
- **ChromaDB** as the vector store.
|
||||
- **LangChain** to orchestrate the retrieval and generation pipeline.
|
||||
|
||||
## Features
|
||||
|
||||
- **Embeddings**: Uses the `nomic-embed-text` model from Ollama.
|
||||
- **Vector Store**: Stores embeddings in a persistent ChromaDB collection.
|
||||
- **LLM**: Generates answers with the `llama3` model from Ollama.
|
||||
- **MCPTool**: A single tool that handles retrieval and generation in one step.
|
||||
- **CLI**: Interactive command‑line interface for quick testing.
|
||||
- Loads a small set of FAQ questions and answers.
|
||||
- Generates embeddings with the `nomic-embed-text` model.
|
||||
- Stores embeddings in a persistent ChromaDB collection.
|
||||
- Retrieves the most relevant answer to a user query.
|
||||
- Generates a natural language response using an Ollama LLM.
|
||||
|
||||
## Setup
|
||||
## Requirements
|
||||
|
||||
- Python 3.10+
|
||||
- Ollama server running locally (default port 11434).
|
||||
Install from https://ollama.ai/ and pull the required models:
|
||||
```bash
|
||||
ollama pull nomic-embed-text
|
||||
ollama pull llama3 # or any other generation model you prefer
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-faq-bot-chromadb-odin.git
|
||||
cd povtornyy-ekzamen-faq-bot-chromadb-odin
|
||||
git clone https://github.com/your-username/faq-bot.git
|
||||
cd faq-bot
|
||||
|
||||
# Create a virtual environment (optional but recommended)
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # On Windows: .venv\\Scripts\\activate
|
||||
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
||||
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Data
|
||||
|
||||
Place your FAQ documents as plain text files (`*.txt`) in the `data/` directory.
|
||||
Each file will be loaded, embedded, and stored in ChromaDB.
|
||||
|
||||
## Running the Bot
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
python -m src.main
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
You will see a prompt:
|
||||
|
||||
```
|
||||
FAQ Bot powered by ChromaDB and Ollama.
|
||||
Type 'exit' to quit.
|
||||
|
||||
Your question:
|
||||
FAQ Bot is ready. Type your question (or 'exit' to quit).
|
||||
```
|
||||
|
||||
Type a question and press Enter. The bot will return an answer.
|
||||
|
||||
## Testing
|
||||
|
||||
Run the unit tests to verify that the bot uses the correct components:
|
||||
|
||||
```bash
|
||||
python -m unittest discover -s tests
|
||||
```
|
||||
|
||||
All tests should pass, confirming that:
|
||||
|
||||
- The embeddings are from `OllamaEmbeddings`.
|
||||
- The vector store is a `Chroma` instance.
|
||||
- No OpenAI modules are imported.
|
||||
- Answers are returned as strings.
|
||||
Type any of the predefined FAQ questions or any other question, and the bot will respond with the most relevant answer.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
├── data/ # FAQ documents (plain text)
|
||||
├── chroma_db/ # Persisted ChromaDB collection
|
||||
faq-bot/
|
||||
├── src/
|
||||
│ └── main.py # Bot implementation
|
||||
├── tests/
|
||||
│ └── test_main.py # Unit tests
|
||||
├── requirements.txt
|
||||
└── README.md
|
||||
│ └── main.py # Main application script
|
||||
├── requirements.txt # Python dependencies
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## Notes
|
||||
## Customizing the FAQ
|
||||
|
||||
- The bot requires an Ollama server running locally.
|
||||
Ensure that the `nomic-embed-text` and `llama3` models are available:
|
||||
The FAQ data is currently hard‑coded in `src/main.py`. To add more questions:
|
||||
|
||||
```bash
|
||||
ollama pull nomic-embed-text
|
||||
ollama pull llama3
|
||||
```
|
||||
1. Open `src/main.py`.
|
||||
2. Edit the `faq_pairs` list inside the `load_faq_data()` function.
|
||||
3. Restart the bot.
|
||||
|
||||
- The vector store is persisted in the `chroma_db/` directory.
|
||||
If you add new documents, delete this folder and rerun the bot to rebuild the index.
|
||||
## Persistence
|
||||
|
||||
Enjoy building your FAQ bot!
|
||||
The vector store is persisted in the `chroma_db/` directory. The next time you run the bot, it will reuse the existing embeddings instead of recomputing them.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- **Ollama not found**: Ensure the Ollama server is running and accessible at `http://localhost:11434`.
|
||||
- **Embedding errors**: Verify that the `nomic-embed-text` model is pulled (`ollama list`).
|
||||
- **Vector store errors**: Delete the `chroma_db/` directory if you suspect corruption.
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
---
|
||||
Reference in New Issue
Block a user