Repository navigation
feat(download-ref): optional MinerU body via the remote parse API - #78
Merged
Merged
Conversation
mineru_parse.py sends KB PDFs to MinerU's v1 parse API (mineru.net by default, stdlib-only, no local GPU) and caches .raw/*/<id>.mineru.md plus the figures it links. arXiv papers go as arxiv.org URL sources, so nothing is uploaded; files are batched into parallel jobs. render.py --mineru uses the cache as the body (full_text: mineru), after JATS and LaTeX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a ref has neither publisher JATS nor arXiv LaTeX, its body comes from
pymupdf4llm. On math-heavy two-column papers that path loses the equations: display equations are cut out as PNG crops, and inline math is flattened into run-together text ([r^a_i, r^b_j]=0,aretherelative). In a KB built for reading physics, that is exactly the part that matters.MinerU recovers it: inline and display math as LaTeX (with
\tag{n}numbering), tables as HTML, figures as images, and a coherent reading order for two-column layouts.Why remote, and why stdlib
Running MinerU locally needs torch plus GBs of models and, realistically, a CUDA GPU. Its hosted service exposes the same v1 parse API that the
mineru4.x client uses (/v1/parse/jobs), and it accepts anonymous jobs. So the new helper calls that API directly withurllib. Users install nothing and need no GPU, and every helper stays stdlib-only.Two details make it fast:
https://arxiv.org/pdf/<id>; the service advertises"sources": ["file_id", "url"]in/v1/health). The service fetches the PDF itself, so nothing is uploaded. This matters: from outside China, uploads to the service's presigned storage ran under 35 KB/s, and themineruCLI timed out on a 4 MB PDF.DOI PDFs still upload, since there is no public URL for them. The SKILL.md text tells the agent to confirm with the user before uploading paywalled PDFs to a third-party service.
--api-url/MINERU_API_URLpoints at a self-hostedmineru-apiinstead; when that server allows local sources, it reads the PDF straight from.raw/.What changed
helpers/mineru_parse.py(new). Discovers.raw/{arxiv,doi}/<id>.pdf, submits batched jobs, polls them, and downloads each result zip. It writes.raw/<kind>/<id>.mineru.mdand copies only the images the markdown links into.figures/<kind>__<id>/. MinerU's zip also contains equation crops that nothing references, and those are left out. Already-parsed PDFs are skipped (--forceredoes them,--only <id>narrows the run).MINERU_API_KEYis optional and raises the quota. The key is sent only to the API origin, never to presigned storage URLs, and is never written to disk.ffligature (efect,efective), whilefi/flsurvive. A small stem list restores the common physics words (effect,differ,coeffic,off-diag, …). A(?!f)guard leaves correct words alone.render.py --mineru. Body priority is now JATS > LaTeX > MinerU > PDF, withfull_text: mineru. Like--tex-source, it is opt-in: a cached.mineru.mdchanges nothing without the flag.index.py,kb_doctor.pyandkb_sync.pyacceptmineruas afull_textvalue.kb_syncwarns that it must re-run the parse, because it cannot regenerate MinerU figures offline.dependencies.md#minerusection (quota, retention, self-hosting), two troubleshooting rows, and thefull_textlist in CLAUDE.md.Testing
pytest -q: 305 passed.tests/test_mineru.pyis offline and covers body priority (with and without the flag, LaTeX beating MinerU), image relinking for both markdown and HTML<img>links, the ligature fix, copying only linked images out of a synthetic result zip, and discovery (skipping cached results,--force, old-stylehep-th-9901001→hep-th/9901001).scripts/validate_skills.py: OK.1106.3375, Haldane PRL;2610.35934, 64 pp.): both parsed via URL source in one 65 s job. The Haldane body went from image-only equations to all 30 numbered equations in LaTeX, with clean inline math. The 64-page paper gained 56 linked figures.kb_doctor.pyreports 0 FAIL, 0 WARN.Follow-up from an earlier proposal for the same backend in another tool: TDAA-Go/TDAA-Go#4.
🤖 Generated with Claude Code