Update README.md

This commit is contained in:
2026-06-05 11:43:34 +00:00
parent 30944f606e
commit 7b78d7e17e
+16 -80
View File
@@ -1,36 +1,23 @@
# RAG Agent with Qdrant & Ollama
# RAG Agent with Local Qdrant and Ollama
This project implements a simple **RAG (RetrievalAugmented Generation) agent** that uses:
This repository implements a simple AI agent that can store, search, and retrieve information from a local vector store using Qdrant and Ollama embeddings. The agent is built with LangChain v1 and supports an interactive CLI with the following commands:
* **Qdrant** a vector database for storing embeddings.
* **Ollama** local LLM and embedding model (`llama3` and `nomicembedtext`).
* **LangChain** framework for building the agent and tools.
* `/add` add a new document to the knowledge base.
* `/search` perform a semantic search in the knowledge base.
* `/quit` exit the program.
The agent can:
## Features
* **Add** documents to the knowledge base.
* **Search** the knowledge base for relevant chunks.
* Answer user queries using the stored knowledge.
* **RAG** Retrieval-Augmented Generation using a local vector store.
* **Qdrant** Vector similarity search engine.
* **Ollama** Local LLM (`llama3`) and embeddings (`nomic-embed-text`).
* **LangChain v1** Modern agent framework.
* **Recursive text splitter** Chunk documents before embedding.
## 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
## Setup
```bash
# Pull the required Ollama models
# Install Ollama models
ollama pull llama3
ollama pull nomic-embed-text
@@ -40,60 +27,9 @@ pip install -r requirements.txt
## Usage
### 1. Load documents into the knowledge base
```bash
python -m src.loader /path/to/text/files
# Load documents from the `docs` folder and start the CLI
python -m src.cli --docs docs
```
All `.txt` files in the directory (recursively) are added to the vector store.
### 2. Start the interactive CLI
```bash
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.
You can then interact with the agent using the commands described above.