Skip to content

Go: implement provider: PaddleOCR_Local - #15158

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:main
May 25, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:main

Conversation

@Haruko386

Copy link
Copy Markdown
Member

What problem does this PR solve?

Go: implement provider: PaddleOCR_Local

Verified from CLI

RAGFlow(user)> ocr with 'PaddleOCR-VL@test@paddleocr_local' file './internal/test1.jpg'
+----------------------+
| text                 |
+----------------------+
| ## Parallel to these |
+----------------------+

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Refactoring

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 22, 2026
@Haruko386 Haruko386 added the ci Continue Integration label May 22, 2026
@Haruko386
Haruko386 marked this pull request as draft May 22, 2026 11:04
@Haruko386
Haruko386 marked this pull request as ready for review May 22, 2026 11:04
@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds local PaddleOCR model support to the model factory system, corrects endpoint naming in Gitee embeddings, updates display names for consistency, fixes type formatting in TogetherAI configuration, extends Zhipu-AI with model and OCR endpoints, and implements a complete OCRFile method with base64-encoded payload handling and result text extraction.

Changes

Local PaddleOCR Model Support and Model Configuration Updates

Layer / File(s) Summary
Model configuration corrections
conf/models/gitee.json, conf/models/mineru_local.json, conf/models/togetherai.json
Gitee embedding endpoint renamed from "embedding" to "embeddings"; MinerU display name updated to "MinerU_local"; TogetherAI rerank model max_tokens converted from string "16384" to numeric 16384.
Extended model endpoint configurations
conf/models/zhipu-ai.json, conf/models/paddleocr_local.json
Zhipu-AI URL suffixes extended with models and ocr endpoint mappings and new "glm-ocr" model definition; new PaddleOCR_Local model configuration with ocr → layout-parsing URL mapping.
Model factory provider dispatch
internal/entity/models/factory.go
CreateModelDriver switch adds routing for "paddleocr_local" provider to instantiate PaddleOCRLocalModel.
PaddleOCR Local model driver implementation
internal/entity/models/paddleocr_local.go
PaddleOCRLocalModel constructed with HTTP client (timeout and connection pooling); unsupported methods (chat, embeddings, rerank, ASR, TTS, file parsing) return errors; OCRFile validates input, detects file type from extension or PDF signature, base64-encodes content, sends POST to local endpoint, validates response error code, concatenates markdown text results from layout parsing output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#15051: Adds mineru_local provider routing to factory.go similar to paddleocr_local integration pattern.
  • infiniflow/ragflow#14586: Adds lmstudio provider routing to factory.go following the same model driver factory dispatch pattern.

Suggested labels

ci


🐰 A local paddle makes OCR flow,
Files decoded to text below,
Config aligned, endpoints true,
New model driver through and through,
Layout parsing, markdown bright,
Local extraction done just right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 accurately describes the main change: implementing a new PaddleOCR_Local provider in Go, which is clearly reflected in the new file additions and factory routing logic.
Description check ✅ Passed The description follows the required template with both sections completed: it explains the problem (implementing PaddleOCR_Local provider), includes CLI verification evidence, and properly checks the type of change categories.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@conf/models/zhipu-ai.json`:
- Around line 273-277: Remove the duplicate "glm-ocr" entry from the models
array: locate the second occurrence of the object whose "name" is "glm-ocr" in
the models JSON and delete that object so each model name is unique (leave the
original/first "glm-ocr" definition intact).

In `@internal/entity/models/paddleocr_local.go`:
- Around line 119-125: The current logic uses "if ... else if" so when fileURL
is present but doesn't end with ".pdf" you never check the content signature;
change to check both independently so a PDF identified by content will set
fileType even if fileURL is non-empty. Specifically, in the block using
fileType, fileURL, content and strings.HasSuffix, replace the "if ... else if"
with two independent checks: one that sets fileType=0 when fileURL
(non-nil/non-empty) ends with ".pdf" and a separate check that sets fileType=0
when len(content)>4 && string(content[:4])=="%PDF".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14259826-b1bd-466c-9728-52bef332128d

📥 Commits

Reviewing files that changed from the base of the PR and between 302f97d and 3ea7c90.

📒 Files selected for processing (7)
  • conf/models/gitee.json
  • conf/models/mineru_local.json
  • conf/models/paddleocr_local.json
  • conf/models/togetherai.json
  • conf/models/zhipu-ai.json
  • internal/entity/models/factory.go
  • internal/entity/models/paddleocr_local.go

Comment thread conf/models/zhipu-ai.json
Comment on lines +273 to +277
{
"name": "glm-ocr",
"model_types": [
"ocr"
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove duplicate glm-ocr model entry.

glm-ocr is already defined earlier in the same models array, so this adds a duplicate entry.

Proposed fix
-    {
-      "name": "glm-ocr",
-      "model_types": [
-        "ocr"
-      ]
-    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@conf/models/zhipu-ai.json` around lines 273 - 277, Remove the duplicate
"glm-ocr" entry from the models array: locate the second occurrence of the
object whose "name" is "glm-ocr" in the models JSON and delete that object so
each model name is unique (leave the original/first "glm-ocr" definition
intact).

Comment on lines +119 to +125
if fileURL != nil && *fileURL != "" {
if strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") {
fileType = 0
}
} else if len(content) > 4 && string(content[:4]) == "%PDF" {
fileType = 0
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

fileType inference misses PDF-by-content when fileURL is present.

With the current if ... else if, any non-empty fileURL that doesn’t end in .pdf skips signature detection, so real PDFs can be sent as image type.

Proposed fix
 fileType := 1
-if fileURL != nil && *fileURL != "" {
-	if strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") {
-		fileType = 0
-	}
-} else if len(content) > 4 && string(content[:4]) == "%PDF" {
-	fileType = 0
-}
+if len(content) >= 4 && string(content[:4]) == "%PDF" {
+	fileType = 0
+} else if fileURL != nil && *fileURL != "" && strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") {
+	fileType = 0
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if fileURL != nil && *fileURL != "" {
if strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") {
fileType = 0
}
} else if len(content) > 4 && string(content[:4]) == "%PDF" {
fileType = 0
}
fileType := 1
if len(content) >= 4 && string(content[:4]) == "%PDF" {
fileType = 0
} else if fileURL != nil && *fileURL != "" && strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") {
fileType = 0
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/entity/models/paddleocr_local.go` around lines 119 - 125, The
current logic uses "if ... else if" so when fileURL is present but doesn't end
with ".pdf" you never check the content signature; change to check both
independently so a PDF identified by content will set fileType even if fileURL
is non-empty. Specifically, in the block using fileType, fileURL, content and
strings.HasSuffix, replace the "if ... else if" with two independent checks: one
that sets fileType=0 when fileURL (non-nil/non-empty) ends with ".pdf" and a
separate check that sets fileType=0 when len(content)>4 &&
string(content[:4])=="%PDF".

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (7e68441) to head (3ea7c90).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15158   +/-   ##
=======================================
  Coverage   93.12%   93.12%           
=======================================
  Files          10       10           
  Lines         713      713           
  Branches      116      116           
=======================================
  Hits          664      664           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zeweihan

Copy link
Copy Markdown

Nice work on the PaddleOCR_Local provider — having a local OCR option that doesn't require external API calls is a big deal for document-heavy workflows where data stays on-prem.

A few thoughts from our experience building OCR pipelines for legal document processing:

  1. Layout-aware OCR matters more than raw character accuracy — for legal docs, the spatial relationship between text blocks (clauses, numbered lists, table cells) is as important as the characters themselves. PaddleOCR's layout analysis is strong here, but make sure the bounding box output preserves reading order, not just spatial position. Legal docs often have multi-column layouts with footnotes that break naive top-to-bottom ordering.

  2. Confidence scores per-region, not just per-character — we've found it useful to expose OCR confidence at the block/paragraph level, not just individual characters. This lets downstream RAG pipelines decide whether to trust the OCR result or flag for human review. A paragraph with 95% confidence is trustworthy; one at 70% needs a second look.

  3. Mixed-language support — legal documents frequently mix languages (e.g., English contracts with Latin legal terms, or Chinese contracts with English clauses). PaddleOCR handles CJK well, but the provider should surface the detected language per-region so the RAG pipeline can apply the right tokenizer/embedding model.

The CLI verification approach is solid — having a way to quickly test OCR output against known documents is invaluable for regression testing when upgrading the OCR engine version.

@JinHai-CN
JinHai-CN merged commit 5d022d8 into infiniflow:main May 25, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants