Repository navigation
fix(parser): read PDF bookmarks into remote parse results - #21499
Conversation
Every PDF method except deepdoc left file.outline empty, so the title chunker had no bookmarks to derive heading levels from. Attach them from the source bytes at the two boundaries that hand out a PDF parse result — the built-in parse methods and ingestion dispatch — and keep any outline the engine already produced authoritative. pdfium now returns the shared doctype.Outline, so the bridge's hand-rolled field copy is gone instead of gaining a second caller. Part of infiniflow#21221: outline data only. remove_toc filtering and remove_header_footer on these paths are not addressed here.
|
@coderabbitai review |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Shared outline type and PDFium extraction internal/deepdoc/parser/pdf/pdfium/pdfium.go, internal/deepdoc/parser/pdf/pdfoxide_bridge.go, internal/parser/parser/pdf_outline_cgo.go, internal/parser/parser/pdf_outline_nocgo.go, internal/parser/parser/pdf_outline_cgo_test.go, internal/parser/parser/pdf_outline_test.go |
PDFium now returns doctype.Outline values, and the PDFOxide bridge returns those values directly. The parser provides cgo and non-cgo extraction helpers. Tests check native extraction of nested bookmarks. |
Attach outlines to parser results internal/parser/parser/pdf_outline.go, internal/parser/parser/pdf_parser_common.go, internal/parser/parser/pdf_outline_test.go |
AttachPDFOutlines adds extracted outlines to eligible results and preserves existing nonempty outlines. ParseWithResult calls it after successful parsing. Tests cover existing outlines, missing bookmarks, and error or file-less results. |
Attach outlines during PDF dispatch internal/ingestion/component/pdf_vision_dispatch.go, internal/ingestion/component/pdf_outline_cgo_test.go |
PDF vision dispatch attaches outlines from the source PDF after normalization. A CGO-gated test checks that the dispatched result includes its bookmark. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant Dispatch as maybeDispatchPDFVision
participant Attach as AttachPDFOutlines
participant Extract as pdfOutlinesFromData
participant PDFium as pdfium.ExtractOutlines
Dispatch->>Attach: normalized result and source PDF bytes
Attach->>Extract: source PDF bytes
Extract->>PDFium: extract bookmarks
PDFium-->>Attach: outline values
Attach-->>Dispatch: result with outline metadata
Possibly related issues
- Issue 21218: The change attaches outlines to dispatched PDF results; the figure, output format, and media-flattening gaps remain.
- Issue 21221: The change populates outlines on dispatched results;
remove_tocandremove_header_footerwiring remains unimplemented. - Issue 21215: The change attaches outlines to remote parse results; page positions and
page_countare not addressed. - Issue 21214: The change attaches outlines to dispatched results; layout positions and image-inlining behavior are not addressed.
- Issue 21216: The change attaches outlines to remote parse results; missing page positions are not addressed.
- Issue 21217: The change attaches outlines to remote parse results; missing page positions are not addressed.
- Issue 21213: The change attaches outlines to dispatched results; image-inlining behavior is not addressed.
Suggested reviewers: jay77721
Merge Risk: 
Minimal · up to 7aeb3
-
No merge-blocking issue is established for the PDF outline attachment change.
Pre-merge checks: 
5
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
🔧 golangci-lint (2.14.0)
-
level=error msg="[linters_context] typechecking error: build constraints exclude all Go files in /internal/deepdoc/parser/pdf/pdfium"
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 finds a bookmark bright,
And hops through chapters left and right.
The pages share their titles clear,
The outline joins the results here.
One leafy trail from start to end,
With nested paths around each bend.
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. |
|
Thanks @xugangqiang. Head is still |
|
The two failing jobs are infrastructure, not this change:
Both are network drops on the self-hosted runner. Everything that did run passed ( |
yuzhichang
left a comment
There was a problem hiding this comment.
Review — head 7aeb3bf
Reviewed merge-base e5a5060..7aeb3bf (10 files, +314/−19) and both result-producing boundaries it patches.
No blocking findings.
- Both boundaries are covered:
PDFParser.ParseWithResult(pdf_parser_common.go:364) and the ingestion normalize closure (pdf_vision_dispatch.go:90-95). Tenant somark/opendataloader reach the former throughpdf.ParseWithResult(pdf_parser_model.go:160), and mineru/monkeyocrv2/paddleocr plus the generic VLM path return into the closure, which already seeds an empty outline andFile, so the patch applies there too. - The plumbed shape matches what the chunker reads:
pdfFileMetaseedsoutlineas[]map[string]any{},AttachPDFOutlineswrites the same type, and the chunker reads it back throughChunkerFileMeta.Extra["outline"](chunker/title.go,chunker/general.go). - The type move is safe:
pdftype.Outlineis already an alias ofdoctype.Outline, so dropping the duplicatepdfium.Outlinestruct only deletes a per-item conversion; no other reference exists and no import cycle is introduced. - Idempotence holds: an engine-produced non-empty outline short-circuits the reader, and re-entry from the dispatch closure after the tenant parser's own
ParseWithResultis a no-op. Thecgo/!cgosplit matches pdfium's build tag and the new test helpers do not collide.
Below the bar: on the built-in deepdoc path a bookmark-free PDF is loaded into pdfium a second time, because the "outline already present" guard cannot distinguish "read and found none" from "never read"; and the !cgo stub silently reports no bookmarks for the pure-Go fallback. Cost and an undocumented fallback, not correctness.
|
Status on head
The two |
Summary
deepdocreturns a result whosefile.outlineis empty. The title chunker reads that key to derive heading levels (internal/ingestion/component/chunker/title.gooutlineFromUpstream), so onplain_text/ MinerU / Docling / OpenDataLoader / SoMark / TCADP and the tenant PaddleOCR / MonkeyOCRv2 / VLM paths it always falls back to flat levels.file.outline.parser.AttachPDFOutlinesis called at the two choke points every dispatched PDF result passes through:PDFParser.ParseWithResultand thenormalizeclosure inmaybeDispatchPDFVision. A result that already carries an outline is left untouched, so the engine that read the bookmarks (DeepDoc) stays authoritative.pdfium.ExtractOutlinesnow returns the shareddoctype.Outlineinstead of its own identical struct, which deletes the hand-rolled field-by-field copy in the pdf_oxide bridge rather than giving it a second caller.remove_tocfiltering orremove_header_footeron these paths; the issue's second and third bullets remain open. fix(web): hide unsupported PDF cleanup controls #21440 proposes hiding the unsupported switches in the UI, which is an alternative for those, not for this.Test plan
bash build.sh --test ./internal/parser/parser/ -run 'TestAttachPDFOutlines|TestParseWithResultAttachesOutline'— 4 new unit tests, no-cgo path covered by a!cgostubgofmt -l,go vetclean, also underCGO_ENABLED=1for./internal/parser/parser/ ./internal/ingestion/component/ ./internal/deepdoc/parser/...TestPDFOutlineNativeExtractionFeedsRemoteResult(parser) andTestPDFDispatchAttachesPDFOutlines(component) pin both call sites with a hand-written bookmarked PDF. CI-only on this host: the local cgo link fails on ORT/pdfium duplicate symbols. To keep that from being an unverified claim, both fixtures were run against real pdfium through a scratch test in thepdfiumpackage (which links standalone) and returned exactly{Chapter 1, 0, 1} {Section 1.1, 1, 2} {Chapter 2, 0, 2}; the same fixtures passpdfinfo/pdftotexton 2 pages in reading order.File["outline"]survives the component-to-component JSON round trip asjson.RawMessageandoutlineFromUpstreamparsestitle/level/page_numberwithanyToInt, which accepts thefloat64a JSON decode produces.Known cost
A PDF that ends up with no outline is loaded by pdfium twice on the tenant-parser path (
ParseWithResultinside the model adapter, then the dispatch closure) because an empty result is indistinguishable from "not attempted". For PDFs that do have bookmarks the second call short-circuits on the guard.Refs #21221