Files
agent-s-rag-pamyatyu/README.md
T
2026-06-30 15:41:27 +03:00

65 lines
1.9 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.
# 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 Ollamas embedding endpoint (`ollama.embeddings`) with caching.
- **LLM** Uses Ollamas chat endpoint (`ollama.chat`) for generation.
- **RAG** Cosine similarity based retrieval of topk 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.