Skip to main content

Auto-removes headers, footers, and noise from PDF text for RAG apps.

Project description

rag-scrubber

Clean your "dirty" PDF text before feeding it to LLMs.

rag-scrubber is a lightweight Python library designed for RAG (Retrieval-Augmented Generation) pipelines. It automatically detects and removes recurring headers, footers, and page numbers from extracted text, and fixes broken hyphenation.

😟 The Problem

When extracting text from PDFs (especially corporate reports or scanned docs), you often get artifacts that confuse LLMs:

"The Q3 revenue was CONFIDENTIAL REPORT 2024 higher than expected..."

These interruptions waste tokens and degrade model performance. rag-scrubber cleans this mess up.

✨ Features

  • Auto-Header/Footer Removal: Uses positional statistics to detect lines that repeat across pages (e.g., "Page 1 of 50", "Confidential").
  • Smart De-Hyphenation: Fixes words split across lines (e.g., com- + puter computer) without merging proper nouns.
  • Zero-Shot Configuration: Works out of the box with sensible defaults, or tune the sensitivity yourself.
  • Lightweight: No heavy ML dependencies. pure Python logic.

📦 Installation

pip install rag-scrubber

🚀 Quick Start

from rag_scrubber import RAGScrubber

# 1. Simulate dirty text (usually coming from PyPDF2 or PDFMiner)
pages = [
    "Q3 FINANCIAL REPORT - CONFIDENTIAL\nThe revenue increased by 20%.\nPage 1",
    "Q3 FINANCIAL REPORT - CONFIDENTIAL\nOperating costs were lowered.\nPage 2",
    "Q3 FINANCIAL REPORT - CONFIDENTIAL\nNew user acquisition is sta-\nble.\nPage 3"
]

# 2. Initialize the scrubber
# threshold=0.4 means if a line appears in >40% of pages, it's garbage.
scrubber = RAGScrubber(threshold=0.4)

# 3. Clean the text
clean_text = scrubber.clean(pages)

print(clean_text)

Output:

The revenue increased by 20%.

Operating costs were lowered.

New user acquisition is stable.

⚙️ Advanced Usage

You can adjust the sensitivity if it is deleting too much (or too little).

# Low threshold (0.1) = Very aggressive (removes anything that repeats even slightly)
# High threshold (0.9) = Very safe (only removes exact matches on almost every page)
scrubber = RAGScrubber(threshold=0.2) 

🤝 Contributing

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/new-logic).
  3. Commit your changes.
  4. Push to the branch.
  5. Open a Pull Request.

📄 License

MIT License. Free to use for commercial and personal projects.

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

rag_scrubber-0.1.3.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

rag_scrubber-0.1.3-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file rag_scrubber-0.1.3.tar.gz.

File metadata

  • Download URL: rag_scrubber-0.1.3.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for rag_scrubber-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9367ce6e1295d607e3e07428f511e6e813e09c0339e8324964cd23ee300d2214
MD5 115990180c4ebf4ca4cd8a3d1babf564
BLAKE2b-256 857460c815b7a6754131bd6450f64c4dc0091f9ee67c4b4a321ba06bf27fa0bf

See more details on using hashes here.

File details

Details for the file rag_scrubber-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: rag_scrubber-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for rag_scrubber-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c31744fe86f4c7a07bda01e78adbd9982b78b9f6908fe6b32d1f4e514ff1ce1c
MD5 b4133e69daaae97b54620bdfbff929a7
BLAKE2b-256 2f0828e93c8f39455924bc1c23e37e9e3d4033ddac0d09629ef695fb1a60f645

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