Ingestion

Document parsing for RAG: PDFs, scans, and tables

Garbage in, garbage out is not a cliché in RAG — it's the primary failure mode. If the parser loses a table header or scrambles reading order, no embedding model or reranker can recover the meaning.

Know what kind of PDF you have

TypeSignalApproach
Digital textSelectable textDirect extraction with layout
Scanned imageNo text layerOCR (Tesseract, cloud OCR)
HybridSome pages text, some imagePer-page detection
Born-digital complexColumns, tables, footnotesLayout-aware parser

Check per page, not per document. A single scanned appendix can silently break retrieval for an otherwise clean file.

Reading order is the hidden problem

A PDF stores glyphs, not paragraphs. Naive extraction often produces text in the wrong order — especially with two-column layouts, sidebars, headers, and footers.

Checks that catch it:

  • Does the first extracted sentence make grammatical sense?
  • Are page headers repeated inside paragraphs?
  • Do list items appear before their introduction?
  • Do footnotes interrupt body text?

Tables

A table row without its header is meaningless. Preserve structure explicitly:

Table: Refund schedule
| Plan     | Window | Refund     |
|----------|--------|------------|
| Annual   | 14 days| 100%       |
| Monthly  | 7 days | Prorated   |

Convert each row into a self-contained sentence when possible:

"Annual plans may be refunded 100% within 14 days."

This makes the row retrievable and interpretable on its own.

OCR is not free quality

OCR introduces character errors that break exact-match retrieval. Common fixes:

  • Use a modern OCR engine, not a 2015 baseline.
  • Store a confidence score per page; flag low-confidence pages for review.
  • Keep the page image reference so a human can verify.
  • Normalize whitespace and hyphenation before chunking.

Metadata to extract

Every chunk should inherit:

  • Document title and id
  • Section or clause number
  • Page number
  • Document type
  • Effective / modified date
  • Access-control labels

These enable filtering, citation, and audit — three things that separate a demo from a system.

Parsing quality checklist

  • Sample 20 pages manually and read them.
  • Verify tables survive as tables.
  • Verify headings map to sections.
  • Check that no page is silently empty.
  • Confirm scanned pages were OCR'd, not skipped.
  • Compare extracted text length to expected length.

Rule: spend a day on parsing before spending a week on prompts. Parsing errors are permanent; prompt tweaks are not.

Messy PDFs breaking your retrieval?

I audit the ingestion pipeline and rebuild parsing and chunking with verifiable structure.

Book a diagnostic