Skip to content

fix(task): queue one PDF task for PaddleOCR, SoMark and TCADP - #20136

Merged
yuzhichang merged 1 commit into
infiniflow:0.27.xfrom
devYRPauli:fix/ocr-parser-one-task
Oct 9, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:0.27.xfrom
devYRPauli:fix/ocr-parser-one-task

Conversation

@devYRPauli

@devYRPauli devYRPauli commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

queue_tasks splits a PDF into 12-page tasks. It skips the split only for one, knowledge_graph, resume, toc_extraction and MinerU. PaddleOCR, SoMark and TCADP are not in that list, but none of them reads the task's page range:

parser page range on the parser call what each task sends
PaddleOCR by_paddleocr takes from_page/to_page and does not pass them to parse_pdf the whole PDF
SoMark by_somark, same shape the whole PDF
TCADP by_tcadp calls parse_pdf with the defaults file_start_page=1, file_end_page=1000 pages 1-1000

Nothing in rag/app/naive.py trims the output to the task's pages after the call. So a 120-page PDF queues 10 tasks, and every task parses and embeds the whole file:

  • 10 full parses on a paid or quota service. A 120-page PDF uses about 1,200 pages of quota.
  • 10 embedding runs for the same chunks. The chunk ids are xxh64(content + doc_id), so the store keeps one copy.
  • increment_chunk_num adds each task's chunk count, so chunk_num is about 10x too high.

The comment on the MinerU check gives the same reason: a split task "would repeatedly upload the entire PDF". This PR uses that unsplit-task mode for PaddleOCR, SoMark and TCADP too.

queue_tasks now passes the resolved layout recognizer through normalize_layout_recognizer, the same function rag/app/naive.py uses for dispatch. It then checks the lowercased name against {"mineru", "paddleocr", "somark", "tcadp parser"}, which are the PARSERS keys in naive.py. The UI stores TCADP as the plain name "TCADP Parser", not as a tenant model id, so the check now reads plain names too. A MinerU recognizer stored as a plain name therefore also gets one task. The multi-range merge from the MinerU mode applies to all four parsers.

This does not change what gets indexed. These three parsers already ignore the pages setting and index the whole file on every task. One task takes about as long as the slowest of the current parallel tasks, because each of those already runs the full parse.

queue_tasks on a 120-page PDF:

layout recognizer 0.27.x this branch
...@PaddleOCR 10 tasks 1 task
...@SoMark 10 tasks 1 task
TCADP Parser 10 tasks 1 task
DeepDOC 10 tasks 10 tasks

The new tests in test_task_service_mineru_page_ranges.py cover the table above and a two-range case for PaddleOCR.

run 0.27.x this branch
test_task_service_mineru_page_ranges.py + test_task_service_queue_tasks.py 4 failed, 10 passed 14 passed
test/unit_test/api + test/unit_test/common 5 failed, 1386 passed 1 failed, 1390 passed

The one failure on both is test_time_utils.py::TestTimestampToDate::test_different_timezones_handled. ruff check and ruff format --check pass on both changed files.

Not in this PR:

@coderabbitai

coderabbitai Bot commented Sep 23, 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: a8d8c74c-a0a7-4a43-bbf8-ef127fe94252

📥 Commits

Reviewing files that changed from the base of the PR and between fa21687 and 3d97a25.

📒 Files selected for processing (2)
  • api/db/services/task_service.py
  • test/unit_test/api/db/services/test_task_service_mineru_page_ranges.py

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Task queuing now identifies MinerU, PaddleOCR, SoMark, and TCADP by normalized layout-recognizer name. These parsers receive a single task spanning the file, with configured page ranges merged. Tests cover these parsers and confirm DeepDOC retains page-size-based splitting.

Changes

Whole-file parser task queuing

Layer / File(s) Summary
Parser detection and task spans
api/db/services/task_service.py, test/unit_test/api/db/services/test_task_service_mineru_page_ranges.py
The task service normalizes layout-recognizer names and uses a shared parser set to select whole-file task handling. It merges multiple configured ranges for those parsers. Tests cover PaddleOCR, SoMark, and TCADP, and verify that DeepDOC still splits tasks by page size.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: wangq8

Merge Risk: ⚪ Minimal · up to 3d97a

The change appears ready to merge after normal checks: the intended parsers queue one task, while DeepDOC retains split tasks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely identifies the main change: queueing one PDF task for PaddleOCR, SoMark, and TCADP.
Description check ✅ Passed The description includes the required Summary section, explains the problem and proposed change, documents affected parsers, test results, and scope limitations.
  • 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 checks the parser names,
Then sends one task across the spans.
PaddleOCR and SoMark join,
TCADP follows in the line.
DeepDOC keeps its pages split,
The rabbit hops, content with it.

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

@devYRPauli

Copy link
Copy Markdown
Contributor Author

Main removed api/db/services/task_service.py with the rest of the Python server in #20289. A rebase onto main leaves this PR with no diff.

The Go server does not have this defect. It queues one ingestion task per document, and a unique index on ingestion_task.document_id enforces it (internal/entity/ingestion_task.go:22). I ran CreateForDocuments on main d64b84c70 for a PDF with task_page_size: 12. PaddleOCR, SoMark, TCADP and DeepDOC each queued 1 task, and each PaddleOCR, SoMark and TCADP parse uploaded the file once.

The file still exists on 0.27.x. Should I retarget this PR to 0.27.x, or close it?

queue_tasks splits a PDF into 12-page tasks unless the layout
recognizer is MinerU. PaddleOCR, SoMark and TCADP ignore from_page and
to_page and send the whole PDF on every task, so a 120-page PDF made 10
full parses on a paid or quota service, 10 embedding runs, and a
chunk_num about 10x too high.

Resolve the layout recognizer with normalize_layout_recognizer and use
the MinerU unsplit-task mode for all four parsers. TCADP is stored as
the plain name "TCADP Parser", so the check now also reads plain names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@devYRPauli
devYRPauli changed the base branch from main to 0.27.x September 29, 2026 15:48
@devYRPauli
devYRPauli force-pushed the fix/ocr-parser-one-task branch from 3d97a25 to 13ff82f Compare September 29, 2026 15:48
@devYRPauli

Copy link
Copy Markdown
Contributor Author

Retargeted to 0.27.x, where the Python server now lives (note on #20090). The commit applies to 0.27.x (1a730e34e) with no conflict, and test_task_service_mineru_page_ranges.py gives 10 passed (4 fail with the fix reverted).

@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM

@xugangqiang
xugangqiang requested a review from yuzhichang October 9, 2026 07:30
@xugangqiang xugangqiang added the ci Continue Integration label Oct 9, 2026
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.97%. Comparing base (a70e038) to head (13ff82f).
⚠️ Report is 16 commits behind head on 0.27.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           0.27.x   #20136      +/-   ##
==========================================
- Coverage   38.01%   37.97%   -0.04%     
==========================================
  Files          54       54              
  Lines       15511    15527      +16     
  Branches      125      125              
==========================================
  Hits         5896     5896              
- Misses       9587     9603      +16     
  Partials       28       28              

☔ View full report in Codecov by Harness.
📢 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.

@yuzhichang
yuzhichang merged commit 8c75e7a into infiniflow:0.27.x Oct 9, 2026
7 checks passed
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.

3 participants