Skip to content

feat: optionally preserve page numbers when concatenating - #709

Open
ZhiyaoWen999 wants to merge 1 commit into
docling-project:mainfrom
ZhiyaoWen999:fix/preserve-concatenate-page-numbers
Open

feat: optionally preserve page numbers when concatenating#709
ZhiyaoWen999 wants to merge 1 commit into
docling-project:mainfrom
ZhiyaoWen999:fix/preserve-concatenate-page-numbers

Conversation

@ZhiyaoWen999

Copy link
Copy Markdown

Summary

  • add an opt-in preserve_page_numbers argument to DoclingDocument.concatenate()
  • preserve page keys, PageItem.page_no, item provenance, and key-value/form graph-cell provenance when enabled
  • reject overlapping input page numbers instead of silently replacing pages
  • keep the existing continuous renumbering behavior as the default

Motivation

_DocIndex.index() always calculates a page offset that shifts every input document into a continuous sequence. This also shifts the first chunk when its original page range does not start at page 1, so callers processing PDF page ranges in parallel lose the source page numbers after concatenation.

The new opt-in mode uses a zero page offset after checking that the input ranges do not overlap. Existing callers are unaffected.

Closes docling-project/docling#3890.

Validation

  • targeted concatenate and filter tests: 6 passed
  • Ruff lint and format checks
  • MyPy on the changed implementation and tests
  • issue fixtures: pages 5–10 and page 11 concatenate to pages 5–11; the 3,723-item result passes JSON serialization and model validation

Signed-off-by: Zhiyao Wen <75983327+ZhiyaoWen999@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

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

@mergify

mergify Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

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)(?:\(.+\))?(!)?:

@ZhiyaoWen999
ZhiyaoWen999 marked this pull request as ready for review August 4, 2026 09:51
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ceberam ceberam added the enhancement New feature or request label Aug 13, 2026

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dolfim-ibm dolfim-ibm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PR looks good, but we want to hold until we do a full integration testing on the Docling CLI behavior and the Docling Serve API

the expected behavior is indeed, for example, that setting page_range=(10,20) will produce an output starting at page 10.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bee] Make function 'concatenate(docs)' keep the original page no to support page range

3 participants