Repository navigation
fix(parser): carry OpenDataLoader PDF positions through to parse items - #21450
Conversation
OpenDataLoader returned text but no geometry, so citations could not be highlighted or cropped. Convert each element's PDF-space bounding box into the canonical screen-space position row using its page size from pdfium, keeping page identity even when geometry is unavailable. Without cgo the text survives, page_count falls back to the service's reported total, and a warning records the missing geometry. Fixes infiniflow#21216
|
@coderabbitai review |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Load geometry and convert parsed elements internal/parser/parser/pdf_parser_opendataloader.go, internal/parser/parser/pdf_parser_opendataloader_cgo.go, internal/parser/parser/pdf_parser_opendataloader_nocgo.go, internal/parser/parser/pdf_parser_remote_common.go |
The parser requests geometry for reported page indexes and converts valid bounding boxes into screen-space positions. It clamps small overflows, warns once per page for larger overflows, preserves valid page numbers when positions are unavailable, and applies page-count fallbacks. |
Validate geometry behavior and existing table parsing internal/parser/parser/pdf_parser_opendataloader_cgo_test.go, internal/parser/parser/pdf_parser_opendataloader_nocgo_test.go, internal/parser/parser/pdf_parser_opendataloader_positions_test.go, internal/parser/parser/pdf_parser_opendataloader_test.go, internal/parser/parser/pdf_parser_table_contract_test.go, internal/parser/parser/pdf_table_no_html_text_test.go |
Tests cover geometry conversion, element types, missing or invalid geometry, clamping, warnings, page-count fallbacks, and parsing with and without cgo. Existing table tests use the geometry-aware conversion function with nil geometry. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested labels: integration, parsing, go, bug
Suggested reviewers: devyrpauli
Merge Risk: 
Minimal · up to a1fbf
-
No established position-parsing defect remains; the PR is mergeable after normal checks.
Pre-merge checks: 
4
-
Full details: Linked Issues check
-
Explanation
Issue
#21216requires page numbers and bounding boxes to produce 1-based[page, left, right, top, bottom]positions.openDataLoaderPageNumberreadspage number,page_number, andpage.openDataLoaderBoxreads the required box aliases.openDataLoaderPositionsconverts PDF coordinates with the pdfium page height and writes bothpositionsand_pdf_positionsfor table, image, formula, text, title, and heading items. The code keepspage_numberwithout geometry and preserves the existing type mapping and table-cell handling. It does not inline image payloads. Added tests cover conversion, fallback behavior, invalid boxes, warnings, item types, and nocgo behavior.
Full details: Out of Scope Changes check
-
Explanation
The changes remain within issue
#21216. The cgo/nocgo geometry split supports position lookup and the documented no-geometry behavior. Page-number collection and page-count fallbacks support the required page identity and result metadata. Tests update existing callers to the geometry-aware helper without changing their contracts. The changes do not add image payloads, alter unrelated element mappings, or implement the separate outline/TOC work.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks each bounding line,
And maps the page from top to base.
When geometry is out of reach,
Page numbers still keep their place.
Small edges tuck within the frame,
Clear positions mark each space.
Comment @coderabbitai help to get the list of available commands.
|
|
Ping for CI: no workflow run has ever been created for this PR (head Could someone approve and run the workflows for this head? The change is Go-only; the unit tier passes locally, and the real-service tiers are exactly what needs CI here. I will rebase and re-request if the head moves. |
|
The coordinate-space assumption is unverified, and the clamp silently masks failures. The PR treats OpenDataLoader's |
Clamping an out-of-page box silently turned a coordinate-space mismatch into a near-full-page highlight. Drop those positions and surface one warning per page instead; only genuine bleed is clamped.
|
Thanks — both points hold, and I have fixed the masking half of it in a1fbf04. Why the clamp was wrong. OpenDataLoader runs behind a tenant-supplied What the code does now. The clamp only covers genuine bleed (overflow beyond the page edge up to 10% of that page dimension, named in the message). Anything past that is treated as evidence the box is not in the page's point space: the positions for that element are dropped, and one warning per page is emitted with the offending box and the page size, e.g. Text and Why not the PaddleOCR scaling path. That adapter can scale because the OCR response carries its own raster dimensions ( Tests. If someone here knows the space the service actually returns, I will replace the heuristic with the real conversion rather than keep the guard. @coderabbitai review |
|
|
Heads-up for whoever is approving fork CI runs: The other open PRs from this account are still waiting on the same approval. Current state, from
One approval per PR releases its whole @xugangqiang @yuzhichang if it is easier to work the queue oldest-first, #21432/#21433/#21447/#21448 are the ones with no CI signal at all yet. |
|
Closing the coordinate-space question with the upstream contract rather than an assertion.
The adapter reads exactly those elements ( What that evidence does not buy us: One residual I have not verified: rotation. The vertical flip uses pdfium's post-rotation page size ( Head stays |
|
CI status on head That leaves the coordinate-space question from your review — I answered it from the upstream contract in the previous comment (positions are carried unmodified from the OpenDataLoader response, and the clamp is gone so out-of-range values surface instead of being masked). @xugangqiang could you take a look when you have a moment? |
|
LGTM |
yuzhichang
left a comment
There was a problem hiding this comment.
Review — head a1fbf04
Reviewed merge-base 176e91d..a1fbf04 and the call chain each hunk reaches: the ODL response path, pdfium.PageSizes, NormalizeResult/validPDFPositions, the crop consumers, and every caller/test touched by the openDataLoaderItems rename.
No blocking findings.
- Row order is right, and it is the part that decides whether this feature works at all.
openDataLoaderPositionsemits{page, left, right, size[1]-top, size[1]-bottom}from OpenDataLoader's y-up[left, bottom, right, top]; becausetop > bottom, the resultingscreenTop < screenBottomsatisfiespdfPositionIsUsable(pdf_result.go) and the y-down convention every existing producer and the cropper use. Degenerate boxes collapse to zero area and are dropped before emission rather than being emitted inverted. - Page identity is consistent across the three places it appears:
openDataLoaderPageIndexesreturnspage-1,pdfium.PageSizeskeys by the 0-based index, andopenDataLoaderPositionslooks uppageSizes[page-1].pageCountcomes fromFPDF_GetPageCountand is 0 only on a failed load, which is exactly the documented fallback trigger, andnormalizePDFPageCountcan only raise it. - No geometry, no wrong geometry: with
!cgoor a document pdfium rejects, items keep their page identity and carry no positions plus one warning; a box that does not fit the page beyond the 10% bleed band is reported per page and dropped instead of clamped into a plausible-looking wrong highlight. That is the correct trade for coordinates the adapter cannot verify. - Table metadata still lands:
projectPDFTableruns beforepage_numberis set, butNormalizeResultre-derivesTableData.Pagefrompage_numberafterwards, so ODL tables are not left on page 0. - Clean rename:
openDataLoaderItems/openDataLoaderPageCounthave no stale references and the affected tests were updated, including new cgo/nocgo/positions coverage. The shape matches the existing PaddleOCR adapter (same helper, same dual key alias, same warning channel). - The 10% band check is also what protects the rotated-page case in practice: a
/Rotate 90page usually trips it and degrades to no positions rather than mirrored ones.
Below the bar, for the record: under !cgo every OpenDataLoader parse adds the "geometry unavailable" warning, the geometry error text says "unavailable" even when a single requested page was out of range, and a cancelled context after geometry surfaces as a warning rather than ParseResult{Err} (PaddleOCR re-checks; ODL does not, and context is already ignored for the HTTP request on the base).
Summary
The OpenDataLoader PDF path read only text/structure from each element, so items never carried
positions/_pdf_positions: citations could not highlight the source PDF and no preview crop region existed. This ports the geometry that the service already returns.page number/page_number/page) and box (bounding box/bounding_box/bbox,[left, bottom, right, top]PDF points, bottom-left origin).[page, left, right, top, bottom]using the page height from pdfium (top = H - bbox_top,bottom = H - bbox_bottom), and write bothpositionsand_pdf_positionson every item type (table, image/figure, formula/equation, text/title/heading).page_number) even when geometry is unavailable, matching the PaddleOCR adapter.page_countcomes from pdfium; without geometry it falls back to the service's reported total, then the highest page number, then 1.Geometry is looked up through a cgo/nocgo split (
pdf_parser_opendataloader_cgo.go/_nocgo.go), mirroring PaddleOCR. Under nocgo the text is preserved unchanged, no positions are emitted, and one warning records that geometry is unavailable.Known limitations
/Rotate 90|270.Validation
CGO_ENABLED=0 go test ./internal/parser/parser/passes, including new tests for: screen-space conversion against a 612x792 page, every element type carrying positions, bleed clamped inside the tolerance, a foreign-space box dropping positions with a per-page warning, one warning per page on a mixed document, inverted/degenerate boxes dropped, page identity without geometry, and the page-count fallback chain.testdata/paddleocr_pages.pdfcomputes the expected screen-space values frompdfium.PageSizesand assertspage_count, but it could NOT be run on this macOS host: the parser package does not link here (missingoffice_oxideheaders / duplicate_office_*symbols, an environment issue also present on pristine main). CI must be the first cgo run.Fixes #21216