Skip to content

feat: honour a reading order supplied by an upstream stage - #4153

Draft
wittjeff wants to merge 1 commit into
docling-project:mainfrom
wittjeff:feat/supplied-reading-order
Draft

feat: honour a reading order supplied by an upstream stage#4153
wittjeff wants to merge 1 commit into
docling-project:mainfrom
wittjeff:feat/supplied-reading-order

Conversation

@wittjeff

@wittjeff wittjeff commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Implements the mechanism proposed in #3958: let a stage upstream of reading order supply the order of a page, instead of the reading-order stage recomputing it.

What

Rules

  • A page is all-or-nothing. One element without an index on a page disqualifies the page and the indices that are present are ignored, rather than interleaving two orderings. A finer merge can come later if a real case needs it.
  • No index anywhere means no behaviour change: the predictor is called exactly as before with the same input.
  • Ties between equal indices break on assembled order.

Relation to #3233

reorder_elements=False there is the degenerate case where postprocessor order is the supplied order for every page. This PR does not add that flag; it can be layered on top, or #3233 rebased onto this.

Tests

tests/test_readingorder_supplied_order.py:

  • a fully indexed page follows the supplied order even when it contradicts geometry, and the same fixture without indices follows the predictor;
  • a page with one unindexed element is predicted whole;
  • a supplied page and a predicted page keep page order;
  • children of a container are ordered among themselves by their indices, independently of the page's top-level elements.

No in-tree producer sets the index yet; the tagged-structure stage in #4148 is the first consumer and will be rebased onto this once the field name and the per-page rule are agreed.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

🤖 Generated with Claude Code

Some stages already know the order of a page: a layout model that
predicts reading order (docling-project#3958), the structure tree of a tagged PDF, or
native form widgets. Add Cluster.reading_order and let the reading-order
stage sort any page whose every element carries an index by that index,
per sibling group, while pages with any unindexed element go through the
predictor as before. Caption, footnote and merge mapping still run on
the combined result. No index anywhere means no behaviour change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Jeff Witt <1848307+wittjeff@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @wittjeff, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant