Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
Update documentation and README files for clarity and accuracy
myhlolib647f87136a1
diff --git a/.github/workflows/mkdocs.yml b/.github/workflows/mkdocs.ymlindex 0c40911b..12a66854 100644--- a/.github/workflows/mkdocs.yml+++ b/.github/workflows/mkdocs.yml@@ -4,16 +4,15 @@ on:branches:- "master"- "dev"+ - "next"jobs:build:name: Deploy docsruns-on: ubuntu-lateststeps:- - name: Checkout master+ - name: Checkoutuses: actions/checkout@v6- with:- ref: dev- name: Deploy docsuses: mhausenblas/mkdocs-deploy-gh-pages@master# Or use mhausenblas/mkdocs-deploy-gh-pages@nomaterial to build without the mkdocs-material themediff --git a/.gitignore b/.gitignoreindex 0e51bdf0..f5824f1c 100644--- a/.gitignore+++ b/.gitignore@@ -68,3 +68,4 @@ output/.e2e/htmlcov/+.zcode/\ No newline at end of filediff --git a/CLAUDE.md b/CLAUDE.mdindex 74be0255..0ab5c5bd 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -171,9 +171,9 @@ MinerU 保留 OCR/VLM/Hybrid 推理、模型生命周期、LLM 增强、tier 策`mineru.types` 重新导出 `docvortex.schema` 的文档类型,并保留 MinerU 产品档位类型。-DocVortex 的 ModelJson/MiddleJson 原生 JSON 使用独立 schema 标识和版本 1.0,持有 `producer` 与 `extensions`。MinerU 的 `effort`、`parse_mode`、`mineru_version` 位于 `extensions["mineru"]`,由 `mineru.integrations.docvortex.build_metadata()` 校验。+共享文档协议是带 `schema` 身份的版本 2.0(Python 属性名为 `schema_id`,JSON 序列化键为 `schema`)。MinerU 直接消费共享类型:`ParseResult` 持有 `MiddleJson` 读写,不维护独立的协议封装层。MinerU 通过 `extensions["mineru"]` 记录实际执行的 `tier` 与 `parse_mode`,由 `mineru.integrations.docvortex.MinerUMetadata` 严格校验(`extra="forbid"`,不接受其他字段,没有 `effort`、`mineru_version` 字段);生产者版本位于 `metadata.producer.version`。-MinerU 的 ParseResult、CLI、HTTP API 和 Doclib 通过 `mineru.integrations.docvortex` 读写原有 schema 2.0 封装;3.4.5 旧页面转换由 `mineru.backend.postprocess.legacy_schema_adapter` 维护。产品字段校验、当前封装和旧结果兼容均归 MinerU,DocVortex 不提供兼容模块或旧路径别名。不要为旧底层构造参数增加动态兼容别名。+历史协议兼容限定在 Doclib 持久化缓存的读取边界(`mineru.doclib.core.middle_json.read_cached_middle_json`),不扩展为通用 SDK/API 的兼容承诺;3.4.5 旧页面转换由 `mineru.backend.postprocess.legacy_schema_adapter` 在该边界内维护。协议细节以 `docs/next/middle-json/` 为唯一参考,兼容行为对应测试为 `tests/unittest/test_doclib_legacy_schema_adapter.py`。产品字段校验和旧结果兼容均归 MinerU,DocVortex 不提供兼容模块或旧路径别名。不要为旧底层构造参数增加动态兼容别名。ModelJson 仍保存 raw pages 与 page_index_map;MiddleJson 仍保存有序 PageInfo 数组。PageInfo 只有 page_idx 与 blocks。Block/InlineSpan 的现有语义、几何和父子约束保持不变;自然语言 InlineSpan 不携带字体或几何信息。@@ -183,7 +183,7 @@ DocVortex 的确定性后处理独立构造有效 MiddleJson。`mineru.backend.p`mineru.render` 保留九种输出:Content List V1/V2 实现及专用选项归属 MinerU,其余七种 renderer 和通用选项来自 DocVortex。两边各自定义 RenderFormat,RenderMode 与共享文档类型仍复用。Content List 通过 `docvortex.render.fragments` 调用共享片段能力,不导入私有实现。公式定界符等宿主配置显式传入,不让 DocVortex 读取 MinerU 配置。-九种输出为 Markdown、HTML、LaTeX、DOCX、EPUB、PDF、Structured Content、Content List V1/V2。LaTeX/EPUB/PDF/Content List 的低层能力不自动扩展所有产品入口。PDF 输出继续采用语义重排版。+九种输出为 Markdown、HTML、LaTeX、DOCX、EPUB、PDF、Structured Content、Content List V1/V2。LaTeX/EPUB/PDF/Content List 的低层能力不自动扩展所有产品入口。PDF 输出布局由 `PdfLayout` 控制:`AUTO`(默认,有几何信息时保留原始布局,缺失时回退语义重排)、`ORIGINAL`(仅原始布局)、`REFLOW`(仅语义重排)。文件写出属于 `docvortex.export`;语义类型不再提供文件导出方法。结果包保存中间协议和物化素材,渲染不依赖已关闭的 PDFium 对象或源文件,也不修改原始语义树。diff --git a/README.md b/README.mdindex 2fa3f903..57399100 100644--- a/README.md+++ b/README.md@@ -28,7 +28,7 @@ Existing AMD and vendor accelerator adaptations remain on [MinerU <4](https://opCopy the following message and send it to your agent:```text-Install or update the global `mineru` Skill. First, run `npx skills add "opendatalab/MinerU#next" --skill mineru --global --yes`. If `npx` is unavailable, fetch https://gcore.jsdelivr.net/gh/opendatalab/MinerU@next/README.md, use its content as `mineru/SKILL.md`, and save it under the appropriate global skills directory for the current agent, not in the current project. Also check both global and project-level skills for other installed skills whose names contain `mineru`. Report any matches and ask before removing them. If global memory is available, record this preference there: "Whenever a PDF, image, or Office document needs to be read or parsed, prefer the `mineru` Skill." Do not write this preference to the current project.+Install or update the global `mineru` Skill. For the stable release (MinerU 4.0), run `npx skills add "opendatalab/MinerU#master" --skill mineru --global --yes`; for the development version, use `opendatalab/MinerU#next` instead. If `npx` is unavailable, fetch https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/README.md (or @next for the development version), use its content as `mineru/SKILL.md`, and save it under the appropriate global skills directory for the current agent, not in the current project. Also check both global and project-level skills for other installed skills whose names contain `mineru`. Report any matches and ask before removing them. If global memory is available, record this preference there: "Whenever a PDF, image, or Office document needs to be read or parsed, prefer the `mineru` Skill." Do not write this preference to the current project.```## When To Use MinerUdiff --git a/README_en.md b/README_en.mdindex 80c5f745..f5702c9b 100644--- a/README_en.md+++ b/README_en.md@@ -66,7 +66,7 @@ source .mineru/bin/activate``````bash-uv pip install -U "mineru>=4.0"+uv pip install -U "mineru>=4.0,<5"mineru-kit parse document.pdf -o document.md --tier standardmineru-kit webui```diff --git a/README_zh.md b/README_zh.mdindex 4a76d0c3..8e415e9f 100644--- a/README_zh.md+++ b/README_zh.md@@ -66,7 +66,7 @@ source .mineru/bin/activate``````bash-uv pip install -U "mineru>=4.0"+uv pip install -U "mineru>=4.0,<5"mineru-kit parse document.pdf -o document.md --tier standardmineru-kit webui```diff --git a/docs/en/index.md b/docs/en/index.mdindex 35af45ca..4036c172 100644--- a/docs/en/index.md+++ b/docs/en/index.md@@ -17,7 +17,8 @@ PDF and images support all four tiers. Office, OpenDocument, EPUB, OFD, HTML, an- [Install and get started](quick_start/index.md)- [Tiers and runtimes](usage/tiers.md)-- [Python SDK and V1 API](usage/sdk_api.md)+- [Python SDK](usage/sdk_api.md)+- [V1 HTTP API](usage/http_api.md)- [3.x → 4.0 migration](reference/migration_4.md)- [Legacy platforms (MinerU <4)](usage/compatibility.md)- [Release history](reference/changelog.md)diff --git a/docs/en/quick_start/docker_deployment.md b/docs/en/quick_start/docker_deployment.mdindex 47738279..3a09b94c 100644--- a/docs/en/quick_start/docker_deployment.md+++ b/docs/en/quick_start/docker_deployment.md@@ -14,6 +14,32 @@ The base image keeps vLLM 0.21.0. The Dockerfile installs `mineru[torch]>=4.0,<5Build-time downloads explicitly select Torch small models and original vLLM weights. Runtime selection is also fixed with `MINERU_MODEL_SMALL_BACKEND=torch` and `MINERU_MODEL_VLM_ENGINE=vllm`. A build machine without a GPU can therefore prepare the correct weights, while inference still requires matching GPU hardware. The China Dockerfile uses ModelScope; the global version uses Hugging Face.+### Image provenance and version checks++The image installs `mineru[torch]>=4.0,<5` from the package index; it does **not** install the repository checkout used as the build context. Building from a `next` or patched checkout still produces a PyPI-version image. Two paths cover the different needs:++| Path | Version source | Use it for |+| --- | --- | --- |+| Release image (`docker/global/Dockerfile`, `docker/china/Dockerfile`) | Pinned `mineru[torch]>=4.0,<5` from the package index | Production deployments |+| Source image (release image + local install) | Your checkout / commit | Verifying `next`, debugging, reproducing a patch |++Tag images with the actual version instead of only `mineru:4`, and confirm what a built image contains:++```bash+docker build -t mineru:4.0.0 -f docker/global/Dockerfile .+docker run --rm mineru:4.0.0 python3 -c "from mineru.version import __version__; print(__version__)"+```++To test a specific source revision, build the release image once, then install your checkout inside the container:++```bash+docker run --gpus all --shm-size 32g --ipc=host -it \+ -v "$PWD":/src mineru:4.0.0 /bin/bash -c \+ "python3 -m pip install -e '/src[torch]' && mineru-kit parse /src/document.pdf -o /src/document.md"+```++The editable install replaces the container's MinerU with your checkout without rebuilding the model layers; record the commit SHA in the image tag when sharing such an image.+## Interactive container```bashdiff --git a/docs/en/reference/index.md b/docs/en/reference/index.mdindex 447f4cdf..b03cbf88 100644--- a/docs/en/reference/index.md+++ b/docs/en/reference/index.md@@ -5,7 +5,7 @@ This section provides detailed reference materials for MinerU project. Here you## Table of Contents- [3.x → 4.0 migration](migration_4.md)-- [Python SDK and V1 API](../usage/sdk_api.md)+- [Python SDK](../usage/sdk_api.md)- [Output Files Documentation](./output_files.md) - Detailed explanation of all output files and their formats- [Changelog](./changelog.md) - Version update history and release notesdiff --git a/docs/en/reference/migration_4.md b/docs/en/reference/migration_4.mdindex a0c65777..ce7b53c3 100644--- a/docs/en/reference/migration_4.md+++ b/docs/en/reference/migration_4.md@@ -23,6 +23,17 @@ Install stable with `"mineru>=4.0,<5"`, inserting extras after the package name- `-o` file/directory semantics depend on the entrypoint. `mineru-kit parse` defaults to Markdown for one file; directory or multi-file inputs write to a directory.- Fields such as `_backend` and `pdf_info` in legacy results are not templates for 4.0. Read actual JSON using the [current output contract](output_files.md). Legacy artifacts are accepted only by explicitly supported compatibility readers; not every old JSON document can be passed to `ParseResult.from_dict()`.+Legacy-result handling is scoped as follows:++| Data | How 4.0 handles it |+| --- | --- |+| Current shared protocol with a `schema` identity (`2.0`) | Read strictly by `ParseResult`, HTTP/ZIP, and Gradio; a payload that carries the current identity but fails validation is not retried as a legacy format |+| Recognizable Doclib-cached history (3.4.5 `pdf_info` pages, `schema_version` `1.0`, or `2.0` without a `schema` key) | Converted in memory by the dedicated Doclib cache reader only; this does not extend to other entrypoints, and history files are not rewritten |+| Old result JSON saved outside Doclib | Not guaranteed to load via `ParseResult.from_dict()`; re-parse the source document |+| Old artifacts missing assets or new geometry data | Regenerate by re-parsing; changing a version number alone does not migrate a payload |++"Can be read" (Doclib cache), "migrated automatically" (nothing rewrites files), and "can re-export every format" (requires current assets and geometry) are separate claims; treat them independently instead of inferring one from another.+## Configuration and modelsConfiguration lives in `$MINERU_HOME/config.yaml`, optionally overridden by `MINERU_CONFIG`. Old `mineru.json` configuration is not read. `model.stack`, `MINERU_MODEL_STACK`, and `--stack` have been removed; configure the two components independently:@@ -36,6 +47,13 @@ model:engine: auto```+Two 3.x environment variables are still recognized and rejected on conflict: when a remote VLM is configured (`model.vlm.server_url` set), a non-empty `MINERU_VL_API_KEY` or `MINERU_VL_MODEL_NAME` that disagrees with the new configuration raises an error asking you to unset the legacy variable. Move these values to the new locations:++| Legacy variable | 4.0 configuration field | 4.0 environment variable |+| --- | --- | --- |+| `MINERU_VL_API_KEY` | `model.vlm.api_key` | `MINERU_MODEL_VLM_API_KEY` |+| `MINERU_VL_MODEL_NAME` | `model.vlm.model` | `MINERU_MODEL_VLM_MODEL` |+Automatic selection follows the platform. Explicit `onnx + llama-cpp` can serve lighter environments. Torch and VLM engines can also be combined when their dependencies are available. Apple Silicon defaults to llama.cpp for the VLM; MLX requires manual installation and selection.Restart relevant services after configuration changes, and download and verify models with matching backend choices. 4.0 has separate small-model bundles: the presence of an old model directory does not prove readiness. See [Model Source](../usage/model_source.md).diff --git a/docs/en/reference/output_files.md b/docs/en/reference/output_files.mdindex 78ea4d7c..cf1366b3 100644--- a/docs/en/reference/output_files.md+++ b/docs/en/reference/output_files.md@@ -76,7 +76,7 @@ and report `pdf_title_geometry_conflict`; unavailable expansion clearance report`pdf_title_clearance_unavailable`. Only rendering context changes, with no input,asset, protocol or public-option changes.-Requires `docvortex>=0.4.3,<1`. DocVortex clears native TXT PDF display equation+Requires `docvortex>=0.4.7,<1` (the current minimum dependency declared by MinerU 4.0). DocVortex clears native TXT PDF display equation`content` once when producing model output; MinerU Flash TXT uses that output.Flash OCR already leaves display equation content empty. MinerU does not clearequation content again. Both Flash paths retain the bbox, orientation, image and@@ -97,7 +97,7 @@ Path("report.html").write_text(html, encoding="utf-8")## Intermediate JSON-`ModelJson` holds analysis `pages` and `page_index_map`; `MiddleJson` holds ordered postprocessed pages and semantic blocks. `schema_id` distinguishes `docvortex.model` from `docvortex.middle`, while `schema_version` identifies the protocol version. Do not identify a document type from its version number alone.+`ModelJson` holds analysis `pages` and `page_index_map`; `MiddleJson` holds ordered postprocessed pages and semantic blocks. JSON consumers identify the payload through the serialized `schema` and `schema_version` keys (`docvortex.model` or `docvortex.middle`, protocol `2.0`). The schema identity is named `schema_id` as a Python attribute, but it serializes as `schema`; when reading or writing JSON, always use the serialized keys. Do not identify a document type from its version number alone.`metadata` carries the file type, producer, and document properties. `extensions["mineru"]` records the actual `tier` and final `parse_mode`. The producing version is `metadata.producer.version`, not a duplicate product extension field. Pages contain `page_idx` and `blocks`; `page_idx` is zero-based, unlike one-based CLI PDF ranges.@@ -152,7 +152,7 @@ Round-trip current results with `ParseResult.from_json(result.to_json())`. Legac## Structured Content-`structured_content()` returns a consumer-facing representation, not another name for the intermediate protocol. It retains `metadata` and `extensions` and turns natural-language spans into easier-to-consume text. Do not invent `schema_id` or `schema_version` fields for it.+`structured_content()` returns a consumer-facing representation, not another name for the intermediate protocol. It retains `metadata` and `extensions` and turns natural-language spans into easier-to-consume text. It carries no schema identity: do not add `schema` or `schema_version` keys to it.```json{diff --git a/docs/en/usage/cli_tools.md b/docs/en/usage/cli_tools.mdindex 40af2143..54d0fa6e 100644--- a/docs/en/usage/cli_tools.md+++ b/docs/en/usage/cli_tools.md@@ -22,6 +22,29 @@ mineru server stopRun `mineru <command> --help` for the authoritative options of each command.+## Parsing, reading, exporting, and waiting++`mineru parse` combines four behaviors that are easy to conflate; keep them separate when scripting:++| Dimension | Default | What to know |+| --- | --- | --- |+| Pages requested | First 10 PDF pages; `--pages all` requests every page | Requesting all pages is not the same as receiving all text on stdout in one response |+| Stdout reading window | 30,000-character soft limit; `--limit` changes it, `--after` continues from a content cursor | When more content exists, a `<!-- Next: mineru parse ... -->` marker with the next command is appended |+| File export | `-o` writes the complete rendered document | The export path ignores `--limit`/`--after`; it is not stdout redirected to a file |+| Client wait | `--wait` waits up to 60 seconds; `--no-wait` returns immediately | A wait timeout exits with code 1 but does not fail or cancel the parse |++A wait timeout is a client-side deadline, not a task failure: the parse keeps running in the document library. With `--json`, the response carries error code `parse_wait_timeout` and the tip to re-run the same command to continue waiting; in text mode the summary points to `mineru show parse <id>` for status. On slower devices or a first run (including model download), pass a larger window explicitly:++```bash+# Stateless conversion of the whole document+mineru-kit parse document.pdf -o document.md --tier standard++# Library parse with a complete export and an explicit 10-minute client wait+mineru parse document.pdf --pages all -o document.md --wait 600+```++When automating, keep three usage patterns apart: agent reading cares about bounded stdout, locators, and continuation; file conversion cares about complete artifacts; async tasks care about job status and the client wait window. Do not merge them into a single "command succeeded/failed" check.+## Stateless and service toolsUse `mineru-kit --help` to list the available tools.diff --git a/docs/en/usage/http_api.md b/docs/en/usage/http_api.mdnew file mode 100644index 00000000..7e033405--- /dev/null+++ b/docs/en/usage/http_api.md@@ -0,0 +1,73 @@+# V1 HTTP API Walkthrough++The self-hosted V1 API is the same interface the Python SDK and WebUI use. This page walks through one complete request cycle with plain HTTP calls: create an upload, upload the bytes, submit a parse job, poll to a terminal state, and download the outputs. For the Python client, see [Python SDK](sdk_api.md).++Start a local service, or point the examples at any V1 deployment including the official cloud service:++```bash+mineru-kit api-server --host 127.0.0.1 --port 8000 --tier standard+```++Requests to `/v1/*` carry `Authorization: Bearer $MINERU_API_KEY` when the service is started with `--api-key`; omit the header for anonymous local access. The byte upload in step 2 does **not** go through `/v1`: it uses exactly the URL, method, and headers returned in step 1.++## Complete example (curl + jq)++```bash+BASE=http://127.0.0.1:8000+AUTH="Authorization: Bearer $MINERU_API_KEY" # omit when the service allows anonymous access+FILE=document.pdf+SIZE=$(stat -c%s "$FILE") # macOS: stat -f%z "$FILE"++# 1. Create an upload session+RESP=$(curl -s -X POST "$BASE/v1/uploads" -H "$AUTH" -H "Content-Type: application/json" -d "{+ \"filename\": \"$FILE\", \"bytes\": $SIZE, \"mime_type\": \"application/pdf\", \"purpose\": \"parse\"+}")++# 2. Upload the bytes using the returned method/url/headers (pending uploads only)+if [ "$(echo "$RESP" | jq -r .status)" = "pending" ]; then+ curl -s -X PUT "$(echo "$RESP" | jq -r .upload_url)" \+ -H "Content-Type: application/pdf" --data-binary "@$FILE"+ # 3. Complete the upload to obtain the file id+ RESP=$(curl -s -X POST "$BASE/v1/uploads/$(echo "$RESP" | jq -r .id)/complete" -H "$AUTH")+fi+FILE_ID=$(echo "$RESP" | jq -r .file.id)++# 4. Submit a parse job+JOB=$(curl -s -X POST "$BASE/v1/parse/jobs" -H "$AUTH" -H "Content-Type: application/json" -d "{+ \"files\": [{\"source\": {\"type\": \"file_id\", \"file_id\": \"$FILE_ID\"}, \"page_range\": \"1-10\"}],+ \"tier\": \"standard\",+ \"output_formats\": [\"markdown\", \"zip\"]+}")+JOB_ID=$(echo "$JOB" | jq -r .job_id)++# 5. Poll until a terminal state (bounded loop; add your own attempt limit)+while : ; do+ JOB=$(curl -s "$BASE/v1/parse/jobs/$JOB_ID" -H "$AUTH")+ STATUS=$(echo "$JOB" | jq -r .status)+ case "$STATUS" in completed|partial|failed|canceled) break ;; esac+ sleep 3+done+echo "$JOB" | jq '{status, progress, files: [.files[] | {name, status, error}]}'++# 6. Download the artifacts of each completed file+for FID in $(echo "$JOB" | jq -r ".files[].output_files.markdown.file_id? // empty"); do+ curl -s "$BASE/v1/files/$FID/content" -H "$AUTH" -o document.md+done+```++Details the example deliberately shows:++- **Upload lifecycle.** Pass `sha256sum` when creating the upload for integrity checking and instant reuse of an already-known file; in that case the response is `completed` and embeds the `file` object directly, so steps 2–3 are skipped.+- **Byte upload.** Always use the returned `upload_method`, `upload_url`, and `upload_headers` verbatim. A self-hosted server returns a same-origin loopback URL; the official API returns a pre-signed object-storage URL that carries its own authorization — do not add the Bearer header there.+- **Terminal states.** `completed`, `partial`, `failed`, and `canceled` are all terminal. `partial` means some files succeeded: read `output_files` from the per-file entries whose `status` is `completed`, and inspect `error` on the rest; partial success is not full completion.+- **Client timeout is not job failure.** If your polling budget runs out while the job is still `queued` or `running`, resume polling `GET /v1/parse/jobs/{job_id}` later; the job is not canceled because your client stopped asking.+- **Outputs.** Every artifact is a `purpose:"parse_output"` file; content always comes from `GET /v1/files/{file_id}/content` using the ids under `files[].output_files`. Treat `GET /v1/health` (`features.sources`, `features.output_formats`) as the source of truth for what the current deployment supports; renderer formats do not imply API support.++## Production notes++- Bind `--host` consciously. The default `127.0.0.1` keeps the service on loopback; `0.0.0.0` exposes it to the network, so combine that with `--api-key` or an authenticating reverse proxy.+- Uploads and outputs are stored on the service host; `--upload-dir` controls the upload directory. Plan disk usage and retention for high-throughput deployments — output files carry `expires_at` where the deployment configures it.+- `--concurrency` caps concurrent parse jobs; queue growth beyond it shows up as longer `queued` times, not failures.+- `GET /v1/usage` reports consumption. Use `/v1/health` and the OpenAPI docs at `/docs` (when enabled) to separate service-side failures from client errors; check server logs before retrying a `failed` job.++The V1 service does not provide legacy `/file_parse` or `/tasks` routes; see [migration](../reference/migration_4.md) for older clients.diff --git a/docs/en/usage/index.md b/docs/en/usage/index.mdindex bf036f77..a58d7e5e 100644--- a/docs/en/usage/index.md+++ b/docs/en/usage/index.md@@ -5,7 +5,8 @@ This section provides comprehensive usage instructions for the project. We will## Table of Contents- [Tiers and runtimes](tiers.md)-- [Python SDK and V1 API](sdk_api.md)+- [Python SDK](sdk_api.md)+- [V1 HTTP API](http_api.md)- [3.x → 4.0 migration](../reference/migration_4.md)- [Legacy platforms (MinerU <4)](compatibility.md)diff --git a/docs/en/usage/model_source.md b/docs/en/usage/model_source.mdindex 47dbfa8b..5a7a9a6a 100644--- a/docs/en/usage/model_source.md+++ b/docs/en/usage/model_source.md@@ -65,12 +65,33 @@ Use `basic` as the download tier when no VLM is needed. Advanced has no separate`local` uses ready local models and fails on missing assets without downloading. An explicit `models download` is a download operation: even with `local` configured, it temporarily resolves a remote source automatically.-## VLM servers and manual MLX+## Remote VLM service and manual MLX-An existing `model.vlm.server_url` takes priority and removes the local VLM weight requirement. This is a model inference endpoint, not the MinerU V1 document parsing API. Small-model requirements still depend on the tier.+An existing `model.vlm.server_url` takes priority and removes the local VLM weight requirement. This is a model inference endpoint, not the MinerU V1 document parsing API. Small-model requirements still depend on the tier. The full field set:++| Field | Default | Purpose |+| --- | --- | --- |+| `model.vlm.engine` | `auto` | Local engine selection: `auto/llama-cpp/vllm/lmdeploy/mlx`; not used while a remote `server_url` is set |+| `model.vlm.server_url` | (unset) | Remote VLM inference endpoint. Must be HTTP(S) without credentials, query, or fragment; a trailing `/v1` is stripped and the URL is kept ending with `/` (reverse-proxy path prefixes are preserved) |+| `model.vlm.api_key` | (unset) | Bearer key for the remote VLM service; environment variable `MINERU_MODEL_VLM_API_KEY` |+| `model.vlm.model` | (unset) | Model name requested from the remote service; environment variable `MINERU_MODEL_VLM_MODEL` |+| `model.vlm.http_timeout` | `600` | Per-request timeout in seconds |+| `model.vlm.max_concurrency` | `100` | Maximum concurrent VLM requests |++Legacy `MINERU_VL_API_KEY` / `MINERU_VL_MODEL_NAME` are rejected when they conflict with these fields; see the [migration guide](../reference/migration_4.md).MLX requires manual installation of `mlx-vlm>=0.7.0,<0.8.0` and explicit `model.vlm.engine: mlx`. `model.stack`, `MINERU_MODEL_STACK`, and `--stack` have been removed. Restart relevant services after configuration changes.+## Three remote connections at a glance++MinerU talks to three different kinds of remote services. They are not interchangeable — do not reuse one service's address, key, or model name for another:++| Connection | Purpose | Where it is configured |+| --- | --- | --- |+| V1 document parsing service | Upload documents, submit parse jobs, download results (self-hosted `mineru-kit api-server`, router, or the official cloud service) | Per client: `MINERU_API_URL` / `MINERU_API_KEY`, or SDK `MinerUApiParser(api_url=..., api_key=...)`. The document library's default remote target is a library runtime setting, not part of `config.yaml` |+| Remote VLM inference service | Model inference for local parse pipelines (Standard/Advanced), OpenAI-compatible | `model.vlm.server_url` / `api_key` / `model` in `config.yaml` |+| LLM-aided post-processing | Title leveling and cross-page table cell continuation | `llm_aided.api_key` / `base_url` / `model` in `config.yaml`; both features are disabled by default |+## Download troubleshootingHugging Face uses `hf_xet` by default. If your network cannot reach Xet CAS, set `HF_HUB_DISABLE_XET=1` before downloading to use regular HTTP, or switch to ModelScope. For offline deployment, download and verify before selecting `local`. See [extension modules](../quick_start/extension_modules.md) for installation combinations.diff --git a/docs/en/usage/quick_usage.md b/docs/en/usage/quick_usage.mdindex 17dbd9f7..e1f1d069 100644--- a/docs/en/usage/quick_usage.md+++ b/docs/en/usage/quick_usage.md@@ -20,8 +20,19 @@ mineru parse <input_path> --pages all -o <output_path>> For more information about output files, please refer to [Output File Documentation](../reference/output_files.md).> [!NOTE]-> The command line tool will automatically attempt cuda/mps acceleration on Linux and macOS systems.-> Windows users who need cuda acceleration should visit the [PyTorch official website](https://pytorch.org/get-started/locally/) to select the appropriate command for their cuda version to install acceleration-enabled `torch` and `torchvision`.+> Runtime acceleration is selected separately for the two model components, based on installed dependencies and detected devices:+>+> - Small models use the Torch backend only when `torch`, `torchvision`, `transformers`, `accelerate`, and `safetensors` are **all** installed and a non-CPU device (CUDA/MPS/...) is detected; otherwise they run ONNX on CPU. Installing Torch alone is not enough.+> - The local VLM engine is chosen independently: macOS always uses llama.cpp; on an accelerator device Linux prefers vLLM, then an installed LMDeploy, and Windows uses LMDeploy; otherwise llama.cpp. MLX is never selected automatically on macOS and requires explicit configuration.+> - Windows users who need CUDA acceleration should first visit the [PyTorch website](https://pytorch.org/get-started/locally/) and install accelerator-enabled `torch` and `torchvision` matching their CUDA version, then install the `mineru[full]` extras.++After installation, confirm the runtimes actually in effect in your environment:++```bash+mineru-kit models show+```++The output reports `Effective small backend` and `Effective VLM engine` together with the config source of each value. See [Tiers and Runtimes](./tiers.md) for the full selection table.If you need to adjust parsing options through custom parameters, you can also check the more detailed [Command Line Tools Usage Instructions](./cli_tools.md) in the documentation.@@ -46,7 +57,7 @@ When an output reaches its budget, follow `next_request` or the returned continu>[!TIP]>Access `http://127.0.0.1:8000/docs` for the OpenAPI documentation. The supported service surface is `/v1/*`, including health, capability discovery, uploads, files, parse jobs, and usage.>- >Native document parsing example: [Python SDK and V1 API](sdk_api.md)+ >Native document parsing example: [Python SDK](sdk_api.md); plain HTTP: [V1 HTTP API](http_api.md)- Start Gradio WebUI visual frontend:```bashdiff --git a/docs/en/usage/sdk_api.md b/docs/en/usage/sdk_api.mdindex 7f62e3f7..06224da5 100644--- a/docs/en/usage/sdk_api.md+++ b/docs/en/usage/sdk_api.md@@ -1,4 +1,4 @@-# Python SDK and V1 API+# Python SDK## Local Python SDK@@ -58,29 +58,24 @@ print(result.markdown())mineru-kit webui --api-url http://127.0.0.1:8000```-## HTTP workflow+### Batching and instance reuse-Discover actual service capabilities first:+Reuse one `MinerUApiParser` instance for batch work instead of constructing a parser per file; each call opens and closes its own HTTP session, so there is nothing to release explicitly:-```bash-curl http://127.0.0.1:8000/v1/health-curl http://127.0.0.1:8000/v1/tiers-```+```python+from pathlib import Path+from mineru.parser import MinerUApiParser-1. Create an upload with `POST /v1/uploads`. Follow its returned URL, HTTP method, and headers, then call `/v1/uploads/{id}/complete` when required to obtain `file.id`. A completed deduplicated upload can return the file reference directly.-2. Submit a job with `POST /v1/parse/jobs`, using a body such as the following.-3. Poll `GET /v1/parse/jobs/{job_id}`. `completed`, `partial`, `failed`, and `canceled` are all terminal. Inspect per-file errors; partial success is not full completion.-4. Download outputs through `GET /v1/files/{file_id}/content` using the artifact references in the job response.--```json-{- "files": [{"source": {"type": "file_id", "file_id": "file-id-from-upload"}, "page_range": "1-3"}],- "tier": "standard",- "ocr_mode": "auto",- "output_formats": ["markdown", "middle_json", "structured_content", "zip"]-}+parser = MinerUApiParser(api_url="http://127.0.0.1:8000", tier="standard", include_images=True)+for pdf in Path("./documents").glob("*.pdf"):+ result = parser.parse(str(pdf))+ (Path("out") / f"{pdf.stem}.md").write_text(result.markdown(), encoding="utf-8")```-Omit `page_range` for non-PDF files. The current self-hosted server provides the four output types above. Consult the server capabilities and OpenAPI at `/docs`; renderer formats do not imply API support.+Failures on the service side surface as per-file job errors rather than client exceptions; check the service logs and `GET /v1/usage` when throughput matters. See [Tiers and Runtimes](tiers.md) for choosing `tier`.++## HTTP API without the SDK++The same upload → job → poll → download cycle can be driven with plain HTTP calls. The [V1 HTTP API walkthrough](http_api.md) provides a complete curl example covering upload completion, terminal states (including `partial`), resuming after a client timeout, and artifact downloads.The 4.0 V1 service does not provide legacy `/file_parse` or `/tasks` routes. See [migration](../reference/migration_4.md) for older clients and [output formats](../reference/output_files.md) for rendering and saving Python results.diff --git a/docs/zh/index.md b/docs/zh/index.mdindex 6f2a7c06..a9d782e9 100644--- a/docs/zh/index.md+++ b/docs/zh/index.md@@ -17,7 +17,8 @@ PDF 和图片支持四档解析;Office、OpenDocument、EPUB、OFD、HTML、CS- [安装与快速入门](quick_start/index.md)- [档位与运行环境](usage/tiers.md)-- [Python SDK 与 V1 API](usage/sdk_api.md)+- [Python SDK](usage/sdk_api.md)+- [V1 HTTP API](usage/http_api.md)- [3.x → 4.0 迁移](reference/migration_4.md)- [旧平台适配(MinerU <4)](usage/compatibility.md)- [更新历史](reference/changelog.md)diff --git a/docs/zh/quick_start/docker_deployment.md b/docs/zh/quick_start/docker_deployment.mdindex 08dbdfb9..a1ba5d2c 100644--- a/docs/zh/quick_start/docker_deployment.md+++ b/docs/zh/quick_start/docker_deployment.md@@ -14,6 +14,32 @@ docker build -t mineru:4 -f docker/china/Dockerfile .构建时明确下载 Torch 小模型和 vLLM 原始权重,运行时也固定 `MINERU_MODEL_SMALL_BACKEND=torch`、`MINERU_MODEL_VLM_ENGINE=vllm`。这允许无 GPU 构建机准备正确的权重,实际推理仍需要匹配的 GPU。国内 Dockerfile 使用 ModelScope,国际版本使用 Hugging Face。+### 镜像版本来源与确认++镜像从包索引安装 `mineru[torch]>=4.0,<5`,**不会**安装作为构建上下文的仓库源码;即使从 `next` 或打过补丁的 checkout 构建,得到的仍是 PyPI 版本镜像。两条路径对应不同需求:++| 路径 | 版本来源 | 适用场景 |+| --- | --- | --- |+| 正式版镜像(`docker/global/Dockerfile`、`docker/china/Dockerfile`) | 包索引固定的 `mineru[torch]>=4.0,<5` | 生产部署 |+| 源码镜像(正式版镜像 + 本地安装) | 你的 checkout / 提交 | 验证 `next`、调试、复现补丁 |++建议给镜像打上实际版本号的 tag,而不是只用 `mineru:4`,并在构建后确认镜像内容:++```bash+docker build -t mineru:4.0.0 -f docker/china/Dockerfile .+docker run --rm mineru:4.0.0 python3 -c "from mineru.version import __version__; print(__version__)"+```++要测试特定源码版本,先构建正式版镜像,再在容器内安装 checkout:++```bash+docker run --gpus all --shm-size 32g --ipc=host -it \+ -v "$PWD":/src mineru:4.0.0 /bin/bash -c \+ "python3 -m pip install -e '/src[torch]' && mineru-kit parse /src/document.pdf -o /src/document.md"+```++可编辑安装会把容器内的 MinerU 换成你的 checkout,且不重建模型层;分发此类镜像时把提交 SHA 一并记录到 tag 中。+## 交互式容器```bashdiff --git a/docs/zh/reference/index.md b/docs/zh/reference/index.mdindex fbe87ddb..d01ef9d6 100644--- a/docs/zh/reference/index.md+++ b/docs/zh/reference/index.md@@ -5,7 +5,7 @@## 目录- [3.x → 4.0 迁移](migration_4.md)-- [Python SDK 与 V1 API](../usage/sdk_api.md)+- [Python SDK](../usage/sdk_api.md)- [输出文件说明](./output_files.md) - 详细介绍所有输出文件及其格式- [更新日志](./changelog.md) - 版本更新历史和发布说明diff --git a/docs/zh/reference/migration_4.md b/docs/zh/reference/migration_4.mdindex b774d1eb..8995eb2e 100644--- a/docs/zh/reference/migration_4.md+++ b/docs/zh/reference/migration_4.md@@ -23,6 +23,17 @@- `-o` 的文件/目录含义依入口而异。`mineru-kit parse` 单文件默认 Markdown;目录或多文件输入输出到目录。- 旧结果中的 `_backend`、`pdf_info` 等字段不能作为 4.0 文档结构模板。按[当前输出协议](output_files.md)读取实际 JSON;历史产物只在明确支持的兼容读取路径中使用,不承诺所有旧 JSON 可直接传给 `ParseResult.from_dict()`。+历史结果的兼容范围如下:++| 数据情况 | 4.0 的处理方式 |+| --- | --- |+| 带 `schema` 身份的当前共享协议(`2.0`) | 由 `ParseResult`、HTTP/ZIP 与 Gradio 严格读取;携带当前身份但校验失败的数据不会回退尝试旧协议 |+| 可识别的 Doclib 历史缓存(3.4.5 `pdf_info` 页面、`schema_version` 为 `1.0`、或无 `schema` 键的 `2.0`) | 仅由 Doclib 专用缓存读取器在内存中转换;不代表其他入口兼容,也不改写历史文件 |+| Doclib 之外保存的旧结果 JSON | 不承诺 `ParseResult.from_dict()` 可以读取;请重新解析源文档 |+| 缺少素材或新版几何信息的旧产物 | 重新解析生成;仅修改版本号不等于完成迁移 |++「能读取」(Doclib 缓存)、「自动迁移」(不会改写任何文件)和「能重新导出全部格式」(需要当前素材与几何)是三个不同的承诺,请按上表区分,不要互相推断。+## 配置与模型配置使用 `$MINERU_HOME/config.yaml`,可由 `MINERU_CONFIG` 指定;旧 `mineru.json` 配置不再读取。`model.stack`、`MINERU_MODEL_STACK` 和 `--stack` 已移除,改为独立配置:@@ -36,6 +47,13 @@ model:engine: auto```+3.x 的两个旧环境变量仍会被识别并在冲突时报错:当配置了远程 VLM(`model.vlm.server_url` 非空)时,`MINERU_VL_API_KEY` 或 `MINERU_VL_MODEL_NAME` 非空且与新配置不一致会直接报错,要求清除旧变量。请将取值迁移到新位置:++| 旧变量 | 4.0 配置字段 | 4.0 环境变量 |+| --- | --- | --- |+| `MINERU_VL_API_KEY` | `model.vlm.api_key` | `MINERU_MODEL_VLM_API_KEY` |+| `MINERU_VL_MODEL_NAME` | `model.vlm.model` | `MINERU_MODEL_VLM_MODEL` |+默认按平台选择后端。显式 `onnx + llama-cpp` 可用于较轻的运行环境;Torch 与 VLM 引擎也可自由组合,但必须满足对应依赖。Apple Silicon 默认 VLM 是 llama.cpp;MLX 需要手动安装和选择。变更配置后重启相关服务,并使用相同后端执行模型下载和验证。4.0 使用独立的小模型包,不能仅凭旧模型目录存在就认定已准备完成,详见[模型源说明](../usage/model_source.md)。diff --git a/docs/zh/reference/output_files.md b/docs/zh/reference/output_files.mdindex d87fd84a..ec77c92c 100644--- a/docs/zh/reference/output_files.md+++ b/docs/zh/reference/output_files.md@@ -47,7 +47,7 @@ pdf_bytes = render(result.middle_json, RenderFormat.PDF,`pdf_title_layout_expanded` 记录扩展;`pdf_layout_font_exception` 记录局部正文较大或空间不足的调整原因、参考/目标/最终字号、原框和绘制框。原始几何重叠时不扩大占用并报告 `pdf_title_geometry_conflict`;原始间距过紧、没有安全扩展区域时报告 `pdf_title_clearance_unavailable`。字号和绘制区域仅存在于渲染上下文,不修改 MiddleJson 或素材,不新增接口参数。-使用 `docvortex>=0.4.3,<1`。DocVortex 在生产原生 TXT PDF 模型输出时将行间公式的 `content` 清空一次,MinerU Flash TXT 直接使用该输出;Flash OCR 原本不填充行间公式内容,MinerU 不再重复清空。两条 Flash 路径保留 bbox、方向、图片及检测到的编号区域,PDF、Markdown、HTML、DOCX、EPUB、LaTeX 沿用图片回退。行内公式、非 Flash tier 的公式文本不变。旧缓存不会自动改写,重新解析才获得新几何和空内容公式。+使用 `docvortex>=0.4.7,<1`(MinerU 4.0 当前声明的最低依赖)。DocVortex 在生产原生 TXT PDF 模型输出时将行间公式的 `content` 清空一次,MinerU Flash TXT 直接使用该输出;Flash OCR 原本不填充行间公式内容,MinerU 不再重复清空。两条 Flash 路径保留 bbox、方向、图片及检测到的编号区域,PDF、Markdown、HTML、DOCX、EPUB、LaTeX 沿用图片回退。行内公式、非 Flash tier 的公式文本不变。旧缓存不会自动改写,重新解析才获得新几何和空内容公式。```pythonfrom pathlib import Path@@ -61,7 +61,7 @@ Path("report.html").write_text(html, encoding="utf-8")## 中间 JSON-`ModelJson` 保存分析结果 `pages` 和 `page_index_map`;`MiddleJson` 保存后处理后的有序页面和语义块。`schema_id` 区分 `docvortex.model` 与 `docvortex.middle`,`schema_version` 标识协议版本。不要只根据版本数字判断文档种类。+`ModelJson` 保存分析结果 `pages` 和 `page_index_map`;`MiddleJson` 保存后处理后的有序页面和语义块。JSON 消费端通过序列化后的 `schema` 与 `schema_version` 两个键识别数据(`docvortex.model` 或 `docvortex.middle`,协议版本 `2.0`)。协议身份在 Python 类型中的属性名为 `schema_id`,但序列化键名是 `schema`;读写 JSON 时一律使用序列化键。不要只根据版本数字判断文档种类。`metadata` 包含文件类型、生产者和文档属性;`extensions["mineru"]` 记录实际执行的 `tier` 与最终 `parse_mode`。版本来自 `metadata.producer.version`,不重复放在产品扩展中。页面包含 `page_idx` 与 `blocks`,`page_idx` 从 0 开始,区别于 CLI 中从 1 开始的 PDF 页码。@@ -111,7 +111,7 @@ Path("report.html").write_text(html, encoding="utf-8")## Structured Content-`structured_content()` 返回面向消费端的内容结构,而非中间协议的另一个名称。它保留 `metadata` 和 `extensions`,将自然语言 span 转为更易消费的文本;不要为它补造 `schema_id` 或 `schema_version`。+`structured_content()` 返回面向消费端的内容结构,而非中间协议的另一个名称。它保留 `metadata` 和 `extensions`,将自然语言 span 转为更易消费的文本;它不携带协议身份,不要为它补造 `schema` 或 `schema_version` 字段。```json{diff --git a/docs/zh/usage/cli_tools.md b/docs/zh/usage/cli_tools.mdindex c97dc9a0..efca4e6a 100644--- a/docs/zh/usage/cli_tools.md+++ b/docs/zh/usage/cli_tools.md@@ -22,6 +22,29 @@ mineru server stop各命令的权威参数以 `mineru <command> --help` 为准。+## 解析、阅读、导出与等待++`mineru parse` 组合了四个容易混淆的行为,编写脚本时应分别对待:++| 维度 | 默认行为 | 需要知道的差异 |+| --- | --- | --- |+| 请求页范围 | PDF 前 10 页;`--pages all` 请求全部页 | 请求全部页不等于标准输出一次返回全部文字 |+| 标准输出阅读窗口 | 30,000 字符软限制;`--limit` 调整,`--after` 从内容游标续读 | 还有后续内容时,输出末尾附加含下一条命令的 `<!-- Next: mineru parse ... -->` 标记 |+| 文件导出 | `-o` 写出完整渲染文档 | 导出路径不经过 `--limit`/`--after`,不是把标准输出重定向到文件 |+| 客户端等待 | `--wait` 最多等待 60 秒;`--no-wait` 立即返回 | 等待超时退出码为 1,但任务不会因此失败或取消 |++等待超时是客户端期限,不是任务失败:解析会在文档库中继续执行。`--json` 模式的响应携带错误码 `parse_wait_timeout`,并提示重新执行同一命令继续等待;文本模式输出任务摘要并指向 `mineru show parse <id>`。较慢设备或首次运行(含模型下载)建议显式加大等待窗口:++```bash+# 无状态转换整份文档+mineru-kit parse document.pdf -o document.md --tier standard++# 文档库解析并完整导出,显式等待 10 分钟+mineru parse document.pdf --pages all -o document.md --wait 600+```++自动化时区分三种用法:Agent 阅读关注有限输出、定位符与续读;文件转换关注完整产物;异步任务关注任务状态与客户端等待期限。不要把它们合并成单一「命令成功/失败」判断。+## 无状态与服务工具使用 `mineru-kit --help` 查看所有工具。diff --git a/docs/zh/usage/http_api.md b/docs/zh/usage/http_api.mdnew file mode 100644index 00000000..78ba63f8--- /dev/null+++ b/docs/zh/usage/http_api.md@@ -0,0 +1,73 @@+# V1 HTTP API 完整示例++自部署 V1 API 与 Python SDK、WebUI 使用同一套接口。本页用纯 HTTP 调用演示一次完整闭环:创建上传、上传字节、提交解析任务、轮询到终态、下载产物。Python 客户端见 [Python SDK](sdk_api.md)。++先启动本地服务,或将示例指向任意 V1 部署(包括官方云服务):++```bash+mineru-kit api-server --host 127.0.0.1 --port 8000 --tier standard+```++服务以 `--api-key` 启动时,`/v1/*` 请求携带 `Authorization: Bearer $MINERU_API_KEY`;匿名本地访问可省略该头。第 2 步的字节上传**不走** `/v1`:必须原样使用第 1 步返回的 URL、方法和请求头。++## 完整示例(curl + jq)++```bash+BASE=http://127.0.0.1:8000+AUTH="Authorization: Bearer $MINERU_API_KEY" # 服务允许匿名访问时省略+FILE=document.pdf+SIZE=$(stat -c%s "$FILE") # macOS 使用 stat -f%z "$FILE"++# 1. 创建上传会话+RESP=$(curl -s -X POST "$BASE/v1/uploads" -H "$AUTH" -H "Content-Type: application/json" -d "{+ \"filename\": \"$FILE\", \"bytes\": $SIZE, \"mime_type\": \"application/pdf\", \"purpose\": \"parse\"+}")++# 2. 用返回的 method/url/headers 上传字节(仅 pending 状态需要)+if [ "$(echo "$RESP" | jq -r .status)" = "pending" ]; then+ curl -s -X PUT "$(echo "$RESP" | jq -r .upload_url)" \+ -H "Content-Type: application/pdf" --data-binary "@$FILE"+ # 3. 完成上传,取得 file id+ RESP=$(curl -s -X POST "$BASE/v1/uploads/$(echo "$RESP" | jq -r .id)/complete" -H "$AUTH")+fi+FILE_ID=$(echo "$RESP" | jq -r .file.id)++# 4. 提交解析任务+JOB=$(curl -s -X POST "$BASE/v1/parse/jobs" -H "$AUTH" -H "Content-Type: application/json" -d "{+ \"files\": [{\"source\": {\"type\": \"file_id\", \"file_id\": \"$FILE_ID\"}, \"page_range\": \"1-10\"}],+ \"tier\": \"standard\",+ \"output_formats\": [\"markdown\", \"zip\"]+}")+JOB_ID=$(echo "$JOB" | jq -r .job_id)++# 5. 轮询直到终态(有界循环,请自行加上尝试上限)+while : ; do+ JOB=$(curl -s "$BASE/v1/parse/jobs/$JOB_ID" -H "$AUTH")+ STATUS=$(echo "$JOB" | jq -r .status)+ case "$STATUS" in completed|partial|failed|canceled) break ;; esac+ sleep 3+done+echo "$JOB" | jq '{status, progress, files: [.files[] | {name, status, error}]}'++# 6. 下载每个成功文件的产物+for FID in $(echo "$JOB" | jq -r ".files[].output_files.markdown.file_id? // empty"); do+ curl -s "$BASE/v1/files/$FID/content" -H "$AUTH" -o document.md+done+```++示例刻意展示的要点:++- **上传生命周期。** 创建上传时传 `sha256sum` 可启用完整性校验和秒传;命中已存在文件时响应直接为 `completed` 并内嵌 `file` 对象,跳过第 2–3 步。+- **字节上传。** 始终原样使用返回的 `upload_method`、`upload_url` 和 `upload_headers`。自部署服务返回同源回环 URL;官方 API 返回自带授权的预签名对象存储 URL——不要额外添加 Bearer 头。+- **终态。** `completed`、`partial`、`failed`、`canceled` 都是终态。`partial` 表示部分文件成功:从 `status` 为 `completed` 的文件条目读取 `output_files`,其余查看 `error`;部分成功不等于全部完成。+- **客户端超时不等于任务失败。** 轮询预算耗尽时任务可能仍是 `queued` 或 `running`;之后继续轮询 `GET /v1/parse/jobs/{job_id}` 即可,任务不会因为客户端停止询问而被取消。+- **产物。** 所有产物都是 `purpose:"parse_output"` 的文件;内容一律通过 `GET /v1/files/{file_id}/content`、用 `files[].output_files` 下的 id 获取。以 `GET /v1/health`(`features.sources`、`features.output_formats`)为当前部署实际能力的依据;渲染器支持的格式不代表 API 暴露。++## 生产部署注意事项++- 谨慎绑定 `--host`。默认 `127.0.0.1` 只监听回环;使用 `0.0.0.0` 暴露到网络时,应配合 `--api-key` 或带鉴权的反向代理。+- 上传与产物存储在服务主机上,`--upload-dir` 控制上传目录。高吞吐部署需规划磁盘用量与保留策略;产物文件的 `expires_at` 以部署配置为准。+- `--concurrency` 限制并发解析任务数;超出后表现为 `queued` 时间变长,而不是失败。+- `GET /v1/usage` 报告用量。用 `/v1/health` 和 `/docs`(启用时)的 OpenAPI 文档区分服务端故障与客户端错误;重试 `failed` 任务前先查看服务端日志。++V1 服务不提供旧 `/file_parse`、`/tasks` 路由;旧客户端迁移见[迁移指南](../reference/migration_4.md)。diff --git a/docs/zh/usage/index.md b/docs/zh/usage/index.mdindex ea2c546a..613cfe11 100644--- a/docs/zh/usage/index.md+++ b/docs/zh/usage/index.md@@ -5,7 +5,8 @@## 目录- [档位与运行环境](tiers.md)-- [Python SDK 与 V1 API](sdk_api.md)+- [Python SDK](sdk_api.md)+- [V1 HTTP API](http_api.md)- [3.x → 4.0 迁移](../reference/migration_4.md)- 本地部署* [基础使用](./quick_usage.md) - 快速上手和基本使用diff --git a/docs/zh/usage/model_source.md b/docs/zh/usage/model_source.mdindex 5f0cf652..8b777eef 100644--- a/docs/zh/usage/model_source.md+++ b/docs/zh/usage/model_source.md@@ -65,12 +65,33 @@ mineru-kit parse document.pdf -o document.md --tier standard`local` 模式只使用就绪的本地模型,缺失时报错,不自动下载。显式执行 `models download` 是下载操作,即使配置为 `local`,该命令也会临时采用自动远端模型源。-## VLM 服务与手动 MLX+## 远程 VLM 服务与手动 MLX-`model.vlm.server_url` 配置已有 VLM 服务时,优先使用该服务,不要求本地 VLM 权重;它是模型推理接口,不是 MinerU V1 文档解析 API。小模型依赖仍由所选档位决定。+`model.vlm.server_url` 配置已有 VLM 服务时,优先使用该服务,不要求本地 VLM 权重;它是模型推理接口,不是 MinerU V1 文档解析 API。小模型依赖仍由所选档位决定。完整字段如下:++| 字段 | 默认值 | 用途 |+| --- | --- | --- |+| `model.vlm.engine` | `auto` | 本地引擎选择:`auto/llama-cpp/vllm/lmdeploy/mlx`;设置远程 `server_url` 时不使用 |+| `model.vlm.server_url` | (未设置) | 远程 VLM 推理地址。必须是 HTTP(S),不允许携带凭据、query 或 fragment;结尾的 `/v1` 会被去掉并保证以 `/` 结尾(保留反向代理路径前缀) |+| `model.vlm.api_key` | (未设置) | 远程 VLM 服务的 Bearer Key;环境变量 `MINERU_MODEL_VLM_API_KEY` |+| `model.vlm.model` | (未设置) | 请求远程服务使用的模型名;环境变量 `MINERU_MODEL_VLM_MODEL` |+| `model.vlm.http_timeout` | `600` | 单请求超时(秒) |+| `model.vlm.max_concurrency` | `100` | VLM 最大并发请求数 |++旧变量 `MINERU_VL_API_KEY` / `MINERU_VL_MODEL_NAME` 与这些字段冲突时会被拒绝,见[迁移指南](../reference/migration_4.md)。MLX 需手动安装 `mlx-vlm>=0.7.0,<0.8.0` 并显式设置 `model.vlm.engine: mlx`。`model.stack`、`MINERU_MODEL_STACK` 和 `--stack` 已移除。修改配置后重启相关服务。+## 三种远程连接对照++MinerU 会连接三类不同的远程服务,它们互不通用——不要把其中一个服务的地址、密钥或模型名复用到另一个上:++| 连接对象 | 用途 | 配置位置 |+| --- | --- | --- |+| V1 文档解析服务 | 上传文档、提交解析任务、下载结果(自部署 `mineru-kit api-server`、router 或官方云服务) | 每个客户端的 `MINERU_API_URL` / `MINERU_API_KEY`,或 SDK 的 `MinerUApiParser(api_url=..., api_key=...)`。文档库的默认远端目标是库内运行时设置,不在 `config.yaml` |+| 远程 VLM 推理服务 | 为本地解析流程(Standard/Advanced)提供模型推理,OpenAI 兼容 | `config.yaml` 的 `model.vlm.server_url` / `api_key` / `model` |+| LLM 辅助后处理 | 标题分级、跨页表格单元格续接 | `config.yaml` 的 `llm_aided.api_key` / `base_url` / `model`;两个功能默认关闭 |+## 下载问题Hugging Face 默认使用 `hf_xet`。如果网络无法访问 Xet CAS,可在下载前设置 `HF_HUB_DISABLE_XET=1` 使用普通 HTTP;也可切换 ModelScope。离线部署先完成下载和验证,再设置 `local`。更多安装组合见[扩展模块](../quick_start/extension_modules.md)。diff --git a/docs/zh/usage/quick_usage.md b/docs/zh/usage/quick_usage.mdindex e18a13c4..a02dd6ed 100644--- a/docs/zh/usage/quick_usage.md+++ b/docs/zh/usage/quick_usage.md@@ -20,8 +20,19 @@ mineru parse <input_path> --pages all -o <output_path>> 更多关于输出文件的信息,请参考[输出文件说明](../reference/output_files.md)。> [!NOTE]-> 命令行工具会在Linux和macOS系统自动尝试cuda/mps加速。Windows用户如需使用cuda加速,-> 请前往 [Pytorch官网](https://pytorch.org/get-started/locally/) 选择适合自己cuda版本的命令安装支持加速的`torch`和`torchvision`。+> 运行时加速按两个模型组件分别选择,依据是已安装的依赖和检测到的设备:+>+> - 小模型仅在 `torch`、`torchvision`、`transformers`、`accelerate`、`safetensors` **全部安装**且检测到非 CPU 设备(CUDA/MPS 等)时使用 Torch 后端,否则使用 ONNX(CPU)。只安装 Torch 并不足以启用。+> - 本地 VLM 引擎独立选择:macOS 固定使用 llama.cpp;加速卡设备上 Linux 优先 vLLM、其次已安装的 LMDeploy,Windows 使用 LMDeploy;否则使用 llama.cpp。macOS 不会自动选择 MLX,需要显式配置。+> - Windows 用户如需 CUDA 加速,请先前往 [PyTorch 官网](https://pytorch.org/get-started/locally/) 选择与 CUDA 版本匹配的命令安装支持加速的 `torch` 和 `torchvision`,再安装 `mineru[full]`。++安装完成后,确认当前环境实际生效的运行时:++```bash+mineru-kit models show+```++输出会报告 `Effective small backend` 与 `Effective VLM engine`,以及每个取值的配置来源。完整选择规则见[档位与运行环境](./tiers.md)。如果需要通过自定义参数调整解析选项,您也可以在文档中查看更详细的[命令行工具使用说明](./cli_tools.md)。@@ -46,7 +57,7 @@ mineru read "doc:ab12cd3/tier:standard/page:11" --json>[!TIP]>在浏览器中访问 `http://127.0.0.1:8000/docs` 查看 OpenAPI 文档。服务只提供 `/v1/*` 接口,包括健康检查、能力发现、上传、文件、解析任务和用量查询。>- >原生文档解析示例:[Python SDK 与 V1 API](sdk_api.md)+ >原生文档解析示例:[Python SDK](sdk_api.md);纯 HTTP 调用见 [V1 HTTP API](http_api.md)- 启动gradio webui 可视化前端:```bashdiff --git a/docs/zh/usage/sdk_api.md b/docs/zh/usage/sdk_api.mdindex 52113c16..7f3dd16d 100644--- a/docs/zh/usage/sdk_api.md+++ b/docs/zh/usage/sdk_api.md@@ -1,4 +1,4 @@-# Python SDK 与 V1 API+# Python SDK## 本地 Python SDK@@ -58,29 +58,24 @@ print(result.markdown())mineru-kit webui --api-url http://127.0.0.1:8000```-## HTTP 工作流+### 批量处理与实例复用-先通过健康检查和档位发现获取实际能力:+批量处理时复用同一个 `MinerUApiParser` 实例,不要每个文件新建一个;每次调用各自开合 HTTP 会话,无需显式释放资源:-```bash-curl http://127.0.0.1:8000/v1/health-curl http://127.0.0.1:8000/v1/tiers-```+```python+from pathlib import Path+from mineru.parser import MinerUApiParser-1. `POST /v1/uploads` 创建上传,根据响应的 URL、HTTP 方法和请求头上传文件;需要时调用 `/v1/uploads/{id}/complete`,取得 `file.id`。已完成的去重上传可直接取得文件引用。-2. `POST /v1/parse/jobs` 提交任务,例如下方 JSON。-3. `GET /v1/parse/jobs/{job_id}` 轮询。`completed`、`partial`、`failed`、`canceled` 都是终态;逐文件检查错误,不能将部分成功当作全部完成。-4. 按任务响应中的产物引用调用 `GET /v1/files/{file_id}/content` 下载结果。--```json-{- "files": [{"source": {"type": "file_id", "file_id": "file-id-from-upload"}, "page_range": "1-3"}],- "tier": "standard",- "ocr_mode": "auto",- "output_formats": ["markdown", "middle_json", "structured_content", "zip"]-}+parser = MinerUApiParser(api_url="http://127.0.0.1:8000", tier="standard", include_images=True)+for pdf in Path("./documents").glob("*.pdf"):+ result = parser.parse(str(pdf))+ (Path("out") / f"{pdf.stem}.md").write_text(result.markdown(), encoding="utf-8")```-非 PDF 文件省略 `page_range`。当前自部署服务提供上例四种产物;以服务能力和 `/docs` 的 OpenAPI 为准,不能由渲染层的格式列表推断 API 支持范围。+服务端失败以逐文件的任务错误呈现,而不是客户端异常;关注吞吐时检查服务日志和 `GET /v1/usage`。档位选择见[档位与运行环境](tiers.md)。++## 不使用 SDK 的 HTTP 调用++上传 → 任务 → 轮询 → 下载的闭环也可以直接用 HTTP 调用完成。[V1 HTTP API 完整示例](http_api.md) 提供了完整的 curl 示例,覆盖完成上传、终态处理(含 `partial`)、客户端超时后继续轮询和产物下载。4.0 V1 服务不提供旧 `/file_parse` 和 `/tasks` 路由。既有客户端迁移见[迁移指南](../reference/migration_4.md),Python 渲染与结果保存见[输出格式](../reference/output_files.md)。diff --git a/mkdocs.yml b/mkdocs.ymlindex 570499f5..3b6d85a8 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -85,7 +85,8 @@ nav:- Usage: usage/index.md- Quick Usage: usage/quick_usage.md- Tiers and Runtimes: usage/tiers.md- - Python SDK and V1 API: usage/sdk_api.md+ - Python SDK: usage/sdk_api.md+ - V1 HTTP API: usage/http_api.md- Legacy Platforms (MinerU <4): usage/compatibility.md- Model Source: usage/model_source.md- CLI Tools: usage/cli_tools.md@@ -107,7 +108,8 @@ nav:- Usage: usage/index.md- Quick Usage: usage/quick_usage.md- Tiers and Runtimes: usage/tiers.md- - Python SDK and V1 API: usage/sdk_api.md+ - Python SDK: usage/sdk_api.md+ - V1 HTTP API: usage/http_api.md- Legacy Platforms (MinerU <4): usage/compatibility.md- Model Source: usage/model_source.md- CLI Tools: usage/cli_tools.md@@ -147,7 +149,8 @@ plugins:Quick Usage: 基础使用CLI Tools: 命令行工具Tiers and Runtimes: 档位与运行环境- Python SDK and V1 API: Python SDK 与 V1 API+ Python SDK: Python SDK+ V1 HTTP API: V1 HTTP APILegacy Platforms (MinerU <4): 旧平台适配(MinerU <4)Migration to 4.0: 迁移到 4.0Model Source: 模型源配置