Brifing

PDF Document Structure Engineering: Outline Recovery for RAG Systems

Automated table of contents generation from typography in headerless PDFs

Towards Data Science3 min

1The Structure Challenge in RAG

Structured RAG pipelines require document tables of contents for efficient retrieval and chunking. However, PDFs exported directly from LaTeX often lack native outlines. This method leverages typographic cues in body text - section headings typically appear larger and bolder. These visual patterns enable automatic heading detection without relying on existing TOC data, significantly expanding the range of processable documents in enterprise environments.

2Six Deterministic Signals

The system analyzes six typographic signals for heading detection: font size ratio, boldness, numeric prefix presence, short length, left alignment, and preceding blank line. Each signal scores 0-1, with numeric prefixes being the strongest indicator (1.6 weight). Font size ratio follows at 1.4 weight. These signals combine to create a robust detection mechanism that works across various document formats and layouts.

3Candidate Identification Process

Signals combine through weighted summation (total weight 5.8) with a 3.0 threshold. In tests on the Attention paper, this identified 24 heading candidates (21 true, 3 false positives from bold table cells). The LLM validation layer subsequently filters false positives. This two-stage approach balances computational efficiency with accuracy, particularly valuable for processing large document volumes.

4Four-Stage Cascade Architecture

The system employs a cascading approach: native TOC, text TOC, LLM analysis, and body typography - progressing only when prior methods fail. Typography analysis is computationally intensive (potentially requiring multiple LLM passes) and therefore optional. For documents known to lack contents pages, the reconstruct_toc_from_body function can be called directly, bypassing earlier stages.

5Mistral OCR Exception

Documents processed through Mistral OCR arrive in markdown format with #-based heading structure. This bypasses typographic analysis entirely, representing a significant optimization path. The parser matrix includes a dedicated shortcut column for this case, reducing processing overhead when dealing with OCR-converted documents.

6Data Model Consistency

The generated toc_df conforms to the Article 5B standard structure, ensuring compatibility with existing retrieval, chunking and summarization components. The model takes line_df and span_df inputs, enriches them with typographic metadata, and outputs structured data containing section headings, levels, and positional information - maintaining pipeline continuity.

7Signal Combination Rationale

No single signal proves definitive - bold/large text might catch figure captions; numeric prefixes could capture enumerated lists. Weighted combination mitigates these issues. The weights reflect domain knowledge rather than machine learning, making the system more interpretable and easier to debug. This approach demonstrates 92% precision in enterprise document testing.

8Implementation Scenarios

The method addresses four core scenarios: 1) No TOC data exists, 2) Only printed TOC present, 3) Native TOC is corrupted, 4) Clear typographic headings exist. Practical implementation processed paper 1706.03762v7.pdf into a 24-entry toc_df, with all steps traceable through interactive notebooks - valuable for both production use and developer education.

9Performance Optimization

The cascade architecture prioritizes least-expensive methods first. Typography analysis, being most resource-intensive, runs last. Clean deterministic signals may require just one LLM pass, while complex cases need multiple. Users control method selection via parameters, enabling optimization for specific document characteristics or processing constraints.

10Evolution from Prior Work

Article 5septies handled TOC reconstruction from existing contents pages. This work targets documents lacking any TOC information. Previous classification as summarization gave way to detection framing, as typographic analysis produces structured outputs with fixed schemas rather than free-form summaries. This shift reflects the method's role in enterprise document processing pipelines.

11Enterprise Applications

As part of the Enterprise Document Intelligence series, this completes the document parsing component in a four-part RAG architecture. Particularly valuable for financial, legal and academic institutions processing unstructured document volumes. Example notebooks demonstrate processing a 24-heading academic paper with just 3 false positives - later filtered by LLM validation.

12Future Directions

The method addresses a critical gap in document intelligence, especially effective for legal documents and technical reports with high structural integrity. Future enhancements may include more nuanced typographic analysis and multilingual support. Early adopters report up to 40% efficiency gains in enterprise RAG systems processing complex document collections.

Original article: Towards Data Science — PDF Doküman Yapısını Düzenleme: RAG için Başlık Çıkarımı