Files
povtornyy-ekzamen-faq-bot-c…/README.md
T

88 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# FAQ Bot with Qdrant Vector Store
This project implements a simple FAQ chatbot that uses **Qdrant** as the vector store for embeddings.
The bot loads a set of FAQ entries, generates embeddings with OpenAIs `text-embedding-ada-002` model, stores them in Qdrant, and answers user queries by performing a similarity search.
## Prerequisites
- Python 3.9+
- A running Qdrant instance (local or remote)
- An OpenAI API key
## Setup
1. **Clone the repository**
```bash
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-faq-bot-qdrant.git
cd povtornyy-ekzamen-faq-bot-qdrant
```
2. **Create a virtual environment and install dependencies**
```bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
```
3. **Configure environment variables**
Create a `.env` file in the project root with the following content:
```dotenv
# Qdrant configuration
QDRANT_HOST=localhost
QDRANT_PORT=6333
QDRANT_API_KEY= # leave empty if no API key is required
# OpenAI configuration
OPENAI_API_KEY=your_openai_api_key_here
```
Replace `your_openai_api_key_here` with your actual OpenAI API key.
4. **Run the bot**
```bash
python src/main.py
```
The bot will ingest the FAQ data into Qdrant and then wait for user input. Type a question and press Enter to receive an answer. Type `exit` or `quit` to stop the bot.
## How It Works
1. **Embedding Generation**
The bot uses OpenAIs `text-embedding-ada-002` to convert each FAQ question into a 1536dimensional vector.
2. **Vector Store**
Qdrant stores these vectors in a collection named `faq_collection`. Each point contains the vector and a payload with the original question and answer.
3. **Querying**
When a user asks a question, the bot generates an embedding for the query, performs a cosine similarity search in Qdrant, and returns the answer from the most similar FAQ entry.
## Customization
- **Adding More FAQs**
Edit the `FAQ_DATA` list in `src/main.py` to include additional question/answer pairs.
- **Changing the Embedding Model**
Replace `"text-embedding-ada-002"` in `get_embedding()` with another OpenAI embedding model if desired.
- **Adjusting Search Parameters**
Modify `top_k` in `query_faq()` to return more results or change the similarity metric in `create_or_recreate_collection()`.
## Troubleshooting
- **Qdrant Connection Errors**
Ensure Qdrant is running and reachable at the host/port specified in the `.env` file.
- **OpenAI Rate Limits**
If you hit rate limits, consider adding retry logic or using a different model.
- **Missing Dependencies**
Run `pip install -r requirements.txt` again to ensure all packages are installed.
## License
This project is provided for educational purposes and is not licensed for commercial use.