Skip to main content

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.

Metadata

Release files for rag-scrubber 0.1.4

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

Source distribution (sdist)

Source distribution for rag-scrubber 0.1.4
File Size Uploaded Provenance Actions
rag_scrubber-0.1.4.tar.gz 4.2 kB Without provenance Details for rag_scrubber-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rag-scrubber 0.1.4
File Interpreter ABI Platform Actions
rag_scrubber-0.1.4-py3-none-any.whl Python 3 none any Details for rag_scrubber-0.1.4-py3-none-any.whl

Total release size: 7.9 kB

Release files / rag_scrubber-0.1.4.tar.gz

Download URL rag_scrubber-0.1.4.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e6473b41dbd859c4b79710399d73a67e59cae6036813bdd5bc48a285b554ef0a
BLAKE2b-256 checksum
How to use checksums
d526880eddd3fa41ba2cf46eca547402d368be0d71eddc7181199f23d1483dbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / rag_scrubber-0.1.4-py3-none-any.whl

Download URL rag_scrubber-0.1.4-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97d4d35d7272201776cd470f57890adb434f2fff8b4637345f370965ff7a9af5
BLAKE2b-256 checksum
How to use checksums
ed5d722eecce018aa02474845844f51591297bb73e07ebeac6d3487e5016a8d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for rag-scrubber 0.1.4

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