42fd00d924228ba37c3511cd9cb616c5baa764d3
CI / build (push) Has been cancelled
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 in‑memory 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
# 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:
langchain
langchain-community
openai
Configuration
Set the Ollama model via environment variable (optional):
export OLLAMA_MODEL=mistral # or any other model available in Ollama
If you run the Ollama server on a non‑default host/port, set:
export OLLAMA_HOST=http://localhost:11434
Running the Agent
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 in‑memory; data will be lost when the program exits.
- For persistent storage, replace the in‑memory implementation with a vector database such as Chroma or FAISS.
- The LLM used for generation is OpenAI’s GPT‑3.5 via the
openaipackage. Adjust theOpenAIinitialization if you prefer another model.
License
MIT License
Description
Languages
Python
67.1%
TypeScript
16.6%
JavaScript
15.4%
Dockerfile
0.9%