2.4 KiB
2.4 KiB
RAG Agent with Qdrant and Ollama
Project Overview
This repository contains a minimal yet complete implementation of an AI agent that can search and add information to a local knowledge base powered by Qdrant (vector database) and Ollama (local LLM & embeddings). The agent is built using the LangChain framework.
The main components are:
- Vector store – Qdrant client with an initialized collection.
- Text splitter – RecursiveCharacterTextSplitter for chunking documents.
- Embedding model – OllamaEmbeddings (
nomic-embed-text). - LLM – ChatOllama (
llama3). - Tools –
search_knowledge_baseandadd_to_knowledge_base. - Agent – created with
create_agentfrom LangChain. - CLI client – simple interactive loop to demonstrate adding documents and searching the knowledge base.
Directory Structure
├── README.md
├── requirements.txt
├── main.py # CLI entry point
├── agent.py # Agent creation logic
├── tools.py # LangChain tool definitions
├── utils.py # Qdrant client, splitter, and helper functions
└── docs/ # Directory with text files to load initially (optional)
Installation
# Pull required Ollama models
ollama pull llama3
ollama pull nomic-embed-text
# Install Python dependencies
pip install -r requirements.txt
Usage
- Load documents – Place any
.txtfiles in thedocs/directory. - Run the CLI:
python main.py - In the interactive prompt you can use:
/add <file_path>– Add a new document to the knowledge base./search <query>– Search the knowledge base and display results./quit– Exit the program.
Example
> /search python data structures
1. Python lists are ordered collections...
2. Tuples are immutable sequences...
Architecture
- The agent is a LangChain agent that uses two tools:
search_knowledge_baseandadd_to_knowledge_base. It receives user messages, decides which tool to call, and returns the result. - The vector store is wrapped by
QdrantVectorStore, which handles embedding generation via OllamaEmbeddings. Documents are split into chunks before insertion. - The CLI orchestrates loading documents at startup and provides a simple REPL for demonstration purposes.
License
MIT © 2026