Skip to content

fix(parser): restore picture OCR independently of VLM enhancement - #20424

Merged
yuzhichang merged 4 commits into
infiniflow:mainfrom
jay77721:fix/picture-ocr-independent-vlm
Sep 30, 2026
Merged

yuzhichang merged 4 commits into
infiniflow:mainfrom
jay77721:fix/picture-ocr-independent-vlm

Conversation

@jay77721

@jay77721 jay77721 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Uploading an image with the picture template fails when vision enhancement is disabled, even though the template declares parse_method: "ocr". Restore local OCR for ocr and empty parse methods by reusing the existing PDF OCR pipeline. The VLM switch independently controls additional descriptions.

Empty OCR results or an unavailable OCR backend retain the image item and a warning in the Parser output. The Tokenizer still filters chunks without text or surrounding context, so this change does not guarantee that textless images enter the index or add image embeddings.

Related Issue

Follow-up to #20166, which removed the standalone-image OCR call path.

SVG parsing is tracked separately in #20442. The picture template retains its existing svg suffix; this PR does not implement SVG decoding, and the current image validation still rejects SVG uploads.

Changes

  • Reuse PDF OCR detection, de-skewing, rotation selection, and batched recognition through OCRImage.
  • Keep OCR text and the image attachment when optional VLM enhancement is unavailable. VLM enhancement returns only a description and warnings, which are merged into the existing Parser result.
  • Guard image admission release with defer, while releasing before the picture parser acquires its own permit.
  • Validate payload size, image headers, and dimensions before raster allocation. Fully decode pixels only when local OCR is selected.
  • Reuse the component package's existing raster image decoders and expand the fallback image suffixes. Preserve the picture template's existing suffix list.
  • Replace the test requiring VLM with coverage for OCR selection, optional enhancement, empty/unavailable OCR, invalid image headers, panic recovery without admission leaks, and decoding pixels only for OCR.
  • Use an embedded 5.2 KB PNG for the native OCR integration test, removing its dependency on external DeepDoc testdata.

Test Plan

Passed locally:

bash build.sh --test ./internal/ingestion/component ./internal/parser/parser ./internal/deepdoc/parser/pdf
bash build.sh --test -run '^(TestMaybeDispatchImage|TestImageDecoders_)' ./internal/ingestion/component
bash build.sh --test -run '^TestBuildComponentParams_Picture$' ./internal/ingestion/task
MODEL_DIR="$PWD/internal/rag/res/deepdoc" bash build.sh --test-integration-go -run '^TestMaybeDispatchImageNativeOCRWithoutVision$' ./internal/ingestion/component
git diff --check

The cgo && integration test runs real ONNX OCR with VLM disabled and checks the known fixture text and image attachment. It also passed when its test binary ran from a temporary directory without the external DeepDoc testdata paths.

@jay77721 jay77721 added go Pull requests that update go code parsing size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. ci Continue Integration labels Sep 30, 2026
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 7f39b308-bc6f-4f48-9c34-523f10b80971

📥 Commits

Reviewing files that changed from the base of the PR and between 28c4a58 and c172f60.

📒 Files selected for processing (1)
  • internal/ingestion/component/media_dispatch_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

Walkthrough

Image dispatch now extracts local OCR text independently of vision enhancement. It validates image payloads, records OCR and VLM warnings, and can append a VLM description. Image parser validation and default suffixes are updated, with tests for dispatch behavior and native OCR.

Changes

Image OCR dispatch

Layer / File(s) Summary
OCR entry point and image parser setup
internal/deepdoc/parser/pdf/parser_ocr.go, internal/ingestion/component/parser.go, internal/ingestion/component/dispatch_model.go
Adds OCRImage. Image setup accepts case-insensitive OCR methods without requiring a language, and the default image suffixes include BMP, TIF/TIFF, and WebP. Comments describe OCR and optional VLM enhancement.
OCR dispatch and optional enhancement
internal/ingestion/component/media_dispatch.go, internal/ingestion/component/media_dispatch_test.go, internal/ingestion/component/media_dispatch_integration_test.go
Image dispatch validates payloads, extracts and orders OCR text, and optionally appends VLM descriptions. Tests cover OCR outcomes, image decoding, analyzer errors, and native OCR.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ImageDispatch
  participant OCRImage
  participant DocumentAnalyzer
  participant describeImage
  participant VLM
  ImageDispatch->>ImageDispatch: Validate image payload
  ImageDispatch->>OCRImage: Pass decoded image and zoom
  OCRImage->>DocumentAnalyzer: Detect and recognize image text
  DocumentAnalyzer-->>OCRImage: Return text boxes
  OCRImage-->>ImageDispatch: Return text boxes
  opt Vision enhancement enabled
    ImageDispatch->>describeImage: Request image description
    describeImage->>VLM: Send image request
    VLM-->>describeImage: Return description
    describeImage-->>ImageDispatch: Return description and warnings
  end
  ImageDispatch->>ImageDispatch: Set image item text and JSON output
Loading

Suggested reviewers: jinhai-cn

Merge Risk: ⚪ Minimal · up to c172f

Image uploads can use local OCR without requiring vision enhancement, while retaining the image when OCR is unavailable. No actionable merge-blocking regression is established from the supplied change context.

Security Architecture Review

Security architecture risk: 🔵 Low · up to c172f

Image uploads now trigger local OCR without requiring vision descriptions. Payload limits, bounded concurrency, and explicit cleanup constrain the added processing. No introduced security defect was established, but cancellation responsiveness and deployment-wide exposure remain incompletely verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Upload-controlled image bytes newly reach local raster decoding and OCR even with vision enhancement disabled. Resource contention can affect other image operations sharing the process-wide admission pool; broader worker or tenant exposure is not quantified by the available deployment evidence.

Trust Boundaries and Controls

  • observed — Remote vision processing remains gated by the enhancement boolean and is skipped without a tenant ID. Both base and head pass that identity through model resolution and send the image to the selected vision driver. This establishes preserved dispatch controls, not verification of upstream tenant authorization.

Resilience and Maintainability Implications

  • observed — OCR receives the request context, and the inspected native detection and batch-recognition implementations forward it to inference calls. Admission is released when the synchronous work exits or unwinds; context propagation alone does not establish prompt termination for every analyzer or decoding operation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: restoring picture OCR independently of VLM enhancement.
Description check ✅ Passed The description includes the required Summary section and clearly explains the problem, solution, scope, implementation details, and test plan.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

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 scans a page of light
OCR gathers words just right
A vision note may join the flow
Image text sorts from top to low
I thump beside the pixels bright

Comment @coderabbitai help to get the list of available commands.

@jay77721
jay77721 marked this pull request as draft September 30, 2026 03:28
@jay77721
jay77721 force-pushed the fix/picture-ocr-independent-vlm branch from e97a9be to 0e3cd66 Compare September 30, 2026 04:12
@jay77721
jay77721 marked this pull request as ready for review September 30, 2026 04:48
@jay77721 jay77721 added ci Continue Integration and removed ci Continue Integration labels Sep 30, 2026
@jay77721
jay77721 requested a review from yuzhichang September 30, 2026 06:02
@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM

@yuzhichang
yuzhichang merged commit 285b2c2 into infiniflow:main Sep 30, 2026
6 checks passed
@jay77721
jay77721 deleted the fix/picture-ocr-independent-vlm branch October 16, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration go Pull requests that update go code parsing size:L This PR changes 100-499 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants