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.4.tar.gz (4.2 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.4-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rag_scrubber-0.1.4.tar.gz
  • Upload date:
  • Size: 4.2 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.4.tar.gz
Algorithm Hash digest
SHA256 e6473b41dbd859c4b79710399d73a67e59cae6036813bdd5bc48a285b554ef0a
MD5 90210e208ca58d7e276ec79b7212a0dd
BLAKE2b-256 d526880eddd3fa41ba2cf46eca547402d368be0d71eddc7181199f23d1483dbc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rag_scrubber-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 97d4d35d7272201776cd470f57890adb434f2fff8b4637345f370965ff7a9af5
MD5 4c6e9bc6c69335e49db9e62a1336f564
BLAKE2b-256 ed5d722eecce018aa02474845844f51591297bb73e07ebeac6d3487e5016a8d0

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