Repository navigation
Fix MinerU parser page range handling - #16600
ayame-selachan wants to merge 7 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds page-range support to MinerU parsing. Page bounds flow from the caller through ChangesMinerU Page-Range Support
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 hops from page to page, Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
deepdoc/parser/mineru_parser.py (1)
851-854: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winFull-document image rendering per split task is wasteful.
In branch A,
__images__(pdf, zoomin=1)renders every page of the PDF even though only[start_page_id, end_page_id]was parsed. For a large PDF split into many tasks this is roughly O(n²) rendering work and memory. Consider bounding rendering tomax(page_indices) + 1(or the requested window) while keeping the coordinate base consistent.🤖 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 `@deepdoc/parser/mineru_parser.py` around lines 851 - 854, The image rendering path in mineru_parser’s __images__ call is rendering the full PDF in the branch where page_indices are already known, which causes unnecessary work for split tasks. Update this logic to bound rendering to the parsed window or to max(page_indices) + 1 while keeping the page coordinate base consistent, and keep the existing start_page_id/end_page_id handling in MineruParser aligned with __images__.
🤖 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 `@deepdoc/parser/mineru_parser.py`:
- Around line 364-365: The page-tag generation in _line_tag() is adding
self.page_from too early, which breaks render-relative numbering for split-page
MinerU outputs. Remove the self.page_from offset from _line_tag() so tags stay
zero-based relative to the rendered window, and let extract_positions() continue
converting back to page indices while crop() remains the only place that
reintroduces self.page_from for absolute positions.
---
Nitpick comments:
In `@deepdoc/parser/mineru_parser.py`:
- Around line 851-854: The image rendering path in mineru_parser’s __images__
call is rendering the full PDF in the branch where page_indices are already
known, which causes unnecessary work for split tasks. Update this logic to bound
rendering to the parsed window or to max(page_indices) + 1 while keeping the
page coordinate base consistent, and keep the existing start_page_id/end_page_id
handling in MineruParser aligned with __images__.
🪄 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: 3fe4164a-0185-4d4b-b6a8-1771ff1d5bf2
📒 Files selected for processing (2)
deepdoc/parser/mineru_parser.pyrag/app/naive.py
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
deepdoc/parser/mineru_parser.py (1)
733-758: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winRemove the duplicated
parse_pdf()parameter block.The current signature contains two parameter lists, so this file will not parse. Keep one signature and include the new
from_page/to_pagekeyword-only parameters.Proposed fix
def parse_pdf( - self, - filepath: str | PathLike[str], - binary: BytesIO | bytes, - callback: Optional[Callable] = None, - *, - output_dir: Optional[str] = None, - backend: str = "pipeline", - server_url: Optional[str] = None, - delete_output: bool = True, - parse_method: str = "raw", - from_page: int = 0, - to_page: int = MAXIMUM_PAGE_NUMBER, - **kwargs, - self, + self, filepath: str | PathLike[str], binary: BytesIO | bytes, callback: Optional[Callable] = None, *, output_dir: Optional[str] = None, backend: str = "pipeline", server_url: Optional[str] = None, delete_output: bool = True, parse_method: str = "raw", + from_page: int = 0, + to_page: int = MAXIMUM_PAGE_NUMBER, **kwargs, ) -> tuple:🤖 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 `@deepdoc/parser/mineru_parser.py` around lines 733 - 758, The parse_pdf signature is duplicated and currently contains two parameter blocks, which breaks parsing. In mineru_parser.py, clean up parse_pdf so it has only one function header, and keep the added keyword-only from_page and to_page parameters alongside the existing filepath, binary, callback, output_dir, backend, server_url, delete_output, and parse_method arguments. Make sure the final signature is syntactically valid and there are no repeated self/parameter sections.
🤖 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.
Outside diff comments:
In `@deepdoc/parser/mineru_parser.py`:
- Around line 733-758: The parse_pdf signature is duplicated and currently
contains two parameter blocks, which breaks parsing. In mineru_parser.py, clean
up parse_pdf so it has only one function header, and keep the added keyword-only
from_page and to_page parameters alongside the existing filepath, binary,
callback, output_dir, backend, server_url, delete_output, and parse_method
arguments. Make sure the final signature is syntactically valid and there are no
repeated self/parameter sections.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e5b92082-91a0-4148-814b-7f3b4986f9ca
📒 Files selected for processing (1)
deepdoc/parser/mineru_parser.py
|
please fix lefthook format - @ayame-selachan |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 0.27.x #16600 +/- ##
=========================================
Coverage ? 93.16%
=========================================
Files ? 10
Lines ? 717
Branches ? 118
=========================================
Hits ? 668
Misses ? 29
Partials ? 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Thanks for the reminder. I merged the latest main branch and fixed the lefthook formatting issues, including removing the duplicated MinerU parse_pdf signature and configuration block introduced during conflict resolution. The ragflow_preflight check is now passing. Could you please take another look when convenient? |
|
This problem, which currently makes minerU almost unusable, when can it be fixed, please fix it as soon as possible @wangq8 |
|
@ayame-selachan would you please resolve the conflicts? |
|
Thanks for the contribution. Reviewing against current 1. Superseded by
|
|
If you are still working on this PR, please re-open it. |
What this PR changes
This PR makes the MinerU parser respect RAGFlow's PDF page-range tasks.
Currently,
by_mineru(...)receivesfrom_pageandto_page, but those values are not passed intoMinerUParser.parse_pdf(...). The MinerU API request then uses fixed values:This means every split RAGFlow task can parse the whole PDF, causing duplicate chunks.
Changes
from_pageandto_pagefromrag/app/naive.pytoMinerUParser.parse_pdf(...).start_page_idandend_page_idtoMinerUParseOptions./file_parse.page_idxmay be either original-PDF-based or relative tostart_page_id.Why this is needed
When a PDF is split into tasks like:
the MinerU parser should parse only each assigned page range. Without this, all tasks may produce identical block counts and duplicated chunks.
Testing
Local syntax check:
Manual validation performed on a PDF parsed with MinerU:
start_page_idandend_page_id.Notes
This PR does not change the chunking strategy itself. It only ensures the MinerU API is called with the intended page range.