Skip to main content

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

noirag-1.0.1.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

noirag-1.0.1-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file noirag-1.0.1.tar.gz.

File metadata

  • Download URL: noirag-1.0.1.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

Hashes for noirag-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b49be8d08d15b3790a244dc6be1447a925a3fba79db15fc26d8450ac655995aa
MD5 2db1d7d6fe3b90065f0d2568eb54f582
BLAKE2b-256 54a7670d37dcb13ea0b43e35d3ad231c8c7ef6f788d44f510c338e2c14a27550

See more details on using hashes here.

File details

Details for the file noirag-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: noirag-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for noirag-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f4c72bd37dc9b5fb0df1f7ed3878a1e36c59067d41472952d34c6b8802ebc95
MD5 cc97b4713ff901074b835e7a1badc9aa
BLAKE2b-256 62e8becfc1febb4e8dce6c8beb12aa222117333b03f9f76815dd422dbd200f78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page