A Field Guide to What Happens Before Your RAG Index Reads a Document

Leader ●1 ●7 ●34
calendar_today ago • schedule5 min read
— Originally published at www.uglypear.com

Most post-mortems on underperforming RAG systems end at the same place, and it is never the model. It is the intake. The documents that entered the index were unreadable, unversioned, unsanitized or unpermissioned, and no amount of prompt engineering can un-poison a corpus. This is a field guide to the layer that gets skipped: what should happen to a document between "someone dropped it in the folder" and "it became retrievable context."

The lens here is operational, not academic. Every practice below is something you can audit on an existing system this week.

The data backdrop, briefly

Two numbers frame the problem. IDC puts global data at roughly 149 to 180 zettabytes for 2024, on a path to 394 zettabytes by 2028, with unstructured content at 80 to 90 percent — precisely the material enterprises want to make queryable. Meanwhile, knowledge-management research reports that 65 percent of employees spend at least an hour weekly recreating existing information (5.68 hours on average), discovering in half the cases that the document already existed. Global scale plus local duplication equals an index full of competing, unmarked versions of the same facts.

Stage one: extraction sets the ceiling

Extraction is where format luck is spent. Clean digital PDFs mostly parse fine. The trouble starts with complex layouts — multi-column reports, nested tables — where reading order and table structure are easily destroyed, and bottoms out with scans.

The canonical stress test: a stamped contract with handwritten margin notes. If extraction merges the seal graphics, the annotations and the clauses into one stream, the misordering propagates silently. Nothing errors out. The text simply lies, and every chunk built from it inherits the lie.

Audit method: pick your ten worst files (scans, dense tables, mixed layouts), run them through your current pipeline, and read the parsed output yourself. If you wouldn't trust it as a source, neither will the model.

Stage two through four: cleaning, redaction, compression

Cleaning removes headers, footers, template boilerplate and stray characters. Low drama, real payoff: retrieval attention is finite, and boilerplate occupies it without contributing semantics.

Redaction is compliance work disguised as preprocessing. Categories like ID numbers, account numbers, contact details and internal pricing need detection and masking before ingestion, not after a leak. Public specifications in mature products cover on the order of 13 sensitive-information categories (UglyPear Data's documentation, for instance, states 13), and IBM's 2025 security research adds urgency: one in five enterprises has experienced data exposure through employee use of shadow AI tools, with breach costs running about 670,000 USD above peer averages. A knowledge base that accepts unredacted documents is a shadow-AI incident with a better interface.

Compression targets embedded images and redundant formatting. Stated publicly and reproducibly: expect roughly 60 to 80 percent size reduction with body text intact. The savings compound — faster parsing, faster retrieval, and lower token cost on every context window you assemble. This is one of the few pipeline stages whose ROI is immediately measurable per query.

Stage five: chunking and the parent-child compromise

Chunk granularity decides whether an answer has context or a context-free fragment. Too fine, and the model receives orphaned sentences; too coarse, and retrieval precision collapses.

The widely adopted compromise is parent-child chunking: index and retrieve small, precise units, but when assembling the context window, substitute the parent section so the model reads with surrounding structure. If your current system has a single flat chunk size for all document types, that alone is worth investigating.

Stage six: permissions and lifecycle

Two questions decide whether a knowledge base survives its first year:

  • Does authorization apply at retrieval time, with granularity fine enough to matter (down to content fragments, not just whole files)?
  • What happens to expired, superseded and orphaned documents?

A system where permissions are a display-layer afterthought leaks; a system without lifecycle management gradually fills with stale answers that outrank fresh ones. Both failure modes are invisible until someone checks.

Observability: the difference between a pipeline and a vending machine

Long-batch ingestion — the legacy-batch migration every enterprise eventually runs — needs three operational properties: visible progress for any batch, failure tracing down to the specific file and step, and rollback for mistaken runs. Modern preprocessing stages in established offerings (progress visualization, per-file failure localization, rollback and re-run) exist precisely because "start the batch and pray" does not scale past a few thousand files.

The economics of human oversight argue the same way. Attention research puts re-focus time after an interruption at roughly 23 minutes, and average daily application switching at 35. Manual inspection of ingestion quality does not survive contact with those numbers.

Evaluation: a golden set beats a feeling

The discipline that ties the stages together:

  1. Build a golden set — questions with known answers, sized honestly (50 is fine to start).
  2. After every change to intake logic, chunking parameters or retrieval configuration, rerun and record hit rates.
  3. Adversarially seed batches with corrupted files and obviously sensitive content; verify interception and that permission filtering fires at retrieval time.
  4. Document failure boundaries: the quality threshold below which a file is refused rather than ingested, and the behavior expected there (skip and report, never invent).

Treat these as regression tests for the corpus. A knowledge base whose quality can be expressed as a tracked number is operated; one that can't is merely hosted.

Incremental remediation: a playbook for the index you already have

Few teams get to design intake from scratch. Most inherit an index that already contains two years of unvetted documents. Deleting and rebuilding is emotionally satisfying and operationally wrong — you lose the only artifact users still semi-trust and restart the clock on every integration built around it.

The workable pattern is incremental remediation with continuous availability:

  1. Snapshot the current index. Every downstream step must be reversible against this baseline; without rollback, a bad remediation batch becomes an outage.
  2. Rank existing content by blast radius: scanned contracts and anything with pricing or personal data first, boilerplate last.
  3. Re-run intake per batch — re-parse, re-redact, re-chunk — with observability active so failures trace to files and steps in real time.
  4. Gate each swap-in on the golden set: if post-remediation hit rates regress, the batch stays out. Numbers decide, not intuition.
  5. Promote whatever workflow the remediation used into the default path for new documents. A cleanup pipeline that only exists during cleanup is a process that will be re-bought in eighteen months.

Expect the first two batches to be diagnostic as much as corrective: they reveal where parsing failures cluster, which document families carry the sensitive data, and where version confusion concentrates. By batch three, the team usually holds a written map of its own data hygiene that is more useful than any external audit.

A selection checklist for teams evaluating tools

  • Ask for sample parsed output on your worst real files, not on vendor demo data.
  • Confirm redaction category coverage and per-category configurability.
  • Verify batch observability: progress, per-file failure tracing, rollback.
  • Confirm the evaluation workflow exists or at least that intermediate artifacts are exportable for your own tests.
  • Pin down the data boundary: can the entire pipeline run inside your network, with nothing leaving it? For corpora containing contracts, pricing, HR and research material, private deployment is not paranoia — it is scoping.

Closing the loop

The layer before the index is where answer quality is decided, and it rewards unglamorous diligence: honest extraction tests, category-based redaction, compression before ingestion, parent-child chunking, retrieval-time permissions, observable batches, and a golden set that turns quality into arithmetic. Do those, and the model conversation changes character — because for the first time, the model is being asked to explain clean material.

Want more #aiagents & #rag deep dives?

Join 6,049+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

Part 5 of 5 in AI Engineering

1 Comment

0 votes

More Posts

What Security Teams Want From AI Agents Before They Let Them Act Alone

Tom Smithverified - Nov 18

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23

Architecting a Local-First Hybrid RAG for Finance

Pocket Portfolio - Feb 25

Sovereign Intelligence: The Complete 25,000 Word Blueprint (Download)

Pocket Portfolio - Apr 1

The Privacy Gap: Why sending financial ledgers to OpenAI is broken

Pocket Portfolio - Feb 23
chevron_left
1.9k Points • 42 Badges
24Posts
4Comments
8Connections
High-performance document compression × RAG data engineering. We turn scattered contracts, reports a... Show more

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
3 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!