add README.md

This commit is contained in:
2026-05-27 14:37:14 +00:00
parent 4ab0407e17
commit 1c918f4d94
+29 -42
View File
@@ -1,60 +1,47 @@
# RAG Agent with Qdrant and Ollama # RAG Agent with Qdrant and Ollama
## Project Overview ## 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. This repository contains a minimal implementation of an AI agent that uses **RAG (RetrievalAugmented Generation)** with a local vector store powered by **Qdrant** and embeddings from **Ollama**. The agent can:
The main components are: 1. Add documents to the knowledge base.
- **Vector store** Qdrant client with an initialized collection. 2. Search the knowledge base semantically.
- **Text splitter** RecursiveCharacterTextSplitter for chunking documents. 3. Answer arbitrary user queries using the stored information.
- **Embedding model** OllamaEmbeddings (`nomic-embed-text`).
- **LLM** ChatOllama (`llama3`).
- **Tools** `search_knowledge_base` and `add_to_knowledge_base`.
- **Agent** created with `create_agent` from LangChain.
- **CLI client** simple interactive loop to demonstrate adding documents and searching the knowledge base.
## Directory Structure The project is structured into three main files:
```
├── README.md - `main.py` entry point with an interactive CLI and examples.
├── requirements.txt - `tools.py` LangChain tools for adding/searching documents.
├── main.py # CLI entry point - `requirements.txt` Python dependencies.
├── 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 ## Installation
```bash ```bash
# Pull required Ollama models # Pull required Ollama models (run once)
ollama pull llama3 ollama pull llama3
ollama pull nomic-embed-text ollama pull nomic-embed-text
# Install Python dependencies # Install Python packages
pip install -r requirements.txt pip install -r requirements.txt
``` ```
## Usage ## Usage
1. **Load documents** Place any `.txt` files in the `docs/` directory. Run the interactive client:
2. **Run the CLI**: ```bash
```bash python main.py
python main.py
```
3. 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
```text
> /search python data structures
1. Python lists are ordered collections...
2. Tuples are immutable sequences...
``` ```
You can use the following commands:
- `/add` add a new document.
- `/search <query>` perform a semantic search.
- `/quit` exit.
- Any other text is treated as a question for the agent.
## Architecture ## Architecture
- The **agent** is a LangChain agent that uses two tools: `search_knowledge_base` and `add_to_knowledge_base`. It receives user messages, decides which tool to call, and returns the result. The agent uses LangChains `create_agent` with two custom tools:
- 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 1. **add_to_knowledge_base** splits input into chunks, embeds them via Ollama, and stores in Qdrant.
MIT © 2026 2. **search_knowledge_base** performs a similarity search on the vector store.
The LLM is an Ollama `llama3` model accessed through LangChains `ChatOllama`. The embeddings are provided by `OllamaEmbeddings` with the `nomic-embed-text` model.
## Extending
Feel free to add more tools or integrate a persistent Qdrant instance instead of an inmemory one. The code is intentionally simple for educational purposes.