Skip to content

fix(parser): carry OpenDataLoader PDF positions through to parse items - #21450

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
ccclucky:fix/21216-odl-positions
Oct 28, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
ccclucky:fix/21216-odl-positions

Conversation

@ccclucky

@ccclucky ccclucky commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Read each element's page number (page number / page_number / page) and box (bounding box / bounding_box / bbox, [left, bottom, right, top] PDF points, bottom-left origin).
  • Convert to the canonical 1-based screen-space row [page, left, right, top, bottom] using the page height from pdfium (top = H - bbox_top, bottom = H - bbox_bottom), and write both positions and _pdf_positions on every item type (table, image/figure, formula/equation, text/title/heading).
  • Guard the coordinate-space assumption instead of hiding it: a box that overflows the page by more than 10% of that dimension is not treated as bleed — its positions are dropped and one warning per page names the box and the page size, so a service returning another coordinate space surfaces instead of becoming a near-full-page highlight.
  • Keep page identity (page_number) even when geometry is unavailable, matching the PaddleOCR adapter.
  • page_count comes 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

  • The Y flip assumes OpenDataLoader boxes and pdfium page sizes share the same post-rotation page space. No rotated fixture was available to verify /Rotate 90|270.
  • The service's coordinate space cannot be read from its response (no page-size field, unlike the PaddleOCR response), so it is validated against the pdfium page rectangle rather than converted by a known ratio.
  • Image payloads are still not inlined into the parse result; only positions are added (the on-demand VLM/chunker crop contract is unchanged).

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.
  • A cgo test against testdata/paddleocr_pages.pdf computes the expected screen-space values from pdfium.PageSizes and asserts page_count, but it could NOT be run on this macOS host: the parser package does not link here (missing office_oxide headers / duplicate _office_* symbols, an environment issue also present on pristine main). CI must be the first cgo run.
  • No end-to-end OpenDataLoader server was available locally; the nocgo tests use an httptest server.

Fixes #21216

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
@ccclucky

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b0068d1-81d0-48b5-b9df-995b7d2ef58f
Commits

Reviewing files that changed from the base of the PR and between 8516b70 and a1fbf04.

Files selected for processing: 5
  • internal/parser/parser/pdf_parser_opendataloader.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

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The OpenDataLoader PDF parser now retrieves PDF page geometry and uses it to convert valid element bounding boxes into screen-space positions. It preserves page numbers when positions are unavailable and applies page-count fallbacks.

Changes: OpenDataLoader PDF position parsing

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: Normal

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: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: carrying OpenDataLoader PDF positions into parsed items. It is concise and specific.
Description check Passed The description includes the required Summary section and explains the problem, implementation, behavior, limitations, validation, and linked issue. It provides sufficient context for review.
Linked Issues check Passed Issue #21216 requires page numbers and bounding boxes to produce 1-based [page, left, right, top, bottom] positions. openDataLoaderPageNumber reads page number, page_number, and page. `openD…
Out of Scope Changes check Passed 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 requi…
Full details: Linked Issues check

Explanation

Issue #21216 requires page numbers and bounding boxes to produce 1-based [page, left, right, top, bottom] positions. openDataLoaderPageNumber reads page number, page_number, and page. openDataLoaderBox reads the required box aliases. openDataLoaderPositions converts PDF coordinates with the pdfium page height and writes both positions and _pdf_positions for table, image, formula, text, title, and heading items. The code keeps page_number without 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.

❤️ Share

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.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ccclucky

Copy link
Copy Markdown
Contributor Author

Ping for CI: no workflow run has ever been created for this PR (head 8516b70396a1d850024fbce0ed4d92424d5f8053), so the checks panel is empty rather than green. Workflows on fork PRs stay unqueued until a maintainer approves them, so this is the only thing blocking a first real signal on the change.

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.

@xugangqiang xugangqiang added the ci Continue Integration label Oct 27, 2026
@xugangqiang

Copy link
Copy Markdown
Contributor

The coordinate-space assumption is unverified, and the clamp silently masks failures. The PR treats OpenDataLoader's bounding box as PDF points directly and only applies math.Min clamping. In contrast, the sibling PaddleOCR adapter (pdf_parser_paddleocr.go) handles OCR coordinates that live in a different space by applying scaling plus an aspect-ratio check and emitting a warning. If OpenDataLoader actually returns pixel/image-space coordinates, the clamp would silently squash the box into a full-page highlight, and citation positioning would be silently misaligned rather than surfaced as an error or warning.

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.
@ccclucky

Copy link
Copy Markdown
Contributor Author

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 opendataloader_apiserver, so its coordinate space is a service contract this adapter cannot read. Asserting PDF points was unverifiable; the math.Min clamp then made the assertion look true — a pixel-space box gets clipped to the page rectangle, so a wrong highlight is indistinguishable from a correct one in the output.

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.

OpenDataLoader page 1: element box [150 1351 550 1400] does not fit page size 612x792; positions omitted because the service coordinates do not match the PDF point space

Text and page_number are kept, so chunking and citation attribution still work — only the highlight is withheld, which matches the existing stance in the same file that a wrong-y highlight is worse than none.

Why not the PaddleOCR scaling path. That adapter can scale because the OCR response carries its own raster dimensions (page.Width/page.Height), so the ratio against pdfium.PageSizes is computable and an aspect-ratio check is meaningful. The OpenDataLoader response has no page-size field (only bounding box/page number variants are read), so there is nothing to divide by — validation against the known page rectangle is the available signal.

Tests. CGO_ENABLED=0 go test -count=1 ./internal/parser/parser/... → ok. New cases: bleed within tolerance still clamps (no warning), a 150-DPI pixel box drops positions and warns, one warning per page across a mixed document, valid pages keep their highlights. The warning reaches the user through reportParserWarnings (internal/ingestion/component/parser.go:604) as WARNING: ... on the Parser progress message.

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

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ccclucky

Copy link
Copy Markdown
Contributor Author

Heads-up for whoever is approving fork CI runs: #21450 was approved at 10:06Z and its run 40485870975 came back fully green on head a1fbf042c83eef2a59543e096926e74a1bb873a5 (preflight / go_integration / tests_infinity / tests_elasticsearch / python_sdk_unit all success), so nothing in the change needs a second look from that angle — thanks.

The other open PRs from this account are still waiting on the same approval. Current state, from commits/<head>/check-runs just now:

PR head state
#21519 08c5d3ca3 all skipped (head moved ~1 min ago with a test-only commit)
#21536 224cab0b5 all skipped
#21527 08ee04bb3 all skipped
#21453 3f6f2ce24 all skipped
#21452 4d62d65fd all skipped
#21448 74b89efca all skipped
#21447 872184f52 all skipped
#21552 8bb92973f no run ever queued
#21499 7aeb3bf45 no run ever queued
#21433 958270c8f no run ever queued
#21432 019417fc2 no run ever queued

One approval per PR releases its whole sep-tests run; the six ragflow_* jobs then report within ~15 minutes, as here. All are Go-only changes, mergeable: clean, and each PR body carries the local verification actually run for its head.

@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.

@ccclucky

Copy link
Copy Markdown
Contributor Author

Closing the coordinate-space question with the upstream contract rather than an assertion.

opendataloader-pdf documents the element field this adapter reads as points, not pixels:

  • README.md field table: `bounding box` | `[left, bottom, right, top]` in PDF points (72pt = 1 inch) — the same table is mirrored in the PyPI 2.5.16 description.
  • README.md, RAG section: "Every element in JSON output includes a bounding box ([left, bottom, right, top] in PDF points) and page number."
  • schema.json → #/$defs/boundingBox: "Bounding box coordinates [left, bottom, right, top]".

The adapter reads exactly those elements (type, content/text, bounding box, page number) out of the parser's JSON; the only apiserver-specific keys it depends on are the json_doc / md_text envelope that carries them.

What that evidence does not buy us: opendataloader_apiserver is tenant-supplied and no service is bundled, so a wrapper that resamples or rescales would break the documented contract without the JSON looking any different. That is the case the guard exists for — past 10% bleed the positions are dropped and one warning per page names the box and the page size, so a rescaling wrapper surfaces as a visible warning instead of a plausible full-page highlight.

One residual I have not verified: rotation. The vertical flip uses pdfium's post-rotation page size (FPDF_GetPageWidth/GetPageHeight apply /Rotate), which is the right frame if the service reports post-rotation boxes. If it reports them in unrotated user space on a rotated page, large boxes trip the fit guard and are dropped rather than mis-highlighted, while small boxes can land off by the rotation. There is no rotated-page fixture here, so I am not claiming that case is covered.

Head stays a1fbf042c — CI is green there and I did not want to invalidate that run with a comment-only commit. If you would rather have the README citation in the code comment above openDataLoaderPositions instead of only in this thread, say so and I will push it as a one-line comment change.

@xugangqiang

@ccclucky

Copy link
Copy Markdown
Contributor Author

CI status on head a1fbf042c, for the record: workflow run 40485870975 is fully green now — ragflow_preflight, ragflow_go_integration, ragflow_tests_elasticsearch, ragflow_tests_infinity and ragflow_python_sdk_unit all success (ragflow_native_backend skipped by design). The Infinity job that was still in progress when I last posted has finished green, so the earlier amber note no longer applies to this PR.

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?

@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM

@yuzhichang yuzhichang 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.

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. openDataLoaderPositions emits {page, left, right, size[1]-top, size[1]-bottom} from OpenDataLoader's y-up [left, bottom, right, top]; because top > bottom, the resulting screenTop < screenBottom satisfies pdfPositionIsUsable (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: openDataLoaderPageIndexes returns page-1, pdfium.PageSizes keys by the 0-based index, and openDataLoaderPositions looks up pageSizes[page-1]. pageCount comes from FPDF_GetPageCount and is 0 only on a failed load, which is exactly the documented fallback trigger, and normalizePDFPageCount can only raise it.
  • No geometry, no wrong geometry: with !cgo or 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: projectPDFTable runs before page_number is set, but NormalizeResult re-derives TableData.Page from page_number afterwards, so ODL tables are not left on page 0.
  • Clean rename: openDataLoaderItems/openDataLoaderPageCount have 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 90 page 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).

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

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenDataLoader PDF parsing drops page positions returned by the service

3 participants