Skip to main content

🧹 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.

Python Streamlit FAISS License


📌 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

Metadata

Release files for noirag 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for noirag 1.0.2
File Size Uploaded Provenance Actions
noirag-1.0.2.tar.gz 22.8 kB Without provenance Details for noirag-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for noirag 1.0.2
File Interpreter ABI Platform Actions
noirag-1.0.2-py3-none-any.whl Python 3 none any Details for noirag-1.0.2-py3-none-any.whl

Total release size: 46.4 kB

Release files / noirag-1.0.2.tar.gz

Download URL noirag-1.0.2.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dd2356781788dd8f395695d120631bcd80a2fcad8ec62df7f246275b94154e53
BLAKE2b-256 checksum
How to use checksums
617bd9b2b960c4bdeee14224955e2a0ee3ac1c2e3fde036ca6556780ace88b6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.5

Release files / noirag-1.0.2-py3-none-any.whl

Download URL noirag-1.0.2-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
020fa69575e4bb27aece3b4bea854ff80eab2a0a52b8d17c2f249210e7907fda
BLAKE2b-256 checksum
How to use checksums
ebfa4c9ef5bc896cd1a041f506e991946441ac8babd94816fb7aa93a69df86d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.5

Security for noirag 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page