Feature request: the document without table structure from the same conversion (one layout pass)

Open
#5,437 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
ai, backend

Research direction

Read the PageAssembleModel and ReadingOrderModel behavior described in the issue, then inspect Page.assembled and StandardPdfPipeline._assemble_document to find a suitable public API. Compare the proposed result with a separate conversion using do_table_structure=False, including Markdown output, page count, tables, pictures, and page numbering; done means the public path matches that conversion without running another model pass.

Written by the indexing model from the issue text.

Description

enhancement pdf priority:medium
Requested feature

A public way to get, from one PDF conversion, the document with table structure (TableFormer) and the same document without it (what do_table_structure=False produces). Today the only public way to get both is to convert twice, which runs the layout model over every page twice.

Use case

A scientific-paper ingestion pipeline keeps two Markdown exports per paper:

  • the table-structured one, for tables;
  • the unstructured one, whose text is the stored, hashed source for downstream steps (sections, page-1 metadata).

Changing the unstructured export would invalidate everything stored from it, so it must stay byte-identical. Converting twice per paper costs roughly a quarter of the conversion time on our CPU-only hosts: the layout pass runs twice.

What we found (Docling 2.143.1, docling-core 2.105.0)

Without a table-structure prediction, PageAssembleModel falls back to Table(otsl_seq=[], table_cells=[], cluster=cluster, ...). ReadingOrderModel then adds the cluster's children under the table as a group. So after a conversion with do_table_structure=True, the unstructured document can be rebuilt without running any model:

result = converter.convert(source)          # do_table_structure=True
structured = result.document
for page in result.pages:
    if page.assembled is None:
        continue
    swap = {id(e): Table(label=e.cluster.label, id=e.cluster.id, text="", otsl_seq=[], table_cells=[],
                         cluster=e.cluster, page_no=page.page_no)
            for e in page.assembled.elements if isinstance(e, Table)}
    for name in ("elements", "body", "headers"):
        setattr(page.assembled, name, [swap.get(id(e), e) for e in getattr(page.assembled, name)])
pipeline = converter._get_pipeline(InputFormat.PDF)
unstructured = pipeline._assemble_document(result).document

On the papers we checked (19 and 46 pages, 12 and 29 tables), the export_to_markdown() of unstructured is identical to a separate do_table_structure=False conversion, including page_no=1. So are num_pages(), the table items (1×1 data plus the child group) and the picture items. The re-assembly takes 1–3 s.

It relies on two internals, Page.assembled and StandardPdfPipeline._assemble_document, so it can break on any release.

Proposal

One of these as public API, whichever fits the design better:

  1. a PdfPipelineOptions flag (for example also_produce_unstructured_tables: bool) that adds a second document to the ConversionResult; or
  2. a public method, for example StandardPdfPipeline.reassemble(conv_res, table_structure=False) -> DoclingDocument (or on ConversionResult), documented as running no model.

We are happy to open a PR for either, with a test that compares against a do_table_structure=False conversion.

Alternatives considered
  • Two conversions: what we do today, at the cost of a second layout pass.
  • A custom Markdown table serializer over the structured document: public API, but the output is not identical to the unstructured conversion. The cell order and tokenization differ.
Dominant language
Python
Stars
71k
Forks
5.4k
Avg merge
2d 22h
Merged PRs (30d)
161

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from docling-project/docling

All issues in docling-project/docling

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.