9f07fd13a1227ae6dfe5dfdb9ee80d5a8507367f
RAG Agent with ChromaDB
Overview
This repository implements a simple RAG (Retrieval‑Augmented Generation) agent that uses ChromaDB as the vector store and Ollama for embeddings and LLM inference. The agent can:
- Add documents to the knowledge base.
- Search the knowledge base semantically.
- Interact via a lightweight CLI.
File Structure
requirements.txt– Python dependencies.chunker.py– Text chunking utilities (RecursiveCharacterTextSplitter).vector_store.py– Wrapper around ChromaDB collection.tools.py– LangChain tools for search and add operations.agent.py– Agent creation with LangChaincreate_agent.cli.py– Simple command‑line interface.init_documents.py– Helper to load all.txtfiles from a directory into the vector store.
Installation
# Pull Ollama models
ollama pull llama3
ollama pull nomic-embed-text
# Install Python packages
pip install -r requirements.txt
Usage
- Load documents (optional):
python init_documents.py - Run the CLI:
Type any question or
python cli.py/quitto exit.
Architecture
- Chunking:
chunker.split_text()splits large texts into 500‑char chunks with 100‑char overlap using LangChain’sRecursiveCharacterTextSplitter. - Vector Store:
vector_store.ChromaVectorStorehandles adding documents and similarity search. Embeddings are generated bylangchain_ollama.OllamaEmbeddings(nomic-embed-text). - Tools: Two tools decorated with
@tool:search_knowledge_baseandadd_to_knowledge_base. They interact with the vector store. - Agent: Created via LangChain’s
create_agent, configured to use the two tools and a simple system prompt. The LLM is an Ollamallama3instance.
Testing
Run the CLI and try:
/quit
Hello, what can you do?
The agent should respond using the knowledge base or add new documents if prompted.
Description
Languages
Python
100%