# RAG Agent with Ollama This project implements a simple Retrieval-Augmented Generation (RAG) agent that uses **Ollama** for both embeddings and LLM inference. The agent stores documents in memory, retrieves the most relevant ones for a query, and generates an answer using the retrieved context. ## Features - **Embeddings** – Uses Ollama’s embedding endpoint (`ollama.embeddings`) with caching. - **LLM** – Uses Ollama’s chat endpoint (`ollama.chat`) for generation. - **RAG** – Cosine similarity based retrieval of top‑k documents. - **FastAPI** – Exposes a REST API for adding documents and asking questions. - **Docker** – Containerized with Ollama and FastAPI. ## Setup ```bash # Clone the repo git clone https://git.brojs.ru/kuzakhmetovartur/agent-s-rag-pamyatyu.git cd agent-s-rag-pamyatyu # Build Docker image docker build -t rag-agent . # Run container docker run -p 8000:8000 rag-agent ``` The API will be available at `http://localhost:8000`. ## API Endpoints | Method | Path | Description | |--------|-----------|---------------------------------| | POST | /documents | Add a document to the agent. | | POST | /ask | Ask a question; returns answer. | ### Example ```bash # Add a document curl -X POST http://localhost:8000/documents \ -H "Content-Type: application/json" \ -d '{"text":"Python is a programming language."}' # Ask a question curl -X POST http://localhost:8000/ask \ -H "Content-Type: application/json" \ -d '{"query":"What is Python?"}' ``` ## Dependencies - `ollama` – Ollama client for embeddings and chat. - `fastapi` – Web framework. - `uvicorn` – ASGI server. - `numpy` – Numerical operations. - `pydantic` – Data validation. All dependencies are listed in `requirements.txt`. ## License MIT License --- This implementation follows the assignment constraints: **only Ollama** is used for embeddings and LLM, no OpenAI services are involved.