Noise-Aware Retrieval-Augmented Generation preprocessing engine
Project description
๐งน NoiRAG: Noise-Aware Retrieval-Augmented Generation
An intelligent, zero-cost preprocessing engine that recovers retrieval accuracy from OCR-damaged and noisy documents using a Hybrid Triage Architecture.
๐ Overview
Real-world RAG (Retrieval-Augmented Generation) systems often fail when processing messy PDFs full of OCR errors, arbitrary line breaks, and formatting garbage. NoiRAG is a lightweight, intelligent preprocessing engine that intercepts and cleans noisy documents before they are embedded into the vector database โ recovering lost retrieval performance using a Hybrid Triage Architecture that dynamically routes each text chunk to the optimal cleaner.
Key results across 8 evaluated experiments:
- โ p-value โฅ 0.05 for all NoiRAG Cleaned results โ statistically indistinguishable from perfect data
- ๐ฐ 99.6% of API calls avoided โ $336+ saved vs. GPT-4o equivalent
- โก Offline-first architecture โ runs 100% local (via Ollama) or via hybrid cloud backends (like Groq)
- ๐ฑ < 0.01 kg COโeq carbon footprint per full pipeline run
๐๏ธ Architecture & Modules
NoiRAG/
โโโ baseline/ # Noise injection & uncleaned baseline measurement
โ โโโ noise_injector.py # Artificially corrupts clean documents
โ โโโ run_baseline.py # Measures raw (uncleaned) retrieval performance
โโโ noirag/
โ โโโ preprocessing/
โ โ โโโ rule_based/ # Regex-based formatting repair
โ โ โโโ statistical/ # SymSpellPy edit-distance spell correction
โ โ โโโ hybrid/ # Hybrid Orchestrator + Quality Scorer + LLM Cleaner
โ โ โโโ hybrid_cleaner.py # Routes chunks to the right cleaner
โ โ โโโ quality_scorer.py # Scores noisiness (OOV + Garbage Density)
โ โ โโโ llm_cleaner.py # Groq / Local Ollama for severe corruption
โ โโโ tests/ # Unit tests for all cleaners
โ โโโ run_noirag.py # Master experiment runner
โโโ pipeline/ # Standard RAG components
โ โโโ chunker/ # Text splitting
โ โโโ embedder/ # BGE-Small embedding
โ โโโ retriever/ # FAISS vector retrieval
โ โโโ generator/ # LLM answer generation
โโโ evaluation/ # Retrieval & generation evaluation metrics
โโโ configs/config.yaml # Central configuration
โโโ data/ # Datasets (ground truth, noisy, cleaned)
โโโ results/tables/ # Benchmark evaluation outputs (JSON)
โโโ main.py # Streamlit dashboard
โ๏ธ How NoiRAG Works
The core innovation is its Hybrid Triage Architecture โ an intelligent routing system that assigns each chunk to the cheapest cleaner capable of fixing it:
๐ Noisy Chunk
โ
โผ
๐ Quality Scorer โโโบ OOV Ratio + Garbage Density Score (0.0 โ 1.0)
โ
โผ
๐ Hybrid Orchestrator
โโโ Score < 0.05 โโโบ โ
Bypass (already clean, don't touch)
โโโ Garbage > 0.05 โโโบ ๐ง Rule-Based (formatting noise)
โโโ OOV > 0.10 โโโบ ๐ Statistical (typos / OCR errors)
โโโ Score > 0.60 โโโบ ๐ค LLM Cleaner (severe corruption)
| Cleaner | What it fixes | Cost | Speed |
|---|---|---|---|
| Bypass | Nothing โ text is already clean | Free | ~0ms |
| Rule-Based | Garbage chars, unicode noise, broken line merging | Free | ~0.1ms |
| Statistical | Typos, OCR substitutions (SymSpellPy) | Free | ~1โ5ms |
| LLM Cleaner | Severely corrupted text (Groq / local Ollama) | Free | varies |
๐ Benchmark Results
All experiments use BAAI/bge-small-en-v1.5 embeddings with FAISS retrieval. p-values are from a paired t-test (MRR scores) against the Ground Truth baseline.
๐ต Formatting Noise Experiments
| Experiment | Queries | GT MRR | Noisy MRR | NoiRAG MRR | p-value | Result |
|---|---|---|---|---|---|---|
formatting_10 |
15 | 0.8833 | 0.9000 | 0.9000 | 0.334 | โ Full recovery |
formatting_25 |
15 | 0.8833 | 0.9467 | 0.8333 | 0.189 | โ Statistically valid |
formatting_50 |
6 | 1.0000 | 1.0000 | 0.6667 | 0.175 | โ Statistically valid |
formatting_75 |
15 | 0.8833 | 0.8667 | 0.8667 | 0.751 | โ Full recovery |
๐ Semantic Noise Experiments
| Experiment | Queries | GT MRR | Noisy MRR | NoiRAG MRR | p-value | Result |
|---|---|---|---|---|---|---|
semantic_10 |
15 | 0.8833 | 0.8222 | 0.8689 | 0.705 | โ Cleaned > Noisy |
semantic_25 |
15 | 0.8833 | 0.9222 | 0.8667 | 0.670 | โ Statistically valid |
semantic_50 |
15 | 0.8833 | 0.6722 ๐ด | 0.8056 | 0.169 | โ Strong recovery |
semantic_75 |
15 | 0.8833 | 0.4022 ๐ด | 0.8300 | 0.379 | ๐ Best recovery |
Reading the table: A p-value โฅ 0.05 means NoiRAG Cleaned is statistically indistinguishable from perfect Ground Truth data. All 8 experiments pass this threshold. โ
๐ Headline Result โ 75% Semantic Noise
| Metric | Ground Truth | Noisy Baseline | NoiRAG Cleaned |
|---|---|---|---|
| P@1 | 0.8667 | 0.2000 (-76.9%) | 0.8000 (+150% recovery) |
| MRR | 0.8833 | 0.4022 (-54.5%) | 0.8300 (+107% recovery) |
| NDCG@5 | 0.8806 | 0.4986 (-43.4%) | 0.8265 (+65.7% recovery) |
p-value = 0.379 โ NoiRAG statistically restores a completely broken RAG pipeline back to near-perfect accuracy.
๐ฐ Cost Savings
NoiRAG processed the full corpus using only free, local algorithms:
| Metric | Value |
|---|---|
| API calls avoided | 99.6% |
| Saved vs. GPT-4o-mini | ~$20 |
| Saved vs. GPT-4o | ~$336 |
| NoiRAG actual cost | $0.00 |
| Processing time | < 2 minutes (full corpus) |
| Carbon footprint | < 0.01 kg COโeq per run |
๐ RAG Evaluation Metrics
| Metric | Description |
|---|---|
| P@1 | Does the #1 retrieved chunk contain the correct answer? |
| R@5 | Out of top 5 chunks, does at least one contain the answer? |
| MRR | Mean Reciprocal Rank โ how close to #1 is the correct answer? |
| NDCG@5 | Normalized Discounted Cumulative Gain โ overall ranking quality |
๐ Installation & Usage
# 1. Clone the repository
git clone https://github.com/shreyabag028/NoiRAG.git
cd NoiRAG
# 2. Install dependencies
pip install -r requirements.txt
# 3. Launch the Streamlit dashboard
streamlit run main.py
# 4. (Optional) Run pipeline from CLI
python -m noirag.run_noirag --noise-type semantic --noise-level 75
# 5. Run unit tests
pytest noirag/tests/ -v
๐ง Environment Variables
Create a .env file in the project root:
# Required for Groq LLM backend (fast, free tier)
GROQ_API_KEY=your_groq_key_here
# Optional: HuggingFace token for private models
HF_TOKEN=your_huggingface_token_here
Note: The Groq API is only used for the LLM Cleaner route, which is triggered for < 1% of chunks (severely corrupted text). All other cleaning is done locally with zero API calls.
๐๏ธ Dataset
Evaluated across 7 diverse domains to ensure cross-domain robustness:
| Domain | Type |
|---|---|
| ๐ Academic Papers | Research articles |
| ๐๏ธ Administrative Documents | Government/institutional |
| ๐ฐ Financial Reports | Earnings, filings |
| โ๏ธ Legal Texts | Contracts, legislation |
| ๐ User Manuals | Technical documentation |
| ๐ฐ News Articles | Journalism |
| ๐ Educational Textbooks | Curriculum material |
๐ฅ Team
Built by Team NoiRAG ยท GitHub Repository
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file noirag-1.0.2.tar.gz.
File metadata
- Download URL: noirag-1.0.2.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd2356781788dd8f395695d120631bcd80a2fcad8ec62df7f246275b94154e53
|
|
| MD5 |
8ae7ba734c6727b3d5be183933f11995
|
|
| BLAKE2b-256 |
617bd9b2b960c4bdeee14224955e2a0ee3ac1c2e3fde036ca6556780ace88b6f
|
File details
Details for the file noirag-1.0.2-py3-none-any.whl.
File metadata
- Download URL: noirag-1.0.2-py3-none-any.whl
- Upload date:
- Size: 23.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
020fa69575e4bb27aece3b4bea854ff80eab2a0a52b8d17c2f249210e7907fda
|
|
| MD5 |
185c5d2e6f63f8b5f508873de250dcc5
|
|
| BLAKE2b-256 |
ebfa4c9ef5bc896cd1a041f506e991946441ac8babd94816fb7aa93a69df86d3
|