2026-06-05 11:29:15 +00:00
2026-06-05 11:29:15 +00:00
2026-06-04 20:03:19 +00:00
2026-06-05 11:27:55 +00:00
2026-06-03 08:44:03 +00:00
2026-06-04 20:02:26 +00:00
2026-06-04 20:02:32 +00:00
2026-06-04 20:02:38 +00:00
2026-06-05 11:28:24 +00:00
2026-06-04 20:02:44 +00:00
2026-06-05 10:24:39 +00:00
2026-06-05 10:24:44 +00:00
2026-06-05 11:28:47 +00:00
2026-06-05 11:28:53 +00:00
2026-06-04 20:03:14 +00:00

RAG Agent with Qdrant & Ollama

This project implements a simple RAG (RetrievalAugmented Generation) agent that uses:

  • Qdrant a vector database for storing embeddings.
  • Ollama local LLM and embedding model (llama3 and nomicembedtext).
  • LangChain framework for building the agent and tools.

The agent can:

  • Add documents to the knowledge base.
  • Search the knowledge base for relevant chunks.
  • Answer user queries using the stored knowledge.

Project structure

workspace/
├── src/
│   ├── __init__.py
│   ├── vector_store.py   # Qdrant wrapper
│   ├── tools.py          # LangChain tools
│   ├── agent.py          # Agent definition
│   ├── loader.py         # Load all .txt files from a directory
│   └── cli.py            # Interactive commandline client
├── requirements.txt
└── README.md

Installation

# Pull the required Ollama models
ollama pull llama3
ollama pull nomic-embed-text

# Install Python dependencies
pip install -r requirements.txt

Usage

1. Load documents into the knowledge base

python -m src.loader /path/to/text/files

All .txt files in the directory (recursively) are added to the vector store.

2. Start the interactive CLI

python -m src.cli

Once started you can use the following commands:

Command Description
/add <title> <file_path> Add a single file to the knowledge base.
/search <query> Search the knowledge base and display top results.
/quit Exit the program.
/help Show help.
Any other text Sent to the agent as a user query.

3. Example session

RAG Agent CLI. Type /help for commands.
> /add example docs/example.txt
Document 'example' added.
> /search quantum
Results:
1. [example - chunk 0] Quantum mechanics is the branch of physics that deals with...
> Tell me more about quantum.
Sure! Here is what I found in the knowledge base: ...
> /quit
Goodbye.

How it works

  • Vector Store KnowledgeBase wraps a QdrantVectorStore. It creates the collection only if it does not exist, preventing accidental data loss.
  • Chunking Documents are split into 500character chunks with 50character overlap using RecursiveCharacterTextSplitter.
  • Tools Two LangChain tools are exposed:
    • search_knowledge_base(query, max_results) returns a list of relevant chunks.
    • add_to_knowledge_base(content, title) adds a document.
  • Agent Built with create_agent from langchain.agents. It uses the local ChatOllama model (llama3).

Extending

  • Replace the embedding model by editing KnowledgeBase.__init__.
  • Add more tools (e.g., delete from knowledge base) following the same pattern.
  • Deploy the agent as a web service by wrapping run_query in a FastAPI endpoint.

License

MIT License.

S
Description
Агент с RAG-памятью
Readme 275 KiB
Languages
Python 100%