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

90 lines
2.2 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 Embeddings
This project demonstrates a simple Retrieval-Augmented Generation (RAG) agent that uses **OllamaEmbeddings** for vector similarity search and a local inmemory knowledge base.
The agent is built with **LangChain** and exposes two tools:
- `search_knowledge_base`: Search the knowledge base for relevant documents.
- `add_to_knowledge_base`: Add new content to the knowledge base.
## Prerequisites
- Python 3.10+
- An Ollama server running locally (e.g., `ollama serve`).
- The Ollama model you want to use (default is `mistral`).
## Installation
```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
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
```
`requirements.txt` contains:
```text
langchain
langchain-community
openai
```
## Configuration
Set the Ollama model via environment variable (optional):
```bash
export OLLAMA_MODEL=mistral # or any other model available in Ollama
```
If you run the Ollama server on a nondefault host/port, set:
```bash
export OLLAMA_HOST=http://localhost:11434
```
## Running the Agent
```bash
python src/agent.py
```
You will see a prompt:
```
Welcome to the RAG Agent. Type 'exit' to quit.
User:
```
- **Add knowledge**:
`add_to_knowledge_base This is a new piece of information.`
- **Search knowledge**:
`search_knowledge_base information`
The agent will automatically decide which tool to use based on the user query.
## Example Session
```
User: add_to_knowledge_base Python is a versatile programming language.
Agent: Document added. Total documents: 1.
User: search_knowledge_base programming language
Agent: Python is a versatile programming language.
```
## Notes
- The knowledge base is **inmemory**; data will be lost when the program exits.
- For persistent storage, replace the inmemory implementation with a vector database such as Chroma or FAISS.
- The LLM used for generation is OpenAIs GPT3.5 via the `openai` package. Adjust the `OpenAI` initialization if you prefer another model.
## License
MIT License