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
## 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.
## Overview
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:
- **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_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.
1. Add documents to the knowledge base.
2. Search the knowledge base semantically.
3. Answer arbitrary user queries using the stored information.
## 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)
```
The project is structured into three main files:
- `main.py` entry point with an interactive CLI and examples.
- `tools.py` LangChain tools for adding/searching documents.
- `requirements.txt` Python dependencies.
## Installation
```bash
# Pull required Ollama models
# Pull required Ollama models (run once)
ollama pull llama3
ollama pull nomic-embed-text
# Install Python dependencies
# Install Python packages
pip install -r requirements.txt
```
## Usage
1. **Load documents** Place any `.txt` files in the `docs/` directory.
2. **Run the CLI**:
```bash
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...
Run the interactive client:
```bash
python main.py
```
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
- 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 **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.
The agent uses LangChains `create_agent` with two custom tools:
## License
MIT © 2026
1. **add_to_knowledge_base** splits input into chunks, embeds them via Ollama, and stores in Qdrant.
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.