docling-java icon indicating copy to clipboard operation
docling-java copied to clipboard

[Improvement] Support PDF heading hierarchy inference (HeadingHierarchyOptions) in ConvertDocumentOptions

Open Krambamboli opened this issue 1 month ago • 8 comments

Description

In Python Docling (docling.datamodel.pipeline_options.PdfPipelineOptions), HeadingHierarchyOptions (heading_hierarchy_options) allows reconstructing a true H1 -> H6 heading tree from PDF bookmarks, outline numbering (1.1, 1.2.1), and font/visual styles instead of emitting all detected section_header elements flat at level 1:

from docling.datamodel.pipeline_options import HeadingHierarchyOptions, PdfPipelineOptions

pipeline_options = PdfPipelineOptions(
    heading_hierarchy_options=HeadingHierarchyOptions(
        enabled=True,
        max_level=6,
        use_bookmarks=True,
        use_numbering=True,
        use_style=True,
        use_font_style=True,
    )
)

Currently, there is no way to enable or configure HeadingHierarchyOptions via ConvertDocumentOptions in docling-java (nor via a DOCLING_SERVE_* container environment variable).

Why this is important for Java RAG pipelines

When using docling-java with Spring AI or LangChain4j for RAG ingestion, structure-aware chunkers (HybridChunker / HierarchicalChunker) rely on the document's heading levels to group sections and build hierarchical metadata paths (e.g., Chapter 1 > 1.2 Methodology). Without HeadingHierarchyOptions, PDF headings frequently remain flat at level 1.

Proposed Change

Expose heading hierarchy configuration in ConvertDocumentOptions (and the underlying docling-serve options schema), e.g.:

  • doHeadingHierarchy(Boolean) / headingHierarchyOptions(HeadingHierarchyOptions) (enabled, maxLevel, useBookmarks, useNumbering, useStyle, useFontStyle).

Krambamboli avatar Oct 22 '26 12:10 Krambamboli

Thanks @Krambamboli for this issue! I'll get working on it!

edeandrea avatar Oct 22 '26 12:10 edeandrea

@all-contributors add @Krambamboli for ideas

edeandrea avatar Oct 22 '26 16:10 edeandrea

@edeandrea

This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected string in JSON at position 6440

allcontributors[bot] avatar Oct 22 '26 16:10 allcontributors[bot]

@all-contributors add @Krambamboli for ideas

edeandrea avatar Oct 22 '26 16:10 edeandrea

@edeandrea

I've put up a pull request to add @Krambamboli! :tada:

allcontributors[bot] avatar Oct 22 '26 16:10 allcontributors[bot]

🎉 This issue has been resolved in v0.7.1 (Release Notes)

docling-java-ops[bot] avatar Oct 22 '26 17:10 docling-java-ops[bot]

@edeandrea Thank you so much for the fast response, I really appreciate it. This makes our ingestion pipeline way better.

Krambamboli avatar Oct 23 '26 09:10 Krambamboli

You're very welcome! Keep the reports coming! Its hard to keep up with Docling's pydantic model. Everything is manual unfortunately.

edeandrea avatar Oct 23 '26 11:10 edeandrea