Skip to content

fix(mineru): thread page_from/page_to into MinerU API request - #16957

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
Harsh23Kashyap:fix/mineru-page-range-thread
Jul 16, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
Harsh23Kashyap:fix/mineru-page-range-thread

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

Problem

When a page range is set on a chunk task, the range is not passed to the MinerU API. Each request sends the full PDF instead of the selected pages, which causes MinerU to process the same content repeatedly and duplicate chunks downstream.

Repro steps

  1. Create a chunk task for a PDF.
  2. Set a page range using page_from and page_to.
  3. Run the task with MinerU parsing enabled.
  4. Inspect the MinerU API request or the resulting chunks.

Expected

The MinerU request should include the selected page range. RAGFlow's page_to is exclusive (Python slice stop); MinerU's end_page_id is 0-based inclusive.

Fix

  • Thread page_from and page_to through parse_pdf, _run_mineru, and _run_mineru_api in deepdoc/parser/mineru_parser.py.
  • Replace the hardcoded MinerU range with values resolved from the task range, translating page_to into end_page_id at the API boundary.
  • Preserve the full-document fallback with start_page_id: 0 and end_page_id: 99999 when no range is provided.
  • Forward from_page and to_page from rag/app/naive.py, clamping to_page to MAXIMUM_PAGE_NUMBER.
  • Log the resolved page range for debugging.

Fixes #16586

Tests

Three regression tests in test/unit_test/deepdoc/parser/test_mineru_parser.py:

  • Explicit page-range values reach the MinerU request payload.
  • The full-document fallback stays intact when no range is provided.
  • to_page converts correctly to MinerU's inclusive end_page_id.
uv run pytest test/unit_test/deepdoc/parser/test_mineru_parser.py

Result: 7/7 tests passed (4 existing + 3 new). py_compile clean.

Review the payload and run the parser test before merging.

The MinerU parser was hardcoding start_page_id=0/end_page_id=99999 in the
file_parse payload, so every page-range task ended up fetching the whole PDF
and duplicating chunks downstream. Thread page_from/page_to through parse_pdf
and _run_mineru, then translate the RAGFlow exclusive to_page into MinerU's
inclusive end_page_id at the API boundary.
by_mineru already received the task dispatcher's page range but dropped it
before calling parse_pdf. Forward the range and clamp the task-sentinel value
so the parser's MAXIMUM_PAGE_NUMBER default still maps to the full-document
fallback inside the API request.
Add three pytest regressions against _run_mineru_api: an explicit range
shows up in the request, the default full-document range still falls back to
0/99999, and the to_page - 1 normalization matches MinerU's 0-based inclusive
end_page_id contract.
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

MinerU page-range propagation

Layer / File(s) Summary
Parser range contract and API translation
deepdoc/parser/mineru_parser.py
parse_pdf accepts page bounds, forwards them through the MinerU request path, and translates the exclusive upper bound into MinerU’s inclusive end_page_id.
Application page-range forwarding
rag/app/naive.py
by_mineru forwards task page bounds and caps the upper bound at MAXIMUM_PAGE_NUMBER.
Request-boundary validation
test/unit_test/deepdoc/parser/test_mineru_parser.py
Tests capture request payloads and verify ranged, default, and end-page normalization behavior.

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

Sequence Diagram(s)

sequenceDiagram
  participant by_mineru
  participant parse_pdf
  participant MinerUParser
  participant MinerU API
  by_mineru->>parse_pdf: page_from and page_to
  parse_pdf->>MinerUParser: forward page range
  MinerUParser->>MinerU API: start_page_id and inclusive end_page_id
  MinerU API-->>MinerUParser: parsed page-range result
Loading

Possibly related PRs

Suggested reviewers: euvre, 6ba3i

Poem

I’m a rabbit with pages to spare,
Slicing each range with careful care.
MinerU bounds now hop in line,
No duplicate chunks in the design.
From start to end, the pages know—
Exactly where their carrots grow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy #16586 by forwarding page ranges and translating the exclusive stop to MinerU's inclusive end page.
Out of Scope Changes check ✅ Passed The modified files stay focused on MinerU page-range handling and related regression tests, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly matches the main change: threading page_from/page_to into the MinerU API request.
Description check ✅ Passed The description explains the problem, expected behavior, fix, and tests, though it doesn't use the exact Summary heading.

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.

@yingfeng yingfeng added the ci Continue Integration label Jul 16, 2026
@yingfeng
yingfeng marked this pull request as draft July 16, 2026 01:40
@yingfeng
yingfeng marked this pull request as ready for review July 16, 2026 01:40
@wangq8
wangq8 self-requested a review July 16, 2026 03:56
@wangq8
wangq8 merged commit 81361c2 into infiniflow:main Jul 16, 2026
17 of 20 checks passed
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (df5c8e7) to head (ec5dbd1).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16957      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

☔ 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.

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 🌈 python Pull requests that update Python code size:S This PR changes 10-29 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MinerU parser ignores split page ranges and duplicates chunks

3 participants