WeightedRAG Setup Guide
This guide walks you through setting up the WeightedRAG pipeline from scratch, including data preparation, chunking, and evaluation.
WeightedRAG Setup Guide
This guide walks you through setting up the WeightedRAG pipeline from scratch, including data preparation, chunking, and evaluation.
๐ Prerequisites
- Python 3.8+
- Git
- Google Cloud SDK (optional, for downloading NQ dataset)
- At least 8GB RAM for processing
- ~10GB disk space for full dataset
๐ Quick Start
1. Clone and Setup Environment
git clone https://github.com/Abhijit85/WeightedRAG.git
cd WeightedRAG
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install --upgrade pip
pip install -e .
pip install -r requirements.txt
2. Install Package in Development Mode
# This enables imports from the weighted_rag module
pip install -e .
Note: The
pip install -e .command uses thesetup.pyfile in the root directory to install the WeightedRAG package in "editable" mode. This allows you to make changes to the code without reinstalling.
๐ Data Preparation
Option A: Download Natural Questions Dataset (Recommended)
# Create data directories
mkdir -p datasets/nq-table/raw
# Download NQ training files (requires gsutil)
gsutil -m cp gs://natural_questions/v1.0/train/nq-train-*.jsonl.gz datasets/nq-table/raw/
# Decompress files
for file in datasets/nq-table/raw/*.jsonl.gz; do
gunzip -k "$file"
done
Option B: Use Sample Data (For Testing)
# Extract sample from first shard only
python chunking/utils/corrected_nq_table_extractor.py \
--input datasets/nq-table/raw/nq-train-00.jsonl \
--output datasets/nq-table/nq_table_full_extraction.jsonl \
--sample 1000
๐ Pipeline Execution
Step 1: Extract Table QA Pairs
# Extract table-centric Q&A pairs from Natural Questions
python chunking/utils/corrected_nq_table_extractor.py \
--input datasets/nq-table/raw/nq-train-00.jsonl \
--output datasets/nq-table/nq_table_full_extraction.jsonl \
--sample 50000
Output: datasets/nq-table/nq_table_full_extraction.jsonl
Step 2: Generate Multi-Granular Chunks
# Create retrieval chunks with different granularities
cd chunking/core
python create_retrieval_tables.py --max-entries 50000
cd ../..
Outputs:
retrieval_tables/processed_tables.jsonlretrieval_tables/retrieval_chunks.jsonlretrieval_tables/chunks_*.jsonl(per chunk type)
Step 3: Convert to BEIR Format
# Transform to evaluation-ready format
python scripts/prepare_nq_tables_beir.py \
--tables retrieval_tables/processed_tables.jsonl \
--chunks retrieval_tables/retrieval_chunks.jsonl \
--output-dir datasets/nq-table/beir \
--chunk-types full_table,table_only,table_row,sliding_window,table_sample,pure_table
Outputs:
datasets/nq-table/beir/corpus.jsonldatasets/nq-table/beir/queries.jsonldatasets/nq-table/beir/qrels.tsv
Step 4: Run Retrieval Evaluation
# Evaluate retrieval performance
python scripts/evaluate_retrieval.py \
--dataset-root datasets/nq-table/beir \
--ks 1,3,5,10 \
--max-queries 500 \
--save-results outputs/nq_table_metrics.json
Outputs:
- Console metrics summary
outputs/nq_table_metrics.json(detailed results)
๐๏ธ Architecture Overview
Key Components
-
Document Chunking: Multi-granular table chunking
- Full tables
- Individual rows
- Sliding windows
- Table samples
-
Embedding: Matryoshka embeddings with multiple dimensions
- Model:
sentence-transformers/all-MiniLM-L6-v2 - Dimensions: 384 (configurable)
- Model:
-
Indexing: FAISS HNSW for efficient similarity search
- Index type:
HNSW32 - Approximate nearest neighbor search
- Index type:
-
Retrieval: Multi-stage weighted retrieval
- Dense vector similarity
- Metadata-based scoring
- Optional cross-encoder reranking
- Optional graph-based reranking
Pipeline Flow
Raw Data โ Extract Tables โ Generate Chunks โ Embed โ Index โ Retrieve โ Rank โ Generate
โ๏ธ Configuration
Basic Configuration
Create config.json for custom settings:
{
"embedding": {
"model_name": "sentence-transformers/all-MiniLM-L6-v2",
"batch_size": 16,
"device": "cpu"
},
"retrieval": {
"stages": [
{
"name": "dense",
"dimension": 384,
"top_k": 100,
"weight": 1.0,
"index_factory": "HNSW32"
}
]
},
"chunking": {
"max_tokens": 128,
"overlap_tokens": 16
}
}
Enable Optional Features
{
"use_graph_rerank": true,
"cross_encoder": {
"model_name": "cross-encoder/ms-marco-MiniLM-L-6-v2",
"batch_size": 32
}
}
๐งช Testing Your Setup
Quick Verification
# Test table extraction
python chunking/utils/corrected_nq_table_extractor.py \
--input datasets/nq-table/raw/nq-train-00.jsonl \
--output test_extraction.jsonl \
--sample 10
# Test chunking
cd chunking/core
python create_retrieval_tables.py --max-entries 10
cd ../..
# Test evaluation (small scale)
python scripts/evaluate_retrieval.py \
--dataset-root datasets/nq-table/beir \
--ks 1,3,5 \
--max-queries 5
๐ ๏ธ Troubleshooting
Common Issues
- ModuleNotFoundError: Run
pip install -e .from repo root - Memory issues: Reduce batch sizes or use smaller sample sizes
- FAISS errors: Install
faiss-cpuorfaiss-gpu - Slow processing: Use GPU if available, reduce dataset size
Performance Tips
- Use GPU for embedding computation
- Increase batch sizes if you have more RAM
- Use FAISS GPU index for large datasets
- Process in smaller chunks if memory constrained
๐ Project Structure
WeightedRAG/
โโโ src/weighted_rag/ # Main package
โ โโโ embeddings/ # Embedding models
โ โโโ index/ # Vector indexes
โ โโโ retrieval/ # Retrieval algorithms
โ โโโ evaluation/ # Metrics and evaluation
โโโ chunking/ # Table chunking logic
โ โโโ core/ # Main chunking algorithms
โ โโโ processors/ # Data processors
โ โโโ utils/ # Utility functions
โโโ scripts/ # Evaluation scripts
โโโ datasets/ # Data storage (gitignored)
โโโ retrieval_tables/ # Generated chunks (gitignored)
โโโ outputs/ # Results and metrics
โโโ setup.py # Package installation configuration
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
Key Files
- setup.py: Defines the package structure and dependencies for
pip install -e . - requirements.txt: Lists all Python dependencies needed for the project
- SETUP.md: This setup guide
- evaluation_log.txt: Detailed logs from evaluation runs
๐ Expected Results
Retrieval Metrics
After successful setup, you should see metrics like:
P@1: 0.25-0.35
P@5: 0.15-0.25
P@10: 0.10-0.20
Recall@10: 0.30-0.50
NDCG@10: 0.30-0.45
MRR: 0.30-0.40
Processing Times
- Table extraction: ~5-10 minutes (50k samples)
- Chunking: ~10-15 minutes (50k samples)
- BEIR conversion: ~2-3 minutes
- Evaluation: ~15-30 minutes (500 queries)
๐ Next Steps
- Scale Up: Process full dataset instead of samples
- Tune Parameters: Adjust chunking, embedding, and retrieval settings
- Add Features: Enable cross-encoder or graph reranking
- Custom Data: Adapt pipeline for your own table datasets
- Production: Deploy with proper error handling and monitoring
๐ Additional Resources
- Original README.md - Technical details
- Evaluation Log - Detailed logs
- Chunking README - Chunking specifics
๐ Getting Help
If you encounter issues:
- Check the troubleshooting section above
- Review the evaluation log for detailed error messages
- Ensure all dependencies are installed correctly
- Verify data paths and file permissions
- Open an issue with detailed error information
๐ฏ Success Criteria
Your setup is working correctly if:
- All scripts run without errors
- Generated files exist in expected locations
- Evaluation produces reasonable metric values
- Processing times are within expected ranges
- No import or dependency errors occur
Related Documents
SUMMARY
permalink: ai-implementation
Retrieval & Prompts
Retrieval quality depends on two things: **what the extraction prompt produces**, and **how Vector Storage is configured**. Most people start with Vector Storage settings โ but the bigger lever is the prompt. A well-structured memory block retrieves accurately even with default settings. A poorly structured one won't retrieve well no matter how much you tune.
App Review Support Guide โ Switch2Go
Switch2Go is an **AAC (Augmentative and Alternative Communication)** app designed specifically for users with **Cerebral Visual Impairment (CVI)**. It allows non-verbal or communication-impaired users to compose and speak phrases entirely hands-free using:
RFC-BLite: High-Performance Embedded Document Database for .NET
**Status:** Draft (living document)