Skip to content

[Bee] reading order step crash because of _has_sequence_interruption in reading_order_rb.py #3940

Description

@yqliving

Bug

When the layout model generated clusters almost sharing the boundaries, you may get the error in reading_order_rb.py, for example, i.bottom=302.7814025878906, j.top=302.78204345703125

self._init_ud_maps(page_elements, state)\n  File \"/usr/local/lib/python3.12/site-packages/docling_ibm_models/reading_order/reading_order_rb.py\", line 360, in _init_ud_maps\n    if not self._has_sequence_interruption(\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.12/site-packages/docling_ibm_models/reading_order/reading_order_rb.py\", line 386, in _has_sequence_interruption\n    candidates = list(spatial_idx.intersection((x_min, y_min, x_max, y_max)))\n                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib64/python3.12/site-packages/rtree/index.py\", line 809, in intersection\n    p_mins, p_maxs = self.get_coordinate_pointers(coordinates)\n                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib64/python3.12/site-packages/rtree/index.py\", line 359, in get_coordinate_pointers\n    raise RTreeError(\nrtree.exceptions.RTreeError: `Coordinates must not have minimums more than maximums`

Root Cause of the Bug

pelem_i.b = 302.7814025878906, pelem_j.t = 302.78204345703125
The is_strictly_above check (called before _has_sequence_interruption) uses an epsilon of 0.001 --> passed
_has_sequence_interruption: y_min = 302.78204345703125, y_max = 302.7814025878906 → y_min > y_max → crash

Fix:

in function _has_sequence_interruption around line 386: add two lines:

y_min, y_max = min(y_min, y_max), max(y_min, y_max)
x_min, x_max = min(x_min, x_max), max(x_min, x_max)

Docling version

docling: 2.107.0
docling-ibm-models==3.13.0

Python version

3.12
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions