This repository serves as a template for building a Retrieval-Augmented Generation (RAG) AI-agent. It provides a modular structure to process PDF documents, split them into manageable text chunks, assign unique IDs, store them in a vector database using embeddings, and then query a language model (via Ollama) to generate context-aware responses.
- PDF Document Processing: Extract text from PDF documents.
- Text Chunking: Split documents into smaller, overlapping chunks.
- Unique Chunk IDs: Generate unique identifiers for each chunk.
- Vector Database Storage: Use Chroma for efficient storage and retrieval of embeddings.
- RAG Pipeline: Retrieve relevant document chunks and generate responses using a language model.
- CLI Tools: Single-query and interactive multi-query command-line interfaces for querying.
Install the necessary packages by running:
pip install ollama pypdf langchain-community chromadbor
python -m pip install -r requirements.txt.
├── constants.py # Configuration constants (MODEL, CHROMA_PATH, DATA_PATH, PROMPT_TEMPLATE)
├── functions
│ ├── database.py # Functions to manage the Chroma database operations
│ ├── embedding.py # Embedding function setup using OllamaEmbeddings
│ ├── id_calculation.py # Functions for generating unique chunk IDs
│ ├── pdf_processing.py # Functions for loading and splitting PDF documents
│ └── query.py # Functions for querying the RAG pipeline
├── main.py # Main script with CLI implementations (run_single_cli & run_multi_cli)
└── README.md # This file
- Clone the Repository
git clone https://github.com/Make1tRain/RAG-template.git
cd RAG-template- Install the Required Packages
python -m pip install -r requirements.txt- Run
setup.pyfor the creation of theDATA_PATHandCHROMA_PATHdirectories which are located insideconstants.py
python setup.py-
Prepare Your Data Place your PDF documents in the directory specified by the DATA_PATH constant in constants.py (default is ./data).
-
Running the AI-Agent Single Query CLI To run a single query against the RAG pipeline, execute:
python main.py "Your query here"Interactive Multi-Query CLI
To launch an interactive session:
python main.pyThen type your queries. Type exit or bye to quit the session.
Document Processing:
Loading: The agent loads PDF and CSV documents from the specified directory.
Splitting: Documents are split into smaller, overlapping chunks for easier processing.
Unique Chunk IDs: Each text chunk is assigned a unique ID based on its source, page number, and position, preventing duplicate entries in the database.
Database Management: Processed chunks are stored in a Chroma vector database. Only new, unique chunks are added, ensuring efficient updates.
Retrieval and Generation: The system retrieves contextually similar chunks based on the user's query using vector similarity, and then combines this context with the query to generate an answer using a language model.
Note: This repository is intended as a template to help you apply the RAG (Retrieval-Augmented Generation) approach. It is designed to be customized and extended based on your specific requirements, whether you are working with different data sources or integrating with other language models.
- Also, this is a very basic template to be used and one I created to just learn how to implement RAG, so use at your own discretion.
- Finally, I used
deepseek-r1:14bmodel for this template along with the given file structure for the chorma database and the data to be fed to the AI-Agent which can all be changed inconstants.py