5d01ac1d8bea2e83b400967ce334f418e958fcfc
# RAG Agent with Qdrant and Ollama
This project implements an AI agent that can search and add documents to a local knowledge base using **Qdrant** for vector storage and **Ollama** for embeddings and LLM inference. The agent is built with **LangChain** and exposes two tools:
- `search_knowledge_base(query, max_results)` – semantic search in the knowledge base.
- `add_to_knowledge_base(content, title)` – add a new document to the knowledge base.
## Features
- **Vector store**: Qdrant with Ollama embeddings (`nomic-embed-text`).
- **Chunking**: Recursive character splitter with overlap.
- **Agent**: Zero-shot React agent that uses the two tools.
- **CLI**: Interactive command line interface to add documents and query the agent.
- **Batch loading**: Script to load all text files from a directory into the knowledge base.
## Prerequisites
- Python 3.10+
- Docker (for Qdrant) or a running Qdrant instance.
- Ollama installed locally with the following models:
```bash
ollama pull llama3
ollama pull nomic-embed-text
Setup
# Clone the repository
git clone https://github.com/your-username/rag-agent.git
cd rag-agent
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Start Qdrant (Docker example)
docker run -p 6333:6333 qdrant/qdrant
Usage
1. Load documents into the knowledge base
python src/main.py /path/to/documents
Supported file types: .txt, .md. (PDF support can be added with an additional parser.)
2. Start the interactive CLI
python src/cli.py
Commands:
/add <file_path>– Add a single document./search <query>– Query the agent./quit– Exit.
3. Example
> /add example.txt
Document 'example' added to knowledge base with 3 chunks.
> /search What is the capital of France?
1. The capital of France is Paris. (Title: example)
Project Structure
rag-agent/
├── src/
│ ├── agent.py
│ ├── cli.py
│ ├── main.py
│ ├── tools.py
│ └── vector_store.py
├── requirements.txt
└── README.md
License
MIT License
Description
Languages
Python
100%