From ae375390853b8d64ab3d5408f8024d02086839ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Thu, 28 May 2026 09:27:58 +0000 Subject: [PATCH] add README.md --- README.md | 78 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 4a3e5fa..7b4c38b 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,52 @@ -# Агент с RAG‑памятью +# RAG Agent with ChromaDB -## Что делает проект -Реализован AI‑агент, использующий локальное векторное хранилище ChromaDB и Ollama для эмбеддингов. Агент умеет добавлять документы (разбивая их на чанки) и выполнять семантический поиск. +## Overview +This repository implements a simple RAG (Retrieval‑Augmented Generation) agent that uses **ChromaDB** as the vector store and **Ollama** for embeddings and LLM inference. The agent can: -## Структура файлов -| Файл | Назначение | -|------|------------| -| `main.py` | Точка входа, демонстрация работы агента. | -| `requirements.txt` | Пакеты‑зависимости. | -| `README.md` | Это описание. | -| `chunker.py` | Разбиение текста на чанки (500/100). | -| `vector_store.py` | Работа с ChromaDB: добавление и поиск. | -| `tools.py` | Декорированные инструменты RAG‑агента. | -| `agent.py` | Создание агента через `create_agent`. | -| `cli.py` | CLI для интерактивного теста. | -| `init_documents.py` | Скрипт загрузки всех файлов из каталога в базу. | +1. Add documents to the knowledge base. +2. Search the knowledge base semantically. +3. Interact via a lightweight CLI. -## Установка +## File Structure +- `requirements.txt` – Python dependencies. +- `chunker.py` – Text chunking utilities (RecursiveCharacterTextSplitter). +- `vector_store.py` – Wrapper around ChromaDB collection. +- `tools.py` – LangChain tools for search and add operations. +- `agent.py` – Agent creation with LangChain `create_agent`. +- `cli.py` – Simple command‑line interface. +- `init_documents.py` – Helper to load all `.txt` files from a directory into the vector store. + +## Installation ```bash +# Pull Ollama models +ollama pull llama3 +ollama pull nomic-embed-text + +# Install Python packages pip install -r requirements.txt -# Ollama: pull nomic-embed-text (для эмбеддингов) ``` -## Примеры использования -```bash -python cli.py add path/to/file.txt # Добавить документ -python cli.py search "Python" # Поиск по базе -``` +## Usage +1. **Load documents** (optional): + ```bash + python init_documents.py + ``` +2. **Run the CLI**: + ```bash + python cli.py + ``` + Type any question or `/quit` to exit. -## Архитектура -1. **LLM** – `ChatOpenAI` через BroJS, но для эмбеддингов используется Ollama. -2. **Embeddings** – `OllamaEmbeddings(model="nomic-embed-text")`. -3. **Vector store** – ChromaDB коллекция «rag_collection» в папке chromadb. -4. **Chunking** – `RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=100)`. -5. **Tools** – `search_knowledge_base`, `add_to_knowledge_base` с декоратором `@tool`. -6. **Agent** – `create_agent` с системным промптом и доступом к инструментам. -7. **CLI** – простая команда‑интерфейс для добавления/поиска. ---- +## Architecture +- **Chunking**: `chunker.split_text()` splits large texts into 500‑char chunks with 100‑char overlap using LangChain’s `RecursiveCharacterTextSplitter`. +- **Vector Store**: `vector_store.ChromaVectorStore` handles adding documents and similarity search. Embeddings are generated by `langchain_ollama.OllamaEmbeddings` (`nomic-embed-text`). +- **Tools**: Two tools decorated with `@tool`: `search_knowledge_base` and `add_to_knowledge_base`. They interact with the vector store. +- **Agent**: Created via LangChain’s `create_agent`, configured to use the two tools and a simple system prompt. The LLM is an Ollama `llama3` instance. -### Тесты -Для проверки можно запустить: -```bash -python cli.py add sample.txt -python cli.py search "Python" +## Testing +Run the CLI and try: ``` +/quit +Hello, what can you do? +``` +The agent should respond using the knowledge base or add new documents if prompted.