TECHNOLOGY

Extract PDF tables for RAG: merged cells and repeated headers

In this article
THE QUICK TAKE

Merged headers, inherited units and footnotes must remain attached to table values when rows become retrievable evidence.

PDF tables need their header relationships and merged-cell scope preserved before they become RAG evidence. Exporting visible cell text alone can attach the wrong unit, product variant or operating condition to a value, even when every individual character was extracted correctly.

Preserve the table as a structured object

The official Docling table export example shows table extraction and export. The document model retains structured table information and provenance. Keep this representation before flattening to prose or Markdown. A merged heading may apply to several columns, while a stub heading may describe several rows. Reading cells as an undifferentiated list loses those relationships and creates ambiguous standalone values.

Build a merged-header fixture

Use a specification table with separate product variants and a heading spanning several operating conditions. Include a unit in the header and a footnote limiting one row. Compare the extracted structure to the source image before indexing. The question should require both a value and its condition, so merely finding a nearby number is insufficient to pass the fixture.

Source featureEvidence that must survive
Merged variant headingWhich subordinate columns it governs
Unit in a headerUnit attached to each derived value
Repeated page headerContinuation rather than a new data row
Footnote markerQualification linked to the affected value

Distinguish continuation from duplication

A long table may repeat its header after a page break. Removing repeated strings blindly can delete a meaningful row, while keeping every repeated header as data pollutes retrieval. Preserve table identity and page provenance, then inspect whether the continuation has the same columns. Do not merge separate tables solely because their headers look alike; captions and section scope can identify different conditions.

Compare extraction paths on the same page

The PyMuPDF Page reference documents another table extraction interface. Treat alternative extractors as candidates with different outputs, not interchangeable truth sources. Compare row boundaries, spans, empty cells and footnotes on the same fixture. An empty cell might mean inherited scope, an absent measurement or a deliberately blank value. Filling it automatically can create a specification the source never stated.

Serialize self-contained table evidence

A retrieved row should carry table title, variant, applicable headers, unit, qualification and source location. Keep the structured original available to resolve ambiguity. Evaluate questions that distinguish adjacent variants and ask about qualified exceptions. Report unresolved spans rather than silently guessing their scope. The resulting evidence becomes longer than bare cell text, but it preserves the relationships needed for a defensible answer and a meaningful page citation.

Related reading: A GPU OCR pipeline for a 1,000-page PDF workload; PaddleOCR on GPU: validating installation and document quality.

← All articles