feat: solution for 'Практическое задание: Агент с RAG-памятью'

This commit is contained in:
2026-05-28 17:55:09 +03:00
parent 5d01ac1d8b
commit 61d5771c9b
11 changed files with 208 additions and 283 deletions
+21 -88
View File
@@ -1,93 +1,26 @@
```markdown
# RAG Agent with Qdrant and Ollama
# Практическое задание: Агент с RAG-памятью
This project implements an AI agent that can search and add documents to a local knowledge base using **Qdrant** for vector storage and **Ollama** for embeddings and LLM inference. The agent is built with **LangChain** and exposes two tools:
Главная
Мои задания
Агент с RAG-памятью
EN
Агент с RAG-памятью
- `search_knowledge_base(query, max_results)` semantic search in the knowledge base.
- `add_to_knowledge_base(content, title)` add a new document to the knowledge base.
Практическое задание: Агент с RAG-памятью
Цель
## Features
Построить AI-агента с локальным RAG-хранилищем знаний на базе Qdrant и Ollama. Агент должен уметь искать и сохранять информацию в векторной базе.
- **Vector store**: Qdrant with Ollama embeddings (`nomic-embed-text`).
- **Chunking**: Recursive character splitter with overlap.
- **Agent**: Zero-shot React agent that uses the two tools.
- **CLI**: Interactive command line interface to add documents and query the agent.
- **Batch loading**: Script to load all text files from a directory into the knowledge base.
Стек
Python 3.10+
Qdrant — векторная база данных
Ollama — локальные LLM и эмбеддинги (llama3, nomic-embed-text)
LangChain — фреймворк для агентов и RAG
Установка
# Ollama
ollama pull llama3
ollama pull nomic-embed-text
## Prerequisites
- Python 3.10+
- Docker (for Qdrant) or a running Qdrant instance.
- Ollama installed locally with the following models:
```bash
ollama pull llama3
ollama pull nomic-embed-text
```
## Setup
```bash
# Clone the repository
git clone https://github.com/your-username/rag-agent.git
cd rag-agent
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Start Qdrant (Docker example)
docker run -p 6333:6333 qdrant/qdrant
```
## Usage
### 1. Load documents into the knowledge base
```bash
python src/main.py /path/to/documents
```
Supported file types: `.txt`, `.md`. (PDF support can be added with an additional parser.)
### 2. Start the interactive CLI
```bash
python src/cli.py
```
Commands:
- `/add <file_path>` Add a single document.
- `/search <query>` Query the agent.
- `/quit` Exit.
### 3. Example
```bash
> /add example.txt
Document 'example' added to knowledge base with 3 chunks.
> /search What is the capital of France?
1. The capital of France is Paris. (Title: example)
```
## Project Structure
```
rag-agent/
├── src/
│ ├── agent.py
│ ├── cli.py
│ ├── main.py
│ ├── tools.py
│ └── vector_store.py
├── requirements.txt
└── README.md
```
## License
MIT License
```
# Python пакеты
pi