feat: solution for 'Агент с RAG-памятью'
CI / build (push) Has been cancelled

This commit is contained in:
2026-07-01 14:05:59 +03:00
parent bd49075b6e
commit 39d55136ad
14 changed files with 332 additions and 406 deletions
+38 -32
View File
@@ -1,41 +1,39 @@
# Agent with RAG Memory using Qdrant and Ollama
# RAG Agent with Ollama Embeddings and Qdrant
This project demonstrates a simple Retrieval-Augmented Generation (RAG) agent built with LangChain, Qdrant, and Ollama. The agent uses Ollama embeddings for vector representation and Qdrant as the vector store.
This project implements a Retrieval-Augmented Generation (RAG) agent that uses:
- **OllamaEmbeddings** from `langchain-community` for local embeddings.
- **Qdrant** as the vector store for efficient similarity search.
- **OpenAI LLM** for generating responses.
## Prerequisites
- Python 3.10+
- Qdrant server running locally or accessible remotely
- Ollama server running locally or accessible remotely
- A running local Ollama instance (default: `http://localhost:11434`).
- A running local Qdrant instance (default: `http://localhost:6333`).
- An OpenAI API key for the LLM.
## Installation
## Setup
```bash
# Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/agent-s-rag-pamyatyu.git
cd agent-s-rag-pamyatyu
# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows use .venv\\Scripts\\activate
# Install dependencies
pip install -r requirements.txt
# or using Poetry
# poetry install
```
## Configuration
Create a `.env` file in the project root with your OpenAI key:
Edit `config.py` to match your environment:
```python
# Qdrant settings
QDRANT_HOST = "localhost"
QDRANT_PORT = 6333
QDRANT_API_KEY = None
QDRANT_COLLECTION = "rag_collection"
# Ollama settings
OLLAMA_MODEL = "llama3"
```
OPENAI_API_KEY=sk-...
```
## Running the Agent
@@ -44,21 +42,29 @@ OLLAMA_MODEL = "llama3"
python src/main.py
```
The script will:
You can then interact with the agent in the console. Type `exit` or `quit` to stop.
1. Connect to Qdrant.
2. Create an Ollama embeddings instance.
3. Add sample documents to the collection if it is empty.
4. Build a RetrievalQA chain using the Ollama LLM.
5. Execute a sample query and print the answer.
## Adding Documents
## Extending
The agent automatically creates a Qdrant collection named `rag_collection`. To add documents, you can extend the `vector_store.py` module or use the Qdrant client directly. For example:
- Replace the sample documents with your own corpus.
- Adjust the `chain_type` in `src/agent.py` if you need a different retrieval strategy.
- Use environment variables or a `.env` file to store sensitive information like `QDRANT_API_KEY`.
```python
from vector_store import get_vector_store
vs = get_vector_store()
vs.add_texts(["Hello world", "Another document"])
```
## Testing
The project includes a minimal test suite (not shown here). To run tests:
```bash
pytest
```
Ensure that your local Ollama and Qdrant instances are running before executing tests.
## License
MIT License
---
MIT License