Update README.md
This commit is contained in:
@@ -1,36 +1,23 @@
|
|||||||
# RAG Agent with Qdrant & Ollama
|
# RAG Agent with Local Qdrant and Ollama
|
||||||
|
|
||||||
This project implements a simple **RAG (Retrieval‑Augmented 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.
|
* `/add` – add a new document to the knowledge base.
|
||||||
* **Ollama** – local LLM and embedding model (`llama3` and `nomic‑embed‑text`).
|
* `/search` – perform a semantic search in the knowledge base.
|
||||||
* **LangChain** – framework for building the agent and tools.
|
* `/quit` – exit the program.
|
||||||
|
|
||||||
The agent can:
|
## Features
|
||||||
|
|
||||||
* **Add** documents to the knowledge base.
|
* **RAG** – Retrieval-Augmented Generation using a local vector store.
|
||||||
* **Search** the knowledge base for relevant chunks.
|
* **Qdrant** – Vector similarity search engine.
|
||||||
* Answer user queries using the stored knowledge.
|
* **Ollama** – Local LLM (`llama3`) and embeddings (`nomic-embed-text`).
|
||||||
|
* **LangChain v1** – Modern agent framework.
|
||||||
|
* **Recursive text splitter** – Chunk documents before embedding.
|
||||||
|
|
||||||
## Project structure
|
## Setup
|
||||||
|
|
||||||
```
|
|
||||||
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 command‑line client
|
|
||||||
├── requirements.txt
|
|
||||||
└── README.md
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Pull the required Ollama models
|
# Install Ollama models
|
||||||
ollama pull llama3
|
ollama pull llama3
|
||||||
ollama pull nomic-embed-text
|
ollama pull nomic-embed-text
|
||||||
|
|
||||||
@@ -40,60 +27,9 @@ pip install -r requirements.txt
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### 1. Load documents into the knowledge base
|
|
||||||
|
|
||||||
```bash
|
```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.
|
You can then interact with the agent using the commands described above.
|
||||||
|
|
||||||
### 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 500‑character chunks with 50‑character 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.
|
|
||||||
Reference in New Issue
Block a user