This repository contains the implementation for the research paper "Adaptive Chunking and Model-Aware Retrieval Strategies for Multi-Hop Retrieval-Augmented Generation".
It implements a Model-Aware RAG pipeline that dynamically adjusts chunk sizes to optimize retrieval for both token-constrained and large-context embedding models.
Existing RAG systems often rely on fixed chunking strategies that fail to account for model-specific constraints. This project introduces an adaptive pipeline that:
- Token-Constrained Models: Uses 1500-character chunks for models like BERT/BGE to prevent truncation.
- Large-Context Models: Uses 5000-character chunks for models like Qwen/Snowflake to maximize semantic coherence.
- Structure Preservation: Converts JSON corpora to PDF to retain layout and hierarchy before segmentation.
- Adaptive Chunking: Logic to switch between chunk sizes based on the selected embedding model.
- Hybrid Retrieval: Combines dense vector retrieval (OpenSearch) with sparse retrieval (BM25).
- Multi-Hop Reasoning: Optimized for questions requiring evidence from multiple documents (MultiHop-RAG benchmark).
- Hallucination Reduction: Larger context windows reduce evidence fragmentation, leading to lower hallucination rates.
app.py: Main application entry point (Streamlit interface).JsonToPdf.py: Preprocessing script to convert JSON datasets into structure-preserving PDFs.split.py: Core logic for the adaptive chunking strategy (sentence-aware segmentation).docker-compose-opensearch.yml: Docker setup for the OpenSearch vector database.MultiHop-Rag/: Dataset and core processing modules.
- Python 3.8+
- Docker (for OpenSearch)
-
Clone the repository:
git clone [https://github.com/DS-ProjectRepo/rag.git](https://github.com/DS-ProjectRepo/rag.git) cd rag -
Start the Vector Database (OpenSearch):
docker-compose -f docker-compose-opensearch.yml up -d
-
Run the Application:
python app.py
Based on the paper's evaluation:
- Retrieval: Significant improvements in Hits@10 and MAP@10 using adaptive chunking.
- Generation: Reduced hallucination rates for inference-heavy queries when using 5000-character chunks with large-context models.
For more details, please refer to the associated research paper.