Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Refactor tier defaults and file type policy

jinzhenj95893edf3677
diff --git a/docs/next/README.md b/docs/next/README.md
index dfed58d2..1c27f132 100644
--- a/docs/next/README.md
+++ b/docs/next/README.md
@@ -18,7 +18,7 @@
3. [端到端工作流](workflows.md): 串起 watch、ingest、parse、cache、search、API、SDK 和 Agent 读取流程。
4. [实现计划](implementation-plan.md): 面向编程 Agent 的细粒度任务拆分、边界和验收。
5. [系统架构](architecture.md): 再理解本地文档库、服务、任务和存储模型。
-6. [解析 Tier](tiers.md): 理解默认选择、`flash`、`medium`、`high`、`extra_high` 的质量、速度、硬件和隐私边界。
+6. [解析 Tier](tiers.md): 理解默认选择、`flash`、`medium`、`high`、`xhigh` 的质量、速度、硬件和隐私边界。
7. [CLI 规格](cli.md): 理解本地入口和批处理体验。
8. [Unified API](api.md): 理解云端和自部署 API 的统一模型。
9. [SDK 设计](sdk.md): 理解 Tool SDK 与 Product SDK 的分层。
diff --git a/docs/next/api/examples.md b/docs/next/api/examples.md
index ac597376..1c3a1571 100644
--- a/docs/next/api/examples.md
+++ b/docs/next/api/examples.md
@@ -131,7 +131,7 @@ curl -X POST http://localhost:8000/v1/parse/jobs \
}'
```
-省略 `tier` 或传 `null` 时,本地 server 只会选择当前可发现的 `medium` 或 `high`。如果两者都不可用,请求应失败,而不是使用 `flash` 返回解析结果。
+对 PDF/image,省略 `tier` 或传 `null` 时,本地 server 按 [解析 Tier](../tiers.md) 的默认选择策略选择非 `flash` 质量 tier。如果不可用,请求应失败,而不是使用 `flash` 返回解析结果。Office/text/HTML 按 [ADR-0024](../decisions/0024-file-type-tier-normalization.md) 的 API Server 批量规则归一为 `flash`。
## 本地 Server: 复用上传流程
diff --git a/docs/next/api/health-models.md b/docs/next/api/health-models.md
index 36e59e52..76f0b069 100644
--- a/docs/next/api/health-models.md
+++ b/docs/next/api/health-models.md
@@ -147,24 +147,15 @@ Tier 对象字段:
| 字段 | 类型 | 必带 | 说明 |
|------|------|:--:|------|
-| `id` | string | 是 | 当前服务提供的真实质量 tier,例如 `medium` 或 `high`。 |
+| `id` | string | 是 | 当前服务提供的真实质量 tier,例如 `medium`、`high` 或 `xhigh`。 |
| `description` | string | 是 | 档位说明。 |
| `current_model` | string 或 null | 是 | 当前 tier 背后的模型 ID。 |
## Tier 选择语义
-`medium` 和 `high` 是 v1 协议中面向用户读取文档的真实质量档位。具体服务当前支持哪些 tier,以 `/v1/tiers` 返回为准。
+v1 协议中面向用户读取文档的质量档位以 [解析 Tier](../tiers.md) 为准。具体服务当前支持哪些 tier,以 `/v1/tiers` 返回为准。
-请求创建 parse job 时,客户端可以省略 `tier` 或传 `null`,表示使用默认选择策略:
-
-| 可发现能力 | 默认选择结果 |
-|------------|---------------|
-| 只有 `medium` | `medium` |
-| 只有 `high` | `high` |
-| 同时有 `medium` 和 `high` | `high` |
-| 没有 `medium` 和 `high` | 报错 |
-
-默认选择策略在任何语境下都不能等价于 `flash`。`flash` 是 watch、发现、索引阶段使用的快速 CPU 引擎,不是用户读取文档时的默认质量档位。
+请求创建 parse job 时,客户端可以省略 `tier` 或传 `null`,表示使用 [解析 Tier](../tiers.md) 中定义的默认选择策略。对 PDF/image 这类支持多 tier 的输入,默认选择不能等价于 `flash`;Office/text/HTML 按 [ADR-0024](../decisions/0024-file-type-tier-normalization.md) 的批量规则归一为 `flash`。
更完整产品语义见 [解析 Tier](../tiers.md)。
@@ -191,7 +182,7 @@ Local Parse Server 的 `health` 通常返回:
| 字段 | 类型 | 说明 |
|------|------|------|
| `parser_version` | string | 本地解析器版本。 |
-| `models` | object | 各后端健康状态,例如 `{"medium":"ok","high":"missing"}`。 |
+| `models` | object | 各后端健康状态,例如 `{"medium":"ok","high":"ok","xhigh":"missing"}`。 |
这些额外字段只供运维和调试使用,通用客户端不能依赖。
@@ -201,10 +192,11 @@ Local Parse Server 的 `health` 通常返回:
|-------------------------|-------------------|
| Medium | `medium` |
| High | `high` |
+| Extra High | `xhigh` |
| 只有 Flash | 不应把 `flash` 作为用户质量解析 tier;默认选择请求应失败。 |
本地或兼容服务应以 `/v1/tiers` 返回值作为能力发现事实。它可以只暴露一个 tier,也可以暴露多个 tier;客户端不应假设具体进程模型。
-如果本地 server 支持 `flash`,它可以在内部 watch 或索引机制中使用,但不应出现在面向用户质量解析的默认选择候选中。
+如果本地 server 支持 `flash`,它可以用于显式 `flash`、仅支持 flash tier 的输入归一化、watch 或索引机制,但不应出现在 PDF/image 面向用户质量解析的默认选择候选中。
`mineru.net/api` 在相当长时间内只提供 `high`。远端 `/v1/tiers` 因此应返回 `high`;省略 `tier` 或传 `null` 等价于使用 `high`。
diff --git a/docs/next/api/parse-jobs.md b/docs/next/api/parse-jobs.md
index eea3e87e..45a79a6e 100644
--- a/docs/next/api/parse-jobs.md
+++ b/docs/next/api/parse-jobs.md
@@ -51,7 +51,7 @@ Job 状态:
| 字段 | 类型 | 必填 | 默认 | 说明 |
|------|------|:--:|------|------|
| `files` | array | 是 | 无 | 至少 1 个,最多由 access level 决定。 |
-| `tier` | string 或 null | 否 | `null` | `medium`、`high` 或 `null`。省略或传 `null` 表示使用默认选择策略,选择当前可发现的最高质量非 `flash` tier。HTML 输入自动路由到 HTML 解析器。 |
+| `tier` | string 或 null | 否 | `null` | 当前服务支持的 tier 或 `null`。省略或传 `null` 表示使用默认选择策略;完整 tier 语义见 [解析 Tier](../tiers.md) 与 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。HTML 输入自动路由到 HTML 解析器。 |
| `output_formats` | array | 否 | `["markdown"]` | 请求产物格式。 |
| `callback` | object | 否 | `null` | Webhook 回调配置,官方 API registered 用户可用。 |
@@ -181,7 +181,7 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定
| `job_id` | string | Job ID。 |
| `status` | string | 当前 job 状态。 |
| `created_at` | string | ISO-8601 UTC。 |
-| `tier` | string | 本次 job 实际使用的 tier。请求省略或传 `null` 时,响应中返回解析后的实际 tier。 |
+| `tier` | string | 本次 job 的请求/解析 tier。请求省略或传 `null` 时,响应中返回解析后的 job tier;非 PDF/image 文件可能按 ADR-0024 在文件执行时归一为 `flash`,暂不暴露 file-level effective tier。 |
| `output_formats` | array | 实际接受的输出格式。 |
| `access_level` | string | `anonymous` 或 `registered`。 |
| `files[]` | array | 输入文件的队列状态。 |
@@ -342,7 +342,7 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定
| 404 | `file_not_found` | `file_id` 不存在或不可见。 |
| 413 | `file_too_large` | 文件超过当前 access level 限制。 |
| 429 | `rate_limit_exceeded` | 触发 parse 类限流。 |
-| 503 | `quality_tier_unavailable` | 请求的 `medium` / `high` 不可用,或默认选择策略找不到可用的非 `flash` tier。 |
+| 503 | `quality_tier_unavailable` | 请求的质量 tier 不可用,或 PDF/image 默认选择策略找不到可用的非 `flash` tier。 |
## 本地 Server 差异
@@ -352,5 +352,5 @@ Local Parse Server 的任务 API 与官方 API 保持同一结构,但有以下
- `health.features.output_formats` 必须反映本地 server 实际支持的输出格式;当前本地实现支持 `markdown`、`middle_json`、`content_list`、`structured_content` 和 `zip`。
- `health.features.sources` 必须反映本地 server 实际允许的 source 类型;只有启动时开启 `--allow-local-source` 才包含 `local`。
- `local` source 可以不生成输入 `file_id`;响应中应保留 `name` 和文件级状态。
-- 省略 `tier` 或传 `null` 时,只能选择本地可发现的 `medium` 或 `high`,不能回退到 `flash`。
-- 如果只有 `flash` 可用,应返回 `quality_tier_unavailable`,而不是返回低质量解析结果。
+- 对 PDF/image,省略 `tier` 或传 `null` 时,只能按默认选择策略选择本地可发现的非 `flash` 质量 tier,不能回退到 `flash`;如果只有 `flash` 可用,应返回 `quality_tier_unavailable`。
+- 对 Office/text/HTML,API Server job 按批量规则处理,即使 job tier 是质量 tier,文件实际解析也按 `flash` 语义归一;暂不新增 file-level effective tier 字段。
diff --git a/docs/next/api/responses.md b/docs/next/api/responses.md
index a3b45919..29a2b9a7 100644
--- a/docs/next/api/responses.md
+++ b/docs/next/api/responses.md
@@ -126,5 +126,5 @@ Local Parse Server 使用同一套错误 envelope。差异主要体现在错误
- 未启用 API Key 时,不会产生 `invalid_api_key`。
- 请求 `local` source 但路径不在 allowlist 内,应返回 `invalid_request_error`。
-- 省略 `tier` 或传 `null` 且无法解析到 `medium` 或 `high` 能力时,应返回 tier 相关错误,不能降级到 `flash`。
+- PDF/image 省略 `tier` 或传 `null` 且无法解析到非 `flash` 质量 tier 时,应返回 tier 相关错误,不能降级到 `flash`。Office/text/HTML 按 [ADR-0024](../decisions/0024-file-type-tier-normalization.md) 归一为 `flash`。
- 解析能力缺失时,应优先返回可操作的 `engine_error`,而不是泛化为 `internal_error`。
diff --git a/docs/next/architecture.md b/docs/next/architecture.md
index e9137e6b..b4f418b8 100644
--- a/docs/next/architecture.md
+++ b/docs/next/architecture.md
@@ -19,11 +19,11 @@ mineru CLI / MCP Server / MinerU.app
- SQLite + FTS5
-> local parse-server
- 独立进程
- - medium / high / extra_high tier
+ - medium / high / xhigh tier
- HTTP API
```
-`doclib` 是默认常驻的本地文档库服务,负责文件入库、SHA256 去重、解析任务调度、缓存、搜索、配置和本地 API。`local parse-server` 是可选独立进程,负责加载较重模型并执行 `medium` / `high` / `extra_high` 等质量 tier 解析。
+`doclib` 是默认常驻的本地文档库服务,负责文件入库、SHA256 去重、解析任务调度、缓存、搜索、配置和本地 API。`local parse-server` 是可选独立进程,负责加载较重模型并执行 `medium` / `high` / `xhigh` 等质量 tier 解析。
Tier 的产品语义以 [解析 Tier](tiers.md) 为准;本文只描述它们在 doclib 和 ParseWorker 中的执行路径。
@@ -151,7 +151,7 @@ metadata 更新规则:入库阶段写基础 metadata;解析完成后,只
| 字段 | 含义 |
|------|------|
| `sha256` | 指向文档内容 |
-| `tier` | 实体 tier:`flash` / `medium` / `high` / `extra_high`;未指定 tier 应在入队前或执行前解析为实体 tier |
+| `tier` | 实体 tier:`flash` / `medium` / `high` / `xhigh`;未指定 tier 应在入队前或执行前解析为实体 tier |
| `page_range` | 正值页码范围字符串,如 `1~5,46~50` |
| `status` | `pending` / `parsing` / `done` / `failed` / `superseded` |
| `priority` | Agent 同步请求高于 watch 后台任务 |
@@ -192,7 +192,7 @@ SQLite 运行在 WAL 模式,使用 FTS5 提供搜索能力。每次 DB 操作
阶段 2: 解析
-> flash: 本地轻量解析
-> 默认选择: 通过 parse-server 能力发现解析为质量 tier
- -> medium/high/extra_high: local 或 remote parse-server
+ -> medium/high/xhigh: local 或 remote parse-server
-> 写 parsed artifacts
-> 更新 fts_contents
-> 更新 parses/docs 状态
@@ -200,7 +200,7 @@ SQLite 运行在 WAL 模式,使用 FTS5 提供搜索能力。每次 DB 操作
这样用户无需理解“索引”和“解析”两个概念;不同 tier 只是解析深度和执行路径不同。
-注意:`flash` 是 watch 自动发现和搜索索引的低成本 tier,不应作为用户主动阅读文档时的默认最终质量。主动阅读未指定 tier 时应使用默认选择策略,解析为当前可发现的最高非 `flash` tier,具体语义见 [解析 Tier](tiers.md)。
+注意:`flash` 是 watch 自动发现和搜索索引的低成本 tier,不应作为 PDF/image 主动阅读时的默认最终质量。PDF/image 主动阅读未指定 tier 时应使用默认选择策略;有能力发现上下文时按 `high` -> `xhigh` -> `medium` 解析。Office/text/HTML 的归一规则见 [ADR-0024](decisions/0024-file-type-tier-normalization.md)。
### 4.2 文件发现到入库
@@ -272,9 +272,9 @@ ParseWorker 按 `tier`、`privacy` 和 parse-server 健康状态路由:
| 条件 | 执行路径 |
|------|----------|
-| 未指定 tier | 通过当前目标 parse-server 能力发现解析为最高可用质量 tier;不可解析为 `flash` |
+| 未指定 tier | PDF/image 通过当前目标 parse-server 能力发现,按 `high` -> `xhigh` -> `medium` 解析;Office/text/HTML 归一为 `flash` |
| `tier=flash` | 直接本地调用轻量 parser,`via=local` |
-| `tier=medium/high/extra_high` 且 `privacy=remote` | 优先调用 config 中的远端地址;产品正式目标是 `mineru.net/api`,当前代码默认值暂为 `https://staging.mineru.org.cn/api` |
+| `tier=medium/high/xhigh` 且 `privacy=remote` | 优先调用 config 中的远端地址;产品正式目标是 `mineru.net/api`,当前代码默认值暂为 `https://staging.mineru.org.cn/api` |
| remote 不可用 | 尝试 fallback 到 local parse-server |
| `privacy=local` 且 local parse-server disabled | 返回 `no_engine` |
| local parse-server 配置但探活失败 | 返回可重试错误 |
@@ -283,7 +283,7 @@ ParseWorker 按 `tier`、`privacy` 和 parse-server 健康状态路由:
关键约束:
- 用户显式 `--remote` 才允许上传文档。
-- 未指定 tier 使用默认选择策略,但永远不会降级到 `flash`。
+- PDF/image 未指定 tier 使用默认选择策略,但永远不会降级到 `flash`。
- 远端解析失败且属于文件损坏、加密等非网络错误时,不 fallback 到本地。
- 重试时保持原始 `privacy` 不变。
- `via` 只在解析完成后写入,避免失败记录误导。
@@ -316,7 +316,7 @@ ParseWorker 按 `tier`、`privacy` 和 parse-server 健康状态路由:
11~20_1710002234000.json
high/
1~20_1710003234000.json
- extra_high/
+ xhigh/
1~20_1710004234000.json
images/
```
@@ -385,7 +385,7 @@ parse-server 配置:
| key | 默认值 | 说明 |
|-----|--------|------|
| `parse_server.local.mode` | `disabled` | `disabled` / `managed` / `self_hosted` |
-| `parse_server.local.managed_tier` | `high` | managed 模式启动的 tier;当前允许 `medium` / `high` / `extra_high` |
+| `parse_server.local.managed_tier` | `high` | managed 模式启动的 tier;当前允许 `medium` / `high` / `xhigh` |
| `parse_server.local.self_hosted_url` | 无 | self-hosted 地址 |
| `parse_server.remote.url` | 当前代码默认 `https://staging.mineru.org.cn/api` | 远端地址;产品正式目标是 `https://mineru.net/api` |
| `parse_server.remote.api_key` | 无 | 远端 API Key |
@@ -406,7 +406,7 @@ Watch、parsing-rules 和 exclude 规则也由 CLI 写入 SQLite。Parsing-rules
|------|------|
| 纯文本 | 直接读取,无需模型解析 |
| Office / HTML | 本地 CPU 全量解析 |
-| PDF / Image | 按 tier 路由到默认选择 / flash / medium / high / extra_high |
+| PDF / Image | 按 tier 路由到默认选择 / flash / medium / high / xhigh |
## 9. 错误与恢复
@@ -498,7 +498,7 @@ parse-server 相关错误:
| code | 含义 | 可重试 |
|------|------|:--:|
-| `quality_tier_unavailable` | 主动阅读需要质量 tier,但只有 `flash` 可用 | 否 |
+| `quality_tier_unavailable` | PDF/image 主动阅读需要质量 tier,但只有 `flash` 可用 | 否 |
| `no_engine` | 本地请求质量 tier,但 local parse-server disabled | 否 |
| `engine_unavailable` | local parse-server 已配置但探活失败 | 是 |
| `parse_server_unavailable` | remote 不可用且 local fallback 不可用 | 是 |
diff --git a/docs/next/cli/README.md b/docs/next/cli/README.md
index 737d7674..535b8a62 100644
--- a/docs/next/cli/README.md
+++ b/docs/next/cli/README.md
@@ -49,8 +49,8 @@ MinerU 仓库提供两款命令行工具:
- 解析 tier 语义以 [解析 Tier](../tiers.md) 为准。
- 不显式 `--remote` 时,不上传用户文档。
-- 用户主动读取文档时,不把 `flash` 作为默认最终质量。
-- 未指定 tier 使用默认选择策略;默认选择永远不会解析为 `flash`。
+- 用户主动读取 PDF/image 时,不把 `flash` 作为默认最终质量。
+- 未指定 tier 使用默认选择策略;PDF/image 默认选择不会解析为 `flash`,Office/text/HTML 归一规则见 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。
- CLI 错误应使用结构化错误码和可执行修复建议。
- 错误码、`retryable` 和 `user_action` 语义见 [错误码体系](../errors.md)。
diff --git a/docs/next/cli/mineru-e2e-test-cases.md b/docs/next/cli/mineru-e2e-test-cases.md
index 92d6d5d7..2b7f8565 100644
--- a/docs/next/cli/mineru-e2e-test-cases.md
+++ b/docs/next/cli/mineru-e2e-test-cases.md
@@ -51,7 +51,7 @@
- `$MINERU_E2E_FIXTURE_DIR/no-read.pdf`,权限不可读文件;若平台无法稳定制造权限场景,可标记相关用例 BLOCKED。
- `$MINERU_E2E_FIXTURE_DIR/output-dir/`,用于输出文件测试的目录。
- 测试环境允许启动本地 doclib server。
-- 测试环境必须安装 `pro` extra,以覆盖本地 medium/high parse-server;默认 tier 相关用例应验证本地 quality tier 可用,不再按缺少本地 quality tier 的预期失败分支判定。
+- 测试环境必须安装当前质量解析依赖 extra,以覆盖本地 quality parse-server;默认 tier 相关用例应验证本地 quality tier 可用,不再按缺少本地 quality tier 的预期失败分支判定。
- 除 PARSE-013A1 外,若 remote parse-server 不可用,`--remote` 相关用例按预期失败分支判定;若可用,必须验证 remote/via/privacy 等字段。
- PARSE-013A1 是 remote high 硬性测试,remote parse-server 不可用或不支持 high 均记录为失败。
@@ -80,7 +80,7 @@ rm -rf .venv
uv venv .venv
source .venv/bin/activate
cd ~/MinerU-Repo
-uv pip install ".[pro]"
+uv pip install ".[high]"
cd ~/mineru-e2e-test
mineru --help
mineru-kit --help
@@ -1239,7 +1239,7 @@ mineru parse "$MINERU_E2E_FIXTURE_DIR/sample.pdf" --pages 1~1 --wait 20 --json
- 三条命令均 exit code = 0
- parse 前 `server status --json` 最终应体现 `parse_server.local.healthy=true`,`supported_tiers` 包含 `high`
- stdout 为可直接解析的 JSON
-- 实际 tier 为 medium 或 high
+- 实际 tier 为 high
- 实际 tier 不为 flash
- 不允许静默返回 flash 内容
- 不包含 Python traceback
@@ -1407,7 +1407,7 @@ mineru parse "$MINERU_E2E_FIXTURE_DIR/sample.pdf" --remote --pages 1~1 --wait 60
- 如果 remote parse-server 可用:
- exit code = 0
- 输出为可直接解析的 JSON
- - tier 应为 remote 支持的 quality tier,例如 medium 或 high
+ - tier 应为 remote 支持的 quality tier;如果 remote 暴露 `high`,默认应为 `high`
- JSON 体现 remote/via/privacy 中的部分字段
- 不允许在未声明 fallback 的情况下静默返回本地 flash 内容
- 如果 remote parse-server 不可用:
@@ -3523,7 +3523,7 @@ Blocked:
Environment:
- mineru version: <如果 help/status 输出能看到则填写,否则 unknown>
- fixture dir: ...
-- quality tier available: medium/high available
+- quality tier available: <available quality tiers>
- remote high available: yes
- pdf fixture source: ...
```
diff --git a/docs/next/cli/mineru-kit-api-server.md b/docs/next/cli/mineru-kit-api-server.md
index 32c3351b..e9e42b3f 100644
--- a/docs/next/cli/mineru-kit-api-server.md
+++ b/docs/next/cli/mineru-kit-api-server.md
@@ -8,7 +8,7 @@
## 1. 定位
-`mineru-kit api-server` 是正式的 self-hosted parse-server 启动入口。当前一个进程可以通过重复 `--tier` 暴露一个或多个 tier;不传 `--tier` 时暴露 `flash`、`medium`、`high`、`extra_high`。
+`mineru-kit api-server` 是正式的 self-hosted parse-server 启动入口。当前一个进程可以通过重复 `--tier` 暴露一个或多个 tier;不传 `--tier` 时暴露 `flash`、`medium`、`high`、`xhigh`。
`mineru doclib` 可以通过 HTTP 调用它执行解析任务。
@@ -46,10 +46,12 @@ api-server 必须提供能力发现接口,让 doclib 或客户端知道当前
| api-server 启动 tier | 请求未指定 tier 时 |
|---------------------|--------------------|
| 包含 `high` | `high` |
-| 不包含 `high` | 使用启动 tier 列表中的第一个 tier |
-| 未传 `--tier` | 暴露 `flash`、`medium`、`high`、`extra_high`,默认 `high` |
+| 不包含 `high`,但包含 `xhigh` | `xhigh` |
+| 不包含 `high` / `xhigh`,但包含 `medium` | `medium` |
+| 只包含 `flash` | 返回 `quality_tier_unavailable`,除非请求显式传 `tier=flash` |
+| 未传 `--tier` | 暴露 `flash`、`medium`、`high`、`xhigh`,默认 `high` |
-因此,如果只以 `--tier flash` 启动裸 api-server,请求未指定 tier 时会使用 `flash`。doclib 的主动阅读默认选择策略应在调用 api-server 前解析为具体质量 tier,避免把用户主动阅读静默降级为 `flash`。
+因此,如果只以 `--tier flash` 启动裸 api-server,请求未指定 tier 时不应静默使用 `flash`。需要 `flash` 时调用方必须显式传 `tier=flash`;非 PDF/image 文件的批量归一规则见 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。
如果用户需要在同一端口提供多个 tier,可以重复 `--tier`;如果不同 tier 需要不同硬件、并发或生命周期策略,则启动多个 api-server 进程并由 doclib 或上层配置分别管理 URL。
@@ -73,7 +75,7 @@ mineru-kit api-server --tier medium --tier high --port 8000
mineru-kit api-server --tier high --language en --ocr-mode ocr --disable-image-analysis
```
-未传 `--tier` 时暴露 `flash`、`medium`、`high`、`extra_high`;请求未指定 tier 时默认 `high`。
+未传 `--tier` 时暴露 `flash`、`medium`、`high`、`xhigh`;PDF/image 请求未指定 tier 时默认 `high`。
启动完成后,HTTP API 不暴露 backend。`GET /v1/tiers` 也不新增 backend 字段;调用方如需推断实现,只能从 `current_model` 做弱推断。
diff --git a/docs/next/cli/mineru-kit-parse.md b/docs/next/cli/mineru-kit-parse.md
index 352d95a5..71563edb 100644
--- a/docs/next/cli/mineru-kit-parse.md
+++ b/docs/next/cli/mineru-kit-parse.md
@@ -113,9 +113,10 @@ local 模式支持:
2. 可以只传 `--backend`
3. 可以同时传 `--tier` 和 `--backend`
4. 如果二者不兼容,直接报错
-5. `--tier` 与 `--backend` 都不传时,当前默认为 `high`
-6. 默认不会落到 `flash`
-7. `flash` 只能显式指定:
+5. `--tier` 与 `--backend` 都不传时,PDF/image 当前默认为 `high`
+6. 单文件 Office/HTML 未指定 tier 时归一为 `flash`;显式指定质量 tier 时报错
+7. 多文件或目录输入按批量规则处理,Office/HTML 即使遇到质量 tier 也归一为 `flash`
+8. PDF/image 的 `flash` 只能显式指定:
- `--tier flash`
- `--backend flash`
@@ -132,10 +133,11 @@ remote 模式通过以下参数进入:
1. `--remote` 与 `--remote-url` 互斥
2. remote 模式允许传 `--tier`
3. remote 模式禁止传 `--backend`
-4. remote 模式未传 `--tier` 时,使用目标服务提供的最高 tier
+4. remote 模式未传 `--tier` 时,PDF/image 使用目标服务的默认选择策略,按 `high` -> `xhigh` -> `medium` 选择
5. remote 模式传了 `--tier` 时:
- 服务提供该 tier,则按该 tier 解析
- 服务不提供该 tier,则报错
+6. `mineru-kit parse` 是低层工具特例,允许 remote 模式处理 Office/HTML 等非 PDF/image 输入;这类输入按批量归一规则使用 `flash` 语义。
## 6. 参数分组
diff --git a/docs/next/cli/mineru-kit.md b/docs/next/cli/mineru-kit.md
index 9a7639e0..7cb44d49 100644
--- a/docs/next/cli/mineru-kit.md
+++ b/docs/next/cli/mineru-kit.md
@@ -49,8 +49,8 @@
- 只支持文件和目录输入,不支持 stdin、路径列表、URL 输入和递归目录。
- `--output` 必填。
-- local 模式支持 `tier` 与 `backend`;二者都不传时当前默认使用 `high` 对应 backend。
-- remote 模式支持 `--remote` / `--remote-url` / `--api-key`,允许传 `--tier`,但禁止传 `--backend`。
+- local 模式支持 `tier` 与 `backend`;PDF/image 二者都不传时当前默认使用 `high` 对应 backend,仅支持 flash tier 的输入按 ADR-0024 归一。
+- remote 模式支持 `--remote` / `--remote-url` / `--api-key`,允许传 `--tier`,但禁止传 `--backend`;`mineru-kit parse` 允许 remote 处理非 PDF/image 输入。
详细命令契约见 [ADR-0016](../decisions/0016-mineru-kit-parse-command.md)。
diff --git a/docs/next/cli/mineru-library.md b/docs/next/cli/mineru-library.md
index 99821dc2..0382951e 100644
--- a/docs/next/cli/mineru-library.md
+++ b/docs/next/cli/mineru-library.md
@@ -175,7 +175,7 @@ watch 用于自动发现文件并建立本地索引。
- watch 默认使用 `flash`。
- watch 的目标是发现和搜索,不是最终阅读质量。
-- Agent 或用户主动读取文档时,应通过 `mineru parse` 使用默认选择策略或显式 tier。
+- Agent 或用户主动读取 PDF/image 文档时,应通过 `mineru parse` 使用默认选择策略或显式 tier;Office/text/HTML 读取按 [ADR-0024](../decisions/0024-file-type-tier-normalization.md) 归一为 `flash` 语义。
- 可插拔设备不可达时,watch 标记为 `unreachable`,该 watch 下的 active 文件标记为 `unreachable`,而不是永久删除。
- 可插拔设备恢复时,watch 和文件恢复为 `active`,并立即对该 watch 执行一次 scan。
- scan 发现文件真实缺失时,文件标记为 `deleted`,保留 `sha256`。
@@ -334,9 +334,9 @@ mineru config parsing-rules add "*/论文/*" --tier medium --pages all
mineru config parsing-rules add "*/合同/*" --tier high --remote
```
-规则命中时,系统必须检查本地或远端能力是否支持对应 tier。不满足时应记录错误或提示用户,不静默降级到 `flash`。
+parsing-rule 的 `tier` 和 `remote` 只适用于 PDF 和 image。Office、text 和 HTML 命中规则时忽略 `tier` 和 `remote`,按 `flash` 解析,并且 parse row 记录为 `flash`。
-parsing-rules 允许不指定 tier。执行时必须解析成实际实体 tier,并记录实际 tier;默认选择不能解析为 `flash`。
+PDF/image 命中规则时,系统必须检查本地或远端能力是否支持对应 tier。rule 未指定 tier 时,按 `high` -> `xhigh` -> `medium` -> `flash` 选择可用 tier,并记录实际 tier。完整文件类型归一规则见 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。
## 已收敛规则
diff --git a/docs/next/cli/mineru-parse.md b/docs/next/cli/mineru-parse.md
index c9b018ee..19f88d57 100644
--- a/docs/next/cli/mineru-parse.md
+++ b/docs/next/cli/mineru-parse.md
@@ -22,7 +22,7 @@ read(locator) = read existing parsed content by stable locator
设计原则:
- 隐私优先:不显式 `--remote` 就不上传文档。
-- 质量优先:未指定 tier 时使用默认选择策略,不会解析为 `flash`。
+- 质量优先:PDF/image 未指定 tier 时使用默认选择策略,不会解析为 `flash`;Office/text/HTML 未指定 tier 时归一为 `flash`。
- Agent-native:默认适合 STDOUT、有限上下文和渐进式阅读。
- 先入库后输出:解析结果先写入本地文档库,再输出。
- 去重缓存:相同 SHA256 和实体 tier 可复用 done 缓存;`--force` 跳过 done 缓存,但可复用 active parse,不作废旧缓存。
@@ -47,7 +47,7 @@ mineru parse <file> [flags]
| Flag | 类型 | 默认 | 说明 |
|------|------|------|------|
-| `--tier` | `flash` / `medium` / `high` / `extra_high` | 不传 | 解析 tier;省略时由服务端决定;语义见 [解析 Tier](../tiers.md) |
+| `--tier` | `flash` / `medium` / `high` / `xhigh` | 不传 | 解析 tier;省略时由服务端决定;语义见 [解析 Tier](../tiers.md) |
| `-p, --pages` | range | 不传 | 分页文档的页码范围;`all` 表示全部页 |
| `--after` | cursor | 不传 | 从服务端返回的 cursor 继续读取 |
| `--limit` | int | `30000` | STDOUT 内容软字符上限 |
@@ -73,7 +73,7 @@ mineru parse <file> [flags]
`mineru parse` 未指定 `--tier` 时使用默认选择策略。
-默认选择策略通过当前目标 parse-server 的能力发现,按 `extra_high`、`high`、`medium` 的顺序选择最高可用的非 `flash` tier。如果找不到这些质量 tier,返回可解释错误。
+PDF/image 的默认选择策略通过当前目标 parse-server 的能力发现,按 [解析 Tier](../tiers.md) 定义的 `high` -> `xhigh` -> `medium` 顺序选择。如果找不到可用质量 tier,返回可解释错误。Office/text/HTML 归一为 `flash` 语义,详见 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。
`flash` 只有在用户显式指定 `--tier flash` 时才作为最终解析结果返回。
@@ -85,7 +85,7 @@ mineru parse <file> [flags]
2. 带 `--remote`:允许上传文档到 config 指定远端或默认 `mineru.net/api`。
3. 本地能力不足:返回错误和修复建议,不静默上传。
4. 用户显式选择 `--tier flash`:允许返回 `flash` 结果。
-5. 未指定 tier:使用默认选择策略,不可降级到 `flash`。
+5. 未指定 tier:PDF/image 使用默认选择策略,不可降级到 `flash`;Office/text/HTML 归一为 `flash`。
当本地能力不足、默认选择无法解析、远端未显式允许或 parse-server 不支持请求 tier 时,错误码见 [错误码体系](../errors.md)。
@@ -149,7 +149,7 @@ marker 是 Agent 的控制协议,不应依赖自然语言猜测。
- `--no-wait`:立即返回任务状态。
- 超过等待时间:返回可继续查询的状态,而不是丢失任务。
-缓存实体应落到解析后的实体 tier,例如 `medium` 或 `high`。
+缓存实体应落到解析后的实体 tier,例如 `medium`、`high` 或 `xhigh`。
## 未决问题
diff --git a/docs/next/cli/mineru-read.md b/docs/next/cli/mineru-read.md
index c4352bba..7d93fe4d 100644
--- a/docs/next/cli/mineru-read.md
+++ b/docs/next/cli/mineru-read.md
@@ -46,11 +46,11 @@ doc:{short_id}/tier:{tier}/page:{page_no}/block:{block_no}/char:{offset}
规则:
- `short_id` 是 doclib 为文档生成的稳定短 ID。
-- `tier` 取值为 `flash`、`medium`、`high`。
+- `tier` 取值为 `flash`、`medium`、`high`、`xhigh`。
- `page_no` 和 `block_no` 使用 1-based 编号。
- `char:{offset}` 使用 block 渲染文本内的 0-based 字符 offset。
-当只给出 `doc:{short_id}` 时,系统会选择当前已缓存的最高可用非 `flash` tier;如果不存在 `medium` 或 `high` 结果,则返回错误,不静默降级到 `flash`。
+当只给出 `doc:{short_id}` 时,系统不会创建新解析,而是在当前已缓存的非 `flash` 质量 tier 中选择最高质量结果,顺序为 `xhigh` -> `high` -> `medium`。如果不存在非 `flash` 质量 tier 结果,则返回错误,不静默降级到 `flash`。
## 4. 核心参数
diff --git a/docs/next/cli/mineru-server.md b/docs/next/cli/mineru-server.md
index f712dd90..87e87506 100644
--- a/docs/next/cli/mineru-server.md
+++ b/docs/next/cli/mineru-server.md
@@ -129,11 +129,11 @@ local parse-server 是独立进程,由 `mineru-kit api-server` 提供。doclib
| 模式 | 行为 |
|------|------|
-| `disabled` | 不启用本地 medium/high 解析 |
+| `disabled` | 不启用本地质量解析 |
| `managed` | doclib 启停时自动管理 parse-server |
| `self_hosted` | 用户自己启动 parse-server,doclib 只连接 URL |
-默认选择策略需要通过 local 或 remote parse-server 的能力发现解析为可用的非 `flash` tier,例如 `medium`、`high` 或 `extra_high`。
+PDF/image 默认选择策略需要通过 local 或 remote parse-server 的能力发现解析为可用的非 `flash` tier,选择顺序见 [解析 Tier](../tiers.md)。Office/text/HTML 的归一规则见 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。
## 6. 崩溃恢复
diff --git a/docs/next/cli/mineru.md b/docs/next/cli/mineru.md
index 67818808..b7d0fca7 100644
--- a/docs/next/cli/mineru.md
+++ b/docs/next/cli/mineru.md
@@ -75,7 +75,7 @@
-> 输出到 STDOUT 或文件
```
-纯文本文件可以直接读取;Office 和 HTML 通常可本地 CPU 解析;PDF 和图片按 tier 路由到默认选择、`flash`、`medium` 或 `high`。
+纯文本文件可以直接读取;Office 和 HTML 通常可本地 CPU 解析;PDF 和图片按 tier 路由到默认选择、`flash`、`medium`、`high` 或 `xhigh`。
## 5. parse 与 read
diff --git a/docs/next/config.md b/docs/next/config.md
index ee64aceb..afdbedd2 100644
--- a/docs/next/config.md
+++ b/docs/next/config.md
@@ -25,7 +25,7 @@ MinerU 有两类配置:
配置必须服务两个产品原则:
- 隐私优先:任何配置都不能导致静默上传文档。
-- 质量优先:主动阅读未指定 tier 时使用默认选择策略,不能静默降级到 `flash`。
+- 质量优先:PDF/image 主动阅读未指定 tier 时使用默认选择策略,不能静默降级到 `flash`;Office/text/HTML 按实际能力归一为 `flash`。
## 2. 两阶段配置模型
@@ -121,7 +121,7 @@ SDK client 显式参数属于当前调用方传入的请求上下文;当它最
## 5. Parse-server 配置
-parse-server 是 `medium` / `high` / `extra_high` 等质量 tier 的解析能力来源。它可以是本地独立进程,也可以是远端 `mineru.net/api` 或当前代码配置的 staging endpoint。
+parse-server 是 `medium` / `high` / `xhigh` 等质量 tier 的解析能力来源。它可以是本地独立进程,也可以是远端 `mineru.net/api` 或当前代码配置的 staging endpoint。
### 5.1 Local parse-server
@@ -229,11 +229,11 @@ mineru config parsing-rules add "*/合同/*" --tier high --remote
约束:
-- 规则必须显式指定 remote,才允许上传远端。
-- 规则命中的 tier 必须经过能力检查。
-- 能力不足时记录结构化错误,不静默降级到 `flash`。
-- 允许不指定 tier。执行时必须通过能力发现解析为实体 tier,并只记录实际使用的实体 tier。
-- 默认选择策略不能解析为 `flash`。
+- 对 PDF/image,规则必须显式指定 remote,才允许上传远端。
+- 对 PDF/image,规则命中的 tier 必须经过能力检查。
+- 对 PDF/image,规则未指定 tier 时按 `high` -> `xhigh` -> `medium` -> `flash` 选择,并只记录实际使用的实体 tier。
+- 对 Office/text/HTML,parsing-rule 的 tier 和 remote 不生效,实际按 `flash` 记录。
+- 完整归一规则见 [ADR-0024](decisions/0024-file-type-tier-normalization.md)。
### 8.3 Exclude
diff --git a/docs/next/decisions/0003-parse-request-wait-batches.md b/docs/next/decisions/0003-parse-request-wait-batches.md
index 5aeeb32e..101d7acf 100644
--- a/docs/next/decisions/0003-parse-request-wait-batches.md
+++ b/docs/next/decisions/0003-parse-request-wait-batches.md
@@ -90,7 +90,7 @@ CLI wait 必须使用 id 级状态查询。
### 方案 B: force 严格总是创建新 batch
-拒绝。语义简单,但会在已有同页 active batch 时重复消耗算力,尤其对 `medium` / `high` 和 remote 解析成本较高。
+拒绝。语义简单,但会在已有同页 active batch 时重复消耗算力,尤其对质量 tier 和 remote 解析成本较高。
### 方案 C: CLI 继续轮询聚合状态
diff --git a/docs/next/decisions/0012-doclib-block-locator.md b/docs/next/decisions/0012-doclib-block-locator.md
index f6e89b71..96ffeb70 100644
--- a/docs/next/decisions/0012-doclib-block-locator.md
+++ b/docs/next/decisions/0012-doclib-block-locator.md
@@ -44,7 +44,7 @@ doc:ab12cd3/tier:medium/page:1/block:3
| 字段 | 说明 |
|------|------|
| `short_id` | `docs.short_id`,见 [ADR-0011](0011-doclib-doc-short-id.md)。 |
-| `tier` | 实际解析档位: `flash` / `medium` / `high`。 |
+| `tier` | 实际解析档位: `flash` / `medium` / `high` / `xhigh`。 |
| `page_no` | 1-based 页号。 |
| `block_no` | 1-based block 号。 |
diff --git a/docs/next/decisions/0016-mineru-kit-parse-command.md b/docs/next/decisions/0016-mineru-kit-parse-command.md
index eb3bf6b0..cdde44fd 100644
--- a/docs/next/decisions/0016-mineru-kit-parse-command.md
+++ b/docs/next/decisions/0016-mineru-kit-parse-command.md
@@ -105,7 +105,7 @@ mineru-kit parse <input...> -o <output> [flags]
3. `--remote` 与 `--remote-url` 互斥
4. remote 模式下允许传 `--tier`
5. remote 模式下禁止传 `--backend`
-6. remote 模式未传 `--tier` 时,使用目标服务提供的最高 tier
+6. remote 模式未传 `--tier` 时,PDF/image 使用目标服务的默认选择策略,按 `high` -> `xhigh` -> `medium` 选择
7. remote 模式传了 `--tier` 时:
- 服务提供该 tier,则按该 tier 解析
- 服务不提供该 tier,则报错
diff --git a/docs/next/decisions/0017-mineru-kit-api-server-command.md b/docs/next/decisions/0017-mineru-kit-api-server-command.md
index 4076eea3..57cbbda7 100644
--- a/docs/next/decisions/0017-mineru-kit-api-server-command.md
+++ b/docs/next/decisions/0017-mineru-kit-api-server-command.md
@@ -44,12 +44,14 @@ managed 是生命周期管理方式,不是用户直接操作的独立命令产
### 3. 单进程 tier 规则
-一个 `mineru-kit api-server` 进程只服务一个 tier。
+一个 `mineru-kit api-server` 进程可以通过重复 `--tier` 暴露一个或多个 tier。
支持的公开 tier:
+- `flash`
- `medium`
- `high`
+- `xhigh`
规则:
@@ -57,7 +59,7 @@ managed 是生命周期管理方式,不是用户直接操作的独立命令产
2. `--backend` 是高级覆盖参数
3. 可以同时传 `--tier` 和 `--backend`
4. 如果二者不兼容,启动直接报错
-5. 未传 `--tier` 时暴露 `flash`、`medium`、`high`、`extra_high`;请求未指定 tier 时默认 `high`
+5. 未传 `--tier` 时暴露 `flash`、`medium`、`high`、`xhigh`;请求未指定 tier 时默认 `high`
### 4. backend 的公开边界
diff --git a/docs/next/decisions/0022-doclib-file-type-tier-remote-semantics.md b/docs/next/decisions/0022-doclib-file-type-tier-remote-semantics.md
index 6bbfb212..8099f17b 100644
--- a/docs/next/decisions/0022-doclib-file-type-tier-remote-semantics.md
+++ b/docs/next/decisions/0022-doclib-file-type-tier-remote-semantics.md
@@ -1,20 +1,20 @@
# ADR-0022: Doclib 文件类型、Tier 与 Remote 语义
-状态: Accepted
+状态: Accepted,已由 ADR-0024 补充
日期: 2026-06-29
-相关文档: ../cli/mineru-parse.md, ../tiers.md, ../errors.md
+相关文档: ../cli/mineru-parse.md, ../tiers.md, ../errors.md, 0024-file-type-tier-normalization.md
## 背景
`mineru parse` 支持多种输入格式,但不同格式背后的解析路径并不相同:
-- PDF 和 image 可以进入质量 tier 路径,支持 `flash`、`medium` 和 `high`。
+- PDF 和 image 可以进入质量 tier 路径,支持 `flash`、`medium`、`high` 和 `xhigh`。
- Office 文件走专门的 Office parser,实际只支持 `flash`。
- text / html 类输入不走 PDF 质量后端,也只具备 `flash` 语义。
-此前 Office 文件显式传入 `--tier medium` 或 `--tier high` 时,会在服务层静默覆盖为 `flash`。CLI 和 JSON 输出只显示最终 tier,无法表达“用户请求被忽略”。这会让自动化脚本、测试和用户判断误以为 medium/high 已被执行。
+此前 Office 文件显式传入质量 tier 时,会在服务层静默覆盖为 `flash`。CLI 和 JSON 输出只显示最终 tier,无法表达“用户请求被忽略”。这会让自动化脚本、测试和用户判断误以为质量 tier 已被执行。
-同时,image 文件需要支持显式 `parse` 并进入 doclib,但 watch / scan 不应把目录中发现的图片自动当作文档纳入库。`--remote` 也需要明确边界:remote 后端只用于质量解析,不支持 `flash`,也不支持非 PDF / image 输入。
+同时,image 文件需要支持显式 `parse` 并进入 doclib,但 watch / scan 不应把目录中发现的图片自动当作文档纳入库。doclib 单对象主动解析的 `--remote` 也需要明确边界:remote 后端只用于质量解析,不支持 `flash`,也不支持非 PDF / image 输入。
因此需要把文件类型、tier、remote 的组合语义显式化,避免静默降级。
@@ -39,14 +39,14 @@ image 扩展名只进入 `PARSEABLE_EXTENSIONS`,不进入 `DISCOVERABLE_EXTENS
质量 tier 只对 PDF 和 image 有意义。
-| 文件类型 | `flash` | `medium` | `high` |
-|----------|---------|------------|-------|
-| PDF | 支持 | 支持 | 支持 |
-| image | 支持 | 支持 | 支持 |
-| Office (`docx` / `pptx` / `xlsx`) | 支持 | 不支持 | 不支持 |
-| text / html (`txt` / `md` / `csv` / `rst` / `tex` / `html` / `htm`) | 支持 | 不支持 | 不支持 |
+| 文件类型 | `flash` | `medium` | `high` | `xhigh` |
+|----------|---------|----------|--------|---------|
+| PDF | 支持 | 支持 | 支持 | 支持 |
+| image | 支持 | 支持 | 支持 | 支持 |
+| Office (`docx` / `pptx` / `xlsx`) | 支持 | 不支持 | 不支持 | 不支持 |
+| text / html (`txt` / `md` / `csv` / `rst` / `tex` / `html` / `htm`) | 支持 | 不支持 | 不支持 | 不支持 |
-当非 PDF / image 文件显式请求 `medium` 或 `high` 时,doclib 不再自动降级为 `flash`,而是返回 `InvalidRequestError`:
+当非 PDF / image 文件在 doclib 单对象主动解析中显式请求质量 tier 时,doclib 不再自动降级为 `flash`,而是返回 `InvalidRequestError`。批量、parsing-rule、API Server 和 mineru-kit 的归一化例外见 [ADR-0024](0024-file-type-tier-normalization.md)。
- `code`: `tier_unsupported_for_file_type`
- `param`: `tier`
@@ -55,16 +55,16 @@ image 扩展名只进入 `PARSEABLE_EXTENSIONS`,不进入 `DISCOVERABLE_EXTENS
### Remote 能力矩阵
-`--remote` 只支持 PDF 和 image,并且不支持 `flash` tier。
+doclib 单对象主动解析中的 `--remote` 只支持 PDF 和 image,并且不支持 `flash` tier。
| 文件类型 | `--remote` |
|----------|------------|
-| PDF | 支持 `medium` / `high`,不支持 `flash` |
-| image | 支持 `medium` / `high`,不支持 `flash` |
+| PDF | 支持非 `flash` 质量 tier,不支持 `flash` |
+| image | 支持非 `flash` 质量 tier,不支持 `flash` |
| Office | 不支持 |
| text / html | 不支持 |
-当非 PDF / image 文件请求 `--remote` 时,doclib 返回 `InvalidRequestError`:
+当非 PDF / image 文件在 doclib 单对象主动解析中请求 `--remote` 时,doclib 返回 `InvalidRequestError`:
- `code`: `remote_unsupported_for_file_type`
- `param`: `remote`
@@ -74,15 +74,15 @@ image 扩展名只进入 `PARSEABLE_EXTENSIONS`,不进入 `DISCOVERABLE_EXTENS
- `code`: `tier_unsupported_for_remote`
- `param`: `tier`
-当 PDF / image 请求 `--remote` 且未显式传入 tier 时,继续使用现有默认 tier 解析逻辑:根据 remote parse server health 选择可用的最高质量 tier。
+当 PDF / image 请求 `--remote` 且未显式传入 tier 时,继续使用 [解析 Tier](../tiers.md) 中定义的默认选择策略。
### 错误优先级
当多个参数同时冲突时,优先返回更贴近显式冲突参数的错误:
-1. `--remote` 与非 PDF / image 文件冲突时,返回 `remote_unsupported_for_file_type`。
+1. doclib 单对象主动解析中,`--remote` 与非 PDF / image 文件冲突时,返回 `remote_unsupported_for_file_type`。
2. PDF / image 的 `--remote --tier flash` 冲突时,返回 `tier_unsupported_for_remote`。
-3. 非 PDF / image 的 `--tier medium/high` 冲突时,返回 `tier_unsupported_for_file_type`。
+3. doclib 单对象主动解析中,非 PDF / image 的质量 tier 冲突时,返回 `tier_unsupported_for_file_type`。
例如 `sample.docx --remote --tier flash` 优先报告 remote 不支持该文件类型,而不是报告 remote 不支持 flash。
@@ -95,10 +95,10 @@ image 扩展名只进入 `PARSEABLE_EXTENSIONS`,不进入 `DISCOVERABLE_EXTENS
原因:
- 自动化脚本可能只检查退出码和 `status=done`,warning / tip 容易被忽略。
-- 用户显式指定 `medium/high` 表示质量预期,静默或半静默降级会制造错误判断。
+- 用户显式指定质量 tier 表示质量预期,静默或半静默降级会制造错误判断。
- 当前响应模型只有 `tip`,没有稳定的 warnings 列表;把冲突语义塞进提示字段不够可靠。
-### 方案 B:为所有格式保留 `medium/high` 名义兼容
+### 方案 B:为所有格式保留质量 tier 名义兼容
未采用。
@@ -134,9 +134,9 @@ image 扩展名只进入 `PARSEABLE_EXTENSIONS`,不进入 `DISCOVERABLE_EXTENS
### 对兼容性
-- 这是有意的行为收紧。依赖 `docx --tier medium/high` 或非 PDF / image `--remote` 成功退出的脚本需要调整。
+- 这是有意的 doclib 单对象主动解析行为收紧。依赖非 PDF / image 显式请求质量 tier 或 `--remote` 成功退出的脚本需要调整。
- 未显式指定质量 tier 的 Office、text、html 解析仍保持 `flash` 语义。
-- PDF / image 的本地 `flash` 和本地 / remote `medium/high` 路径保持可用。
+- PDF / image 的本地 `flash` 和本地 / remote 质量 tier 路径保持可用。
### 对测试
@@ -144,8 +144,8 @@ image 扩展名只进入 `PARSEABLE_EXTENSIONS`,不进入 `DISCOVERABLE_EXTENS
- 显式 parse image 能入库并创建 parse 任务。
- watch / scan 不自动发现 image。
-- 非 PDF / image 请求 `medium/high` 报 `tier_unsupported_for_file_type`。
-- 非 PDF / image 请求 `--remote` 报 `remote_unsupported_for_file_type`。
+- doclib 单对象主动解析中,非 PDF / image 请求质量 tier 报 `tier_unsupported_for_file_type`。
+- doclib 单对象主动解析中,非 PDF / image 请求 `--remote` 报 `remote_unsupported_for_file_type`。
- PDF / image 请求 `--remote --tier flash` 报 `tier_unsupported_for_remote`。
## 后续动作
diff --git a/docs/next/decisions/0024-file-type-tier-normalization.md b/docs/next/decisions/0024-file-type-tier-normalization.md
new file mode 100644
index 00000000..c2cdfc81
--- /dev/null
+++ b/docs/next/decisions/0024-file-type-tier-normalization.md
@@ -0,0 +1,168 @@
+# ADR-0024: 文件类型与 Tier 归一化语义
+
+状态: Accepted
+日期: 2026-07-09
+相关文档: ../tiers.md, ../cli/mineru-parse.md, ../cli/mineru-kit-parse.md, ../api/parse-jobs.md, 0022-doclib-file-type-tier-remote-semantics.md
+
+## 背景
+
+MinerU 同时支持 PDF、image、Office、text 和 HTML 输入,但这些输入并不具备相同的 tier 能力。
+
+PDF 和 image 支持质量 tier: `flash`、`medium`、`high`、`xhigh`。Office、text 和 HTML 当前只有 `flash` 语义,没有对应的质量 tier。此前不同入口对“非 PDF/image + 质量 tier”的处理不完全一致:
+
+- 有的入口报错。
+- 有的入口静默走 Office / text / HTML parser。
+- parsing-rule 可能创建 `tier=high` 等 parse row,但实际执行的仍是 Office / flash 语义。
+
+这种不一致会让 parse row、缓存目录、locator 和用户看到的实际解析能力脱节。因此需要定义一套按操作类型区分的归一化规则。
+
+本 ADR 细化并部分修订 ADR-0022。ADR-0022 中 doclib 主动单文件解析的严格错误语义仍保留;本 ADR 补充 batch、parsing-rule、API Server 和 mineru-kit 的例外。
+
+## 决策
+
+### 1. 文件类型分组
+
+MinerU 在 tier 语义上把输入分为两组:
+
+| 分组 | 文件类型 | Tier 能力 |
+|------|----------|-----------|
+| 支持多 tier 的输入 | PDF、image | `flash`、`medium`、`high`、`xhigh` |
+| 仅支持 flash tier 的输入 | Office、text、HTML | 仅 `flash` 语义 |
+
+Office、text 和 HTML 即使通过高层接口传入了 `medium`、`high` 或 `xhigh`,也不能把结果记录为这些质量 tier,除非未来另有 ADR 明确引入对应能力。
+
+### 2. 单对象主动操作
+
+单对象主动操作包括:
+
+- `mineru parse <single-file>` 经 doclib 解析。
+- `DoclibClient.ensure_parse(ParseRequest(...))`。
+- SDK 直接解析单个文件。
+- `mineru-kit parse` 展开后只有一个输入文件。
+
+规则:
+
+| 输入类型 | 未指定 tier | 指定 `flash` | 指定 `medium/high/xhigh` |
+|----------|-------------|--------------|--------------------------|
+| PDF / image | 使用该入口默认质量选择策略 | 使用 `flash` | 使用指定质量 tier |
+| Office / text / HTML | 归一为 `flash` | 使用 `flash` | 报错 |
+
+因此,单对象主动操作中,用户显式指定质量 tier 表达明确质量预期。对于没有质量 tier 能力的输入,系统不能静默降级。
+
+### 3. 批量操作
+
+批量操作包括:
+
+- API Server v1 parse job。
+- `mineru-kit parse` 展开后包含多个输入文件,或输入目录。
+- parsing-rule 触发的后台解析。
+
+批量操作的目标是处理一组异构文件。为了避免一个 Office、text 或 HTML 文件阻断整个批次,仅支持 flash tier 的输入允许静默归一为 `flash`。
+
+规则:
+
+| 输入类型 | 未指定 tier | 指定 `flash` | 指定 `medium/high/xhigh` |
+|----------|-------------|--------------|--------------------------|
+| PDF / image | 使用该入口默认选择策略 | 使用 `flash` | 使用指定质量 tier |
+| Office / text / HTML | 归一为 `flash` | 使用 `flash` | 归一为 `flash` |
+
+批量操作中,非 PDF/image 的实际 parse row、缓存目录、locator 和 metadata 必须记录 `flash`,不能记录用户传入的质量 tier。
+
+API Server 当前只有 job 级 `tier` 字段,暂不扩展 file-level effective tier 字段。因此 API job 响应中的 job tier 可以表示请求 tier;但内部执行非 PDF/image 文件时,应按 `flash` 语义处理,不产生伪质量缓存。
+
+### 4. Parsing-Rule 语义
+
+parsing-rule 是批量/后台规则,不是用户对单个文件的显式 parse 请求。
+
+规则:
+
+- `tier` 和 `remote` 参数只适用于 PDF 和 image。
+- Office、text 和 HTML 命中 parsing-rule 时,忽略 rule 中的 `tier` 和 `remote`,按 `flash` 解析。
+- PDF/image 命中 parsing-rule 且指定 tier 时,使用 rule tier。
+- PDF/image 命中 parsing-rule 但未指定 tier 时,按以下顺序选择可用 tier:
+
+```text
+high -> xhigh -> medium -> flash
+```
+
+这与用户主动阅读默认选择不同。parsing-rule 是后台批量策略,可以接受最后降级到 `flash`,因为 watch 自动发现本身也接受 `flash`。
+
+### 5. Remote 语义
+
+remote 的含义取决于入口:
+
+| 入口 | 非 PDF/image + remote |
+|------|----------------------|
+| doclib / `mineru parse` 单文件主动解析 | 报错 |
+| parsing-rule | 忽略 remote,按 `flash` |
+| API Server job | 不适用;API Server 自身就是解析服务 |
+| `mineru-kit parse` | 允许,作为低层工具特例 |
+
+doclib 单文件主动解析中,`remote=true` 表示用户显式要求把该文件交给 remote parse-server。因为 remote parse-server 只支持 PDF/image,该组合必须报错,不能静默改成本地 `flash`,否则会改变用户显式选择的执行路径和隐私语义。
+
+`mineru-kit parse` 是低层工具,允许 `--remote` 处理非 PDF/image 输入;当非 PDF/image 不能使用质量 tier 时,按批量归一规则处理。
+
+## 替代方案
+
+### 方案 A: Office/text/HTML 一律静默忽略 tier
+
+未采用。
+
+原因:
+
+- 单文件主动操作中,用户显式指定质量 tier 通常表示明确质量预期。
+- 静默忽略会让脚本和用户误以为质量 tier 已执行。
+- doclib 的 parse row、缓存和 locator 应准确表达实际结果能力。
+
+### 方案 B: Office/text/HTML 一律遇到质量 tier 报错
+
+未采用。
+
+原因:
+
+- 批量任务经常包含混合文件类型。
+- parsing-rule 是后台批量策略,不应因为非 PDF/image 文件携带无效质量 tier 而阻断整个目录处理。
+- API Server v1 parse job 当前是多文件接口,也应支持异构输入。
+
+### 方案 C: 为 API Server 增加 file-level effective tier 字段
+
+暂不采用。
+
+原因:
+
+- 当前目标是先统一行为,不扩展 API response schema。
+- API job 的 job-level tier 可以继续表达请求 tier。
+- 如未来需要精确暴露每个文件的实际 tier,可另行设计 file-level effective tier 字段。
+
+## 影响
+
+### 对 doclib
+
+- doclib 单文件主动解析保持严格语义: 非 PDF/image 显式质量 tier 报错。
+- 非 PDF/image 未指定 tier 或指定 `flash` 时,实际记录为 `flash`。
+- parsing-rule 触发非 PDF/image 时,实际 parse row 必须为 `flash`。
+- parsing-rule 对 PDF/image 未指定 tier 时,允许 `high -> xhigh -> medium -> flash` 兜底。
+
+### 对 SDK 和 mineru-kit
+
+- SDK 单文件解析应按单对象主动操作语义处理。
+- `mineru-kit parse` 需要根据展开后的输入数量区分单对象和批量。
+- `mineru-kit parse --remote` 对非 PDF/image 是允许的低层工具特例。
+
+### 对 API Server
+
+- API Server job 按批量操作语义处理。
+- 非 PDF/image 文件即使 job tier 是质量 tier,执行时也按 `flash` 语义。
+- 暂不新增 file-level effective tier 字段。
+
+### 对缓存和 locator
+
+- 缓存键、parse row、locator 和产物 metadata 必须记录实际 tier。
+- 非 PDF/image 不应产生 `medium`、`high` 或 `xhigh` 缓存。
+
+## 后续动作
+
+1. 更新 doclib parsing-rule 入队逻辑,确保非 PDF/image 始终创建 `tier=flash` 的 parse row。
+2. 更新 parsing-rule 的 PDF/image 默认 tier 选择顺序为 `high -> xhigh -> medium -> flash`。
+3. 检查 SDK、mineru-kit 和 API Server,对单对象和批量操作分别应用本 ADR 的归一化规则。
+4. 同步更新 CLI、SDK 和 API 文档,避免继续表述为“所有入口统一报错”或“所有入口统一静默降级”。
diff --git a/docs/next/decisions/README.md b/docs/next/decisions/README.md
index 99c3e01b..a5dbbb42 100644
--- a/docs/next/decisions/README.md
+++ b/docs/next/decisions/README.md
@@ -51,6 +51,7 @@
| [ADR-0021](0021-doclib-local-transport-discovery.md) | Accepted | Doclib 本地 Transport 与 Endpoint Discovery |
| [ADR-0022](0022-doclib-file-type-tier-remote-semantics.md) | Accepted | Doclib 文件类型、Tier 与 Remote 语义 |
| [ADR-0023](0023-cli-runtime-contract.md) | Accepted | CLI Runtime 输出、错误与退出码集中契约 |
+| [ADR-0024](0024-file-type-tier-normalization.md) | Accepted | 文件类型与 Tier 归一化语义 |
## 模板
diff --git a/docs/next/errors.md b/docs/next/errors.md
index d65bfd52..15cafb97 100644
--- a/docs/next/errors.md
+++ b/docs/next/errors.md
@@ -21,7 +21,7 @@
- 错误格式兼容 OpenAI API。
- `message` 面向人类,`code`、`param`、`retryable` 和 `user_action` 面向程序。
- 不显式 `--remote` 时,不用错误恢复逻辑静默上传文档。
-- 默认选择策略永远不能降级为 `flash`;找不到 `medium/high` 时必须报错。
+- PDF/image 的默认选择策略不能降级为 `flash`;找不到非 `flash` 质量 tier 时必须报错。Office/text/HTML 这类仅支持 flash tier 的输入归一规则见 [ADR-0024](decisions/0024-file-type-tier-normalization.md)。
- 未来新增 `code` 只能追加,不改变既有语义。
## 3. 错误响应格式
@@ -72,7 +72,7 @@ Tier 语义见 [解析 Tier](tiers.md)。本节定义 `flash`、`medium`、`high
| type | code | HTTP | retryable | param | 触发场景 | user_action |
|------|------|------|:--:|-------|----------|-------------|
-| `engine_error` | `quality_tier_unavailable` | 503 | 否 | `tier` | 主动阅读场景需要 `medium/high`,但只有 `flash` 可用 | `start_parse_server_or_use_remote_or_explicit_flash` |
+| `engine_error` | `quality_tier_unavailable` | 503 | 否 | `tier` | PDF/image 主动阅读场景需要非 `flash` 质量 tier,但只有 `flash` 可用 | `start_parse_server_or_use_remote_or_explicit_flash` |
| `engine_error` | `no_engine` | 503 | 否 | `tier` | 本地无匹配实体 tier 的引擎 | `enable_parse_server_or_change_tier` |
| `engine_error` | `engine_unavailable` | 503 | 是 | null | 引擎进程未启动、崩溃或暂不可用 | `wait_or_restart_parse_server` |
| `engine_error` | `parse_server_unavailable` | 503 | 是 | null | local 或 remote parse-server 不可达 | `wait_or_check_parse_server` |
diff --git a/docs/next/everydoc-doclib-gap-review.md b/docs/next/everydoc-doclib-gap-review.md
index c12f22c0..68d511ef 100644
--- a/docs/next/everydoc-doclib-gap-review.md
+++ b/docs/next/everydoc-doclib-gap-review.md
@@ -12,7 +12,7 @@
- 去掉 everydoc 中显式暴露给用户的 `index` 概念。
- 在 doclib 中用“入库 + flash parse”替代 everydoc 的 lightweight index。
-- 将解析能力统一到 `flash` / `medium` / `high` 解析档位。
+- 将解析能力统一到 `flash` / `medium` / `high` / `xhigh` 解析档位。
- 将解析结果存储收敛为 Middle JSON,Markdown / Content List 等格式读取时即时转换。
尽管如此,everydoc 仍有一些已经设计清楚、甚至已经实现的 doclib 类能力。最近补齐文件变化检测时发现,MinerU doclib 曾遗漏 everydoc 中命名清晰的 `discover_file` / change detection 机制,因此有必要系统性回看 everydoc 中还有哪些设计值得回收。
@@ -276,7 +276,7 @@ MinerU 当前状态:
风险:
- Agent 很难按解析档位和文件类型控制搜索范围。
-- 用户无法快速判断结果来自低成本 flash、medium 还是 high 的充分解析。
+- 用户无法快速判断结果来自低成本 flash,还是 medium / high / xhigh 的质量解析。
P0 结论:
diff --git a/docs/next/glossary.md b/docs/next/glossary.md
index c8a87ff5..9b0ce9bb 100644
--- a/docs/next/glossary.md
+++ b/docs/next/glossary.md
@@ -51,14 +51,17 @@
|------|------|------|
| `flash` | 实体 tier | CPU-only、快速、低质量,用于 watch、发现和索引 |
| `medium` | 实体 tier | 面向普通本地硬件的模型解析能力 |
-| `high` | 实体 tier | 当前最高质量解析能力,可来自 `mineru.net/api` 或高端本地硬件 |
+| `high` | 实体 tier | 绝大多数场景足够好的高质量解析能力,可来自 `mineru.net/api` 或高端本地硬件 |
+| `xhigh` | 实体 tier | 最高质量解析能力,比 `high` 消耗更多算力和时间 |
规范:
- CLI/API/SDK 的用户可见参数应使用 `tier`。
- CLI 不传 `--tier`、HTTP API 省略 `tier` 或传 JSON `null`、Python SDK 传 `None` 表示使用默认选择策略。
-- 任务入队、缓存目录、产物 metadata 应记录实际使用的实体 tier,即 `flash`、`medium` 或 `high`。
-- 默认选择策略永远不能解析为 `flash`。
+- 任务入队、缓存目录、产物 metadata 应记录实际使用的实体 tier,即 `flash`、`medium`、`high` 或 `xhigh`。
+- PDF/image 的默认选择策略不能解析为 `flash`;Office/text/HTML 这类仅支持 flash tier 的输入归一规则见 [ADR-0024](decisions/0024-file-type-tier-normalization.md)。
+
+完整产品语义见 [解析 Tier](tiers.md)。
### 3.2 Backend
@@ -156,7 +159,7 @@
`parse-server` 是最终术语,中文统一为“解析服务”。它是无状态解析服务,提供 v1 Unified API,并且已经作为配置命名的一部分使用。
-它接收文件或本地路径,执行 `medium` / `high` 等解析能力,并返回解析任务与产物。它不管理长期文档库、watch、搜索索引或用户本地配置。
+它接收文件或本地路径,执行 `medium` / `high` / `xhigh` 等解析能力,并返回解析任务与产物。它不管理长期文档库、watch、搜索索引或用户本地配置。
文档中推荐写法:
@@ -356,7 +359,7 @@ Ingest 不等于 parse。Ingest 可以不产生完整 Middle JSON。
- 生成 Middle JSON 和 render output。
- 更新 parse 状态、缓存和内容索引。
-主动阅读场景下,未指定 tier 应使用默认选择策略,并至少解析到 `medium`。
+主动阅读场景下,未指定 tier 应使用默认选择策略,并解析到可用的非 `flash` 质量 tier。
## 8. 隐私与执行路径
@@ -501,7 +504,7 @@ Local Parse Server 默认不按公网 access level 做售卖或配额区分。
|----------|------|
| `tier` | 字段名、参数名、泛指解析档位 |
| Tier | 章节标题或概念名 |
-| `flash` / `medium` / `high` | tier 枚举值 |
+| `flash` / `medium` / `high` / `xhigh` | tier 枚举值 |
| parse-server | 最终术语,泛指解析服务 |
| Local Parse Server | 本地解析服务 |
| Remote Parse Server | 远端解析服务 |
diff --git a/docs/next/implementation-plan.md b/docs/next/implementation-plan.md
index 3430e9fb..f5b199f1 100644
--- a/docs/next/implementation-plan.md
+++ b/docs/next/implementation-plan.md
@@ -87,7 +87,7 @@ Agent 领取任务时,应先读本节。如果任务标记为“已实现需
| M0 | 锁定当前行为与测试骨架 | 后续任务有稳定测试入口。 |
| M1 | Middle JSON 和 ParseResult 基础设施 | JSON 批次可恢复、校验、渲染。 |
| M2 | doclib 主链路 | watch/ingest/parse/cache/compaction/read-time render 可闭环。 |
-| M3 | tier、privacy、parse-server 路由 | 默认选择、local/remote、medium/high 行为可验证。 |
+| M3 | tier、privacy、parse-server 路由 | 默认选择、local/remote、质量 tier 行为可验证。 |
| M4 | CLI / SDK / API 对齐 | 用户入口使用同一语义和错误模型。 |
| M5 | Agent-native 输出 | locator、marker、citation 基础可用。 |
| M6 | Telemetry | doclib server 聚合、flush、CLI 管理入口和隐私边界可验证。 |
@@ -1092,7 +1092,7 @@ M1 和 M2 的部分测试任务可以并行,但 `ParseResult.from_dict()`、JS
4. `tier=flash` 映射到 `flash` backend。
5. `tier=medium` 映射到默认 medium backend。
6. `tier=high` 映射到默认 high backend。
-7. `tier=None` 在 Tool SDK 场景中如果不能发现 medium/high,应报错,不静默 flash。
+7. `tier=None` 在 Tool SDK 的 PDF/image 场景中如果不能发现非 `flash` 质量 tier,应报错,不静默 flash;Office/HTML 这类仅支持 flash tier 的输入按实际能力归一为 `flash`。
完成边界:
@@ -1517,7 +1517,7 @@ P0 完成需要满足:
P1 完成需要满足:
-1. Agent 主动读取默认升级到 `medium` / `high`。
+1. Agent 主动读取默认升级到非 `flash` 质量 tier。
2. Markdown 可选输出 locator marker。
3. 高质量解析完成后刷新搜索索引。
diff --git a/docs/next/middle-json/envelope.md b/docs/next/middle-json/envelope.md
index de87f8e0..a9e2bdba 100644
--- a/docs/next/middle-json/envelope.md
+++ b/docs/next/middle-json/envelope.md
@@ -64,7 +64,7 @@
|------|------|:--:|------|
| `mineru_version` | string | 是 | 生成该结果的 MinerU 版本。 |
| `backend` | string | 是 | `hybrid`、`office`、`html`、`flash`。 |
-| `tier` | string 或 null | 是 | `flash`、`medium`、`high` 的解析结果语义;未经过 tier 解析的工具层结果可为 `null`。 |
+| `tier` | string 或 null | 是 | `flash`、`medium`、`high`、`xhigh` 的解析结果语义;未经过 tier 解析的工具层结果可为 `null`。 |
| `file` | object | 是 | 文件级信息。 |
| `features` | object | 是 | 本次解析启用的能力。 |
| `models` | object | 是 | 实际模型信息。 |
diff --git a/docs/next/middle-json/structured-content-schema.md b/docs/next/middle-json/structured-content-schema.md
index 6deb991c..718fce05 100644
--- a/docs/next/middle-json/structured-content-schema.md
+++ b/docs/next/middle-json/structured-content-schema.md
@@ -78,7 +78,7 @@ Structured Content 是从 Middle JSON render 得到的结构化内容 JSON。它
约束:
-- `tier` 只记录实际使用的实体 tier: `flash` / `medium` / `high`。
+- `tier` 只记录实际使用的实体 tier: `flash` / `medium` / `high` / `xhigh`。
- 不记录 `requested_tier` / `resolved_tier`。
- `backend` 是实现信息,普通客户端不应依赖它做产品逻辑。
diff --git a/docs/next/open-questions.md b/docs/next/open-questions.md
index bc0bf8cc..f27b7367 100644
--- a/docs/next/open-questions.md
+++ b/docs/next/open-questions.md
@@ -23,7 +23,7 @@
| 规则 | 当前结论 |
|------|----------|
| `parse-server` | 最终术语,中文为“解析服务”;此前误写的相关术语不作为项目概念使用。 |
-| 默认选择策略 | 只会解析为可用的非 `flash` 质量 tier;当前顺序为 `extra_high` > `high` > `medium`。 |
+| 默认选择策略 | 以 [解析 Tier](tiers.md) 为准;PDF/image 默认读取不会解析为 `flash`,Office/text/HTML 归一规则见 [ADR-0024](decisions/0024-file-type-tier-normalization.md)。 |
| 实际 tier 记录 | 任务、缓存、产物和 metadata 只记录实际使用的实体 tier,不记录 `requested_tier` / `resolved_tier`。 |
| `flash` | 长期存在,既是一个解析档位,也是 PDF 快速解析 backend 名称。 |
| doclib 产物 | `parsed/` 目录持久化按页组织的 Middle JSON 批次文件和必要图片 sidecar;Markdown、Content List、HTML 读取时转换。 |
@@ -36,8 +36,8 @@
| Force 与 invalidate | `--force` 跳过 done cache,可复用 active parse,只为未覆盖页创建新 parse;invalidate 才改变旧缓存可用性,详见 [ADR-0002](decisions/0002-force-vs-invalidate.md)。 |
| doclib HTTP API | 本地 doclib HTTP API 使用 `/docs`、`/parses`、`/search` 和 `POST /invalidate`,详见 [ADR-0004](decisions/0004-doclib-http-api-resources.md)。 |
| 本地 `high` | `high` 本地运行是正式支持能力,不是实验能力;当前代码基本 ready。 |
-| mineru.net tier | `mineru.net/api` 在相当长时间内只提供最高等级的 `high` 解析。 |
-| api-server tier | `mineru-kit api-server --tier` 可重复;未传时当前暴露 `flash`、`medium`、`high`、`extra_high`。 |
+| mineru.net tier | `mineru.net/api` 在相当长时间内默认提供 `high` 解析;`high` 是绝大多数场景足够好的高质量档位,但不是最高档。 |
+| api-server tier | `mineru-kit api-server --tier` 可重复;未传时当前暴露 `flash`、`medium`、`high`、`xhigh`。 |
| managed 生命周期 | managed 模式下,模型下载、预热、重试和退避由 `mineru-kit api-server` 负责。 |
| 本地 api-server 安全 | 本地 api-server 默认监听 loopback;可通过 `--api-key` 设置固定 API Key,默认不设置。 |
| P0 主链路 | P0 包含完整 watch、rules、search,不再把它们标为可选主链路。 |
@@ -50,8 +50,8 @@
| `mineru-kit` 参数稳定性 | 暂不划分 `stable` / `experimental` 等稳定性等级,先保持简单。 |
| `mineru-kit parse` 输入 | 当前只支持文件和目录输入;不支持 stdin、路径列表、URL 输入和递归目录。 |
| `mineru-kit parse` 输出 | `--output` 必填;单文件可输出到文件路径或目录路径;多文件只能输出到目录路径;同名冲突直接报错并终止整个批次。 |
-| `mineru-kit parse` local/remote | local 支持 `tier/backend` 并校验兼容,二者都不传时默认 `high`;remote 支持 `--remote`/`--remote-url`/`--api-key`,允许传 `tier`,禁止传 `backend`。 |
-| parsing-rules 默认 tier | parsing-rules 允许不指定 tier;执行时必须解析为实体 tier,并只记录实际 tier;默认选择不能解析为 `flash`。 |
+| `mineru-kit parse` local/remote | local 支持 `tier/backend` 并校验兼容,PDF/image 二者都不传时默认 `high`,Office/text/HTML 按 ADR-0024 归一;remote 支持 `--remote`/`--remote-url`/`--api-key`,允许传 `tier`,禁止传 `backend`。 |
+| parsing-rules 默认 tier | parsing-rules 允许不指定 tier;PDF/image 按 `high` -> `xhigh` -> `medium` -> `flash` 选择,Office/text/HTML 归一为 `flash`;只记录实际 tier。 |
| Telemetry P0 | P0 必须实现 doclib server telemetry 状态、聚合、flush 和 CLI 管理入口;纯工具无 telemetry 能力。 |
| `mineru parse` 默认页码范围 | 分页文档默认解析和读取 `1~min(page_count,10)`;该默认由 doclib 读取/解析计划负责,CLI 参数层不硬编码默认 `--pages`。 |
| 渐进式阅读协议 | Server 返回结构化 `next_request`;CLI marker 只由 `next_request` 渲染,不作为协议源头,详见 [ADR-0013](decisions/0013-doc-content-progressive-reading.md)。 |
@@ -68,8 +68,8 @@
| doclib schema 稳定边界 | 稳定的是 doclib public models,不是 SQLite 表结构;稳定性分为 `core stable`、`operational stable` 和 `diagnostic / internal`,详见 [ADR-0020](decisions/0020-doclib-schema-stability-boundary.md)。 |
| `mineru-kit` 对外暴露 | `mineru-kit` 保留为专家工具入口;Agent 默认入口是 `mineru`,skill 不主动暴露 `mineru-kit`。 |
| Office/HTML unknown bbox | 公共 schema 允许 unknown bbox;不要求 Office/HTML 在 P0 估算真实 bbox,validator 应区分 unknown 与非法 bbox。 |
-| 本地 managed tier 硬件基线 | 本地 managed `medium` / `high` / `extra_high` 都要求至少 16GB 总内存;`medium` 不要求 GPU,纯 CPU 可用但可能较慢;`high` / `extra_high` 需要满足 NVIDIA / Apple Silicon / MinerU 支持的 AI 加速器条件。详见 [解析 Tier](tiers.md#5-medium)。 |
-| watch tier 升级 | P0 不做基于启发式的自动提示或自动排队升级。watch 默认使用 `flash`;后台自动升级只由用户显式配置的 parsing-rules 触发;用户或 Agent 主动读取时再按默认选择策略解析到可用的非 `flash` 质量 tier。 |
+| 本地 managed tier 硬件基线 | 本地 managed tier 的硬件边界以 [解析 Tier](tiers.md) 为准。 |
+| watch tier 升级 | P0 不做基于启发式的自动提示或自动排队升级。watch 默认使用 `flash`;后台自动升级只由用户显式配置的 parsing-rules 触发;用户或 Agent 主动读取 PDF/image 时再按默认选择策略解析到可用的非 `flash` 质量 tier。 |
| Middle JSON `schema_version` | 采用 `pages` 的 Middle JSON 顶层结构必须写 `schema_version`;当前运行时不读取 `pdf_info`;历史 `pdf_info` 只作为离线 migration 或重新生成对象。当前暂不增加 `_meta`;`ParseResult.to_dict()` 可能保留顶层 `_backend` 临时 metadata;代码常量定义为 `mineru.parser.MIDDLE_JSON_SCHEMA_VERSION`。 |
## 3. Blocker
diff --git a/docs/next/roadmap.md b/docs/next/roadmap.md
index 22e576f0..e57f1674 100644
--- a/docs/next/roadmap.md
+++ b/docs/next/roadmap.md
@@ -53,7 +53,7 @@ Agent 使用场景是下一阶段的设计原点。CLI、SDK、MCP 和输出格
### 2.4 SaaS 只做高质量后端
-SaaS 不承担 MinerU 的全部产品体验。它的定位是最高质量、最快速度的远程解析能力,通过统一 API 为 CLI、SDK、MCP 和开发者服务。
+SaaS 不承担 MinerU 的全部产品体验。它的定位是高质量、可扩展的远程解析能力,通过统一 API 为 CLI、SDK、MCP 和开发者服务。
### 2.5 数据驱动但不被指标绑架
@@ -137,7 +137,7 @@ Agent 使用 MinerU 有两条通道:
| 搜索 | P0 | 文件名与内容检索,属于 watch、rules、search 主链路 |
| 桌面端 | P1 | CLI 的 GUI 壳 |
-解析能力通过 `flash`、`medium`、`high`、`extra_high` 暴露;用户未指定 tier 时使用默认选择策略。tier 的用户语义、硬件边界和质量策略见 [解析 Tier](tiers.md)。
+解析能力通过 `flash`、`medium`、`high`、`xhigh` 暴露;用户未指定 tier 时使用默认选择策略。tier 的用户语义、硬件边界和质量策略见 [解析 Tier](tiers.md)。
命令分工:
diff --git a/docs/next/sdk/api-parser.md b/docs/next/sdk/api-parser.md
index 818252a5..ab1f0d5c 100644
--- a/docs/next/sdk/api-parser.md
+++ b/docs/next/sdk/api-parser.md
@@ -59,7 +59,7 @@ class MinerUApiParser(DocumentParser):
|------|------|
| `api_url` | v1 API base URL,如 `https://mineru.net/api` 或 `http://127.0.0.1:16580`。省略时读取 `MINERU_API_URL`,再退回默认官方 API。 |
| `api_key` | Bearer token。省略时读取 `MINERU_API_KEY`;Local Parse Server 未启用鉴权时可为空。 |
-| `tier` | `flash`、`medium`、`high`、`extra_high` 或 `None`。`None` 表示 SDK 在 HTTP 请求中省略 `tier`,让 v1 API 使用默认选择策略。 |
+| `tier` | `flash`、`medium`、`high`、`xhigh` 或 `None`。`None` 表示 SDK 在 HTTP 请求中省略 `tier`,让 v1 API 使用默认选择策略;非 PDF/image 文件按 API Server 批量规则归一,见 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。 |
| `include_images` | 是否从 zip 产物读取图片 sidecar,并挂载到 `ParseResult` 图片缓存。 |
| `include_model_output` | 是否请求并保留模型原始输出;开启时通过 zip 产物读取。 |
@@ -111,7 +111,7 @@ Local Parse Server 必须通过 `--allow-local-source` 开启,并在 `features
| `flash` | `flash` |
| `medium` | `medium` |
| `high` | `high` |
-| `extra_high` | `extra_high` |
+| `xhigh` | `xhigh` |
它不接受也不保存 backend 参数。backend 是本地 parser 层的高级实现概念,不应出现在 API-backed parser 的公开构造参数、实例属性或请求 payload 中。
diff --git a/docs/next/sdk/doclib-client.md b/docs/next/sdk/doclib-client.md
index 594eb6f7..58ccad85 100644
--- a/docs/next/sdk/doclib-client.md
+++ b/docs/next/sdk/doclib-client.md
@@ -75,7 +75,7 @@ def ensure_parse(self, request: ParseRequest) -> ParseResponse: ...
| 参数 | 说明 |
|------|------|
| `path` | 本地文件路径。 |
-| `tier` | `flash`、`medium`、`high`、`extra_high` 或 `None`。`None` 表示使用 doclib 规则和默认策略。 |
+| `tier` | `flash`、`medium`、`high`、`xhigh` 或 `None`。`None` 表示使用 doclib 规则和默认策略;非 PDF/image 单文件未指定 tier 时归一为 `flash`,显式质量 tier 报错。 |
| `page_range` | 页码范围。 |
| `force` | 跳过已有 done 缓存并重新解析;可复用 active parse,只为未覆盖页创建新 parse。 |
| `remote` | 是否允许调用远端 parse-server。默认 `False`。远端 URL 来自 doclib config;API Key 优先来自 doclib config,未配置时使用环境变量。 |
diff --git a/docs/next/sdk/migration.md b/docs/next/sdk/migration.md
index 36391c87..d62fc0f6 100644
--- a/docs/next/sdk/migration.md
+++ b/docs/next/sdk/migration.md
@@ -62,13 +62,13 @@ SDK 迁移的目标不是重写现有 parser,而是稳定已经成形的边界
1. 在 `parse()` 增加 `tier` 参数。
2. 保留 `backend` 作为高级兼容参数。
3. 明确 `backend` 覆盖 `tier`。
-4. 增加 `tier=None` 默认选择逻辑,且永不回退到 `flash`。
+4. 增加 `tier=None` 默认选择逻辑:PDF/image 永不回退到 `flash`,Office/HTML 这类仅支持 flash tier 的输入按实际能力归一为 `flash`。
验收:
- `parse(path, tier="medium")` 可用。
- `parse(path, tier="high")` 可用或给出明确 engine error。
-- `parse(path)` 或 `parse(path, tier=None)` 不会静默使用 flash。
+- PDF/image 的 `parse(path)` 或 `parse(path, tier=None)` 不会静默使用 flash;Office/HTML 这类仅支持 flash tier 的输入未指定 tier 时返回实际 `flash` 语义。
- `parse(path, tier="flash")` 只有显式请求时使用 flash。
## Phase 4: 错误模型统一
diff --git a/docs/next/sdk/parser.md b/docs/next/sdk/parser.md
index 57660a6c..41d02ce0 100644
--- a/docs/next/sdk/parser.md
+++ b/docs/next/sdk/parser.md
@@ -120,10 +120,10 @@ class DocumentParser:
|------|--------------|------|
| `flash` | `flash` | 快速 CPU-only。 |
| `medium` | `hybrid-engine` + `effort="low"` | 消费级硬件可用的本地小模型组合。 |
-| `high` | hybrid 默认高质量 backend | 最高质量。 |
-| `extra_high` | hybrid backend + 更高 effort | 当前代码支持的专家档位,需显式请求。 |
+| `high` | hybrid 默认高质量 backend | 绝大多数场景足够好的高质量档位。 |
+| `xhigh` | hybrid backend + 更高 effort | 最高质量档位,用更多算力和时间换取小幅质量提升。 |
-`tier=None` 表示使用默认选择策略,选择可用的最高非 `flash` tier。当前默认选择不自动升级到 `extra_high`;只有用户显式请求 `tier="flash"` / `tier="extra_high"` 或对应 backend 时,才返回这些非默认档位结果。
+`tier=None` 表示使用默认选择策略。PDF/image 直接本地解析且没有能力列表时默认 `high`,有能力发现上下文时按 `high` -> `xhigh` -> `medium` 选择;Office/HTML 这类仅支持 flash tier 的输入未指定 tier 时归一为 `flash`,显式质量 tier 应报错。完整 tier 语义见 [解析 Tier](../tiers.md) 和 [ADR-0024](../decisions/0024-file-type-tier-normalization.md)。
## 重依赖边界
diff --git a/docs/next/sdk/tiers-errors.md b/docs/next/sdk/tiers-errors.md
index 12787185..c877152b 100644
--- a/docs/next/sdk/tiers-errors.md
+++ b/docs/next/sdk/tiers-errors.md
@@ -7,30 +7,13 @@
## Tier 语义
-SDK 层必须使用与产品一致的 tier 语义:
-
-| Tier | SDK 含义 |
-|------|----------|
-| `flash` | 用户显式请求快速 CPU-only 解析。不能作为默认选择的回退。 |
-| `medium` | 本地或自部署 parse-server 可用的标准质量解析能力。 |
-| `high` | 当前最高质量解析能力;`mineru.net/api` 长期只提供该 tier。 |
-| `extra_high` | 当前代码支持的更高质量实验/专家档位,映射到 hybrid backend;产品默认选择策略暂不依赖它。 |
-
-完整产品语义见 [解析 Tier](../tiers.md)。
+SDK 层必须使用与产品一致的 tier 语义。完整产品语义见 [解析 Tier](../tiers.md)。
## 默认选择规则
-SDK 中未指定 tier,或 Python 调用传 `tier=None` 时,必须遵循:
-
-| 可用能力 | 默认选择结果 |
-|----------|-------------|
-| 只有 `medium` | `medium` |
-| 只有 `high` | `high` |
-| 同时发现 `medium` 和 `high` | `high` |
-| 发现 `extra_high` | 只有调用方显式请求时使用,默认选择策略暂不自动升级到它 |
-| 都没有 | 报错 |
+SDK 中未指定 tier,或 Python 调用传 `tier=None` 时,必须遵循 [解析 Tier](../tiers.md) 和 [ADR-0024](../decisions/0024-file-type-tier-normalization.md) 中的默认选择策略。
-默认选择不能变成 `flash`。如果用户想使用 `flash`,必须显式传入 `tier="flash"` 或 `backend="flash"`。
+对 PDF/image,默认选择不能变成 `flash`。Office/text/HTML 没有质量 tier;单文件解析未指定 tier 时归一为 `flash`,显式传入 `medium`、`high` 或 `xhigh` 应报错。
## Tool SDK 的 tier 处理
@@ -48,9 +31,9 @@ SDK 中未指定 tier,或 Python 调用传 `tier=None` 时,必须遵循:
| `flash` | `flash` |
| `medium` | `hybrid-engine` + `effort="low"` |
| `high` | hybrid 默认高质量 backend |
-| `extra_high` | hybrid backend + 更高 effort |
+| `xhigh` | hybrid backend + 更高 effort |
-`tier=None` 使用默认选择策略,结果为 `high` 或 `medium`;`extra_high` 需要显式请求。
+`tier=None` 使用默认选择策略。PDF/image 直接本地解析且没有能力列表时默认 `high`;有能力发现上下文时按 `high` -> `xhigh` -> `medium` 选择。Office/text/HTML 单文件解析未指定 tier 时归一为 `flash`。结果记录实际 tier,不能为仅支持 flash tier 的输入记录伪质量 tier。
## Doclib SDK 的 tier 处理
@@ -63,8 +46,8 @@ SDK 中未指定 tier,或 Python 调用传 `tier=None` 时,必须遵循:
doclib 的质量优先规则:
-- 用户读取文档时默认最低接受 `medium`。
-- 找不到 `medium` / `high` 且不允许 remote 时,应报错。
+- 用户读取文档时默认使用非 `flash` 质量 tier。
+- 找不到可用的非 `flash` 质量 tier 且不允许 remote 时,应报错。
- 不应擅自返回 `flash` 结果作为读取结果。
## 隐私策略
diff --git a/docs/next/telemetry-minimum.md b/docs/next/telemetry-minimum.md
index 525bdc3a..77828bd6 100644
--- a/docs/next/telemetry-minimum.md
+++ b/docs/next/telemetry-minimum.md
@@ -690,7 +690,7 @@ status = <metric-specific low-cardinality status>
按需补充:
```text
-tier = default | flash | medium | high | medium(default) | high(default) | unknown
+tier = default | flash | medium | high | xhigh | medium(default) | high(default) | xhigh(default) | unknown
server = local(flash) | local(managed) | local(self-hosted) | remote(official) | remote(custom) | none | unknown
error_code = <telemetry_error_code>
bucket = <metric bucket value>
@@ -747,8 +747,8 @@ scan_failed
`tier` 归一化规则:
-- `flash` / `medium` / `high` 表示用户显式指定,或后台任务的实体 tier。
-- `medium(default)` / `high(default)` 只用于入口请求层指标,表示请求未显式指定 tier,但默认选择策略最终解析到了 `medium` 或 `high`。
+- `flash` / `medium` / `high` / `xhigh` 表示用户显式指定,或后台任务的实体 tier。
+- `medium(default)` / `high(default)` / `xhigh(default)` 只用于入口请求层指标,表示请求未显式指定 tier,但默认选择策略最终解析到了 `medium`、`high` 或 `xhigh`。
- `default` 只用于入口请求在默认 tier 解析完成前就失败,且调用方未显式指定 tier 的场景。
- `unknown` 表示无法安全判断。
@@ -1142,7 +1142,7 @@ parse.invalidate.count:
- `parse.finished.count {status=failed}` 的 `tier` 规则:
- 调用方显式指定 tier 且请求失败时,使用该显式 tier。
- 调用方未显式指定 tier,且在默认 tier 解析完成前就失败时,使用 `default`。
- - 调用方未显式指定 tier,但默认选择策略已明确解析到了实体 tier 后才失败时,使用 `medium(default)` 或 `high(default)`。
+ - 调用方未显式指定 tier,但默认选择策略已明确解析到了实体 tier 后才失败时,使用 `medium(default)`、`high(default)` 或 `xhigh(default)`。
采集点位:
diff --git a/docs/next/telemetry.md b/docs/next/telemetry.md
index eb960da8..b5c08871 100644
--- a/docs/next/telemetry.md
+++ b/docs/next/telemetry.md
@@ -278,7 +278,7 @@ Dimension 只允许低基数字段:
|------|-------------|
| `source` | `http_api` / `sdk` / `cli` / `mcp` / `web` / `app` / `watch` / `background` / `unknown` |
| `caller` | `agent` / `user` / `http_client` / `sdk` / `web` / `app` / `system` / `unknown` |
-| `tier` | `default` / `flash` / `medium` / `high` / `medium(default)` / `high(default)` / `unknown` |
+| `tier` | `default` / `flash` / `medium` / `high` / `xhigh` / `medium(default)` / `high(default)` / `xhigh(default)` / `unknown` |
| `status` | `succeeded` / `failed` / `partial` / `canceled` |
| `input_type` | `pdf` / `docx` / `pptx` / `xlsx` / `html` / `other` / `unknown` |
| `output_format` | `middle_json` / `markdown` / `structured_content` / `other` |
@@ -324,8 +324,8 @@ CLI 的 `caller` 可以通过父进程识别。若父进程是 Claude Code、Cod
`tier` 同时表达请求档位和实际解析档位:
- 用户未指定 tier,且尚未解析到实体 tier 时,使用 `default`。
-- 用户显式指定实体 tier,或任务已经完成且没有必要保留默认来源时,使用 `flash`、`medium` 或 `high`。
-- 用户未指定 tier,且已经解析到实体 tier,同时仍需要保留来源信息时,使用 `medium(default)` 或 `high(default)`。
+- 用户显式指定实体 tier,或任务已经完成且没有必要保留默认来源时,使用 `flash`、`medium`、`high` 或 `xhigh`。
+- 用户未指定 tier,且已经解析到实体 tier,同时仍需要保留来源信息时,使用 `medium(default)`、`high(default)` 或 `xhigh(default)`。
- 默认选择不会解析为 `flash`,因此不定义 `flash(default)`。
- parse-server 相关 metric 也使用同一个 `tier` 维度,不再单独使用 `parse_server_tier`。
@@ -457,7 +457,7 @@ Parse-server 相关 metric 必须带以下维度,便于区分用户是否使
```text
server: local(managed) | local(self-hosted) | remote(official) | remote(custom) | unknown
-tier: medium | high | medium(default) | high(default) | unknown
+tier: medium | high | xhigh | medium(default) | high(default) | xhigh(default) | unknown
status: succeeded | failed | partial | canceled
```
@@ -476,7 +476,7 @@ Parse-server 配置口径:
- 数量: `parse_server.requested.count`、`parse_server.completed.count`、`parse_server.files.count`、`parse_server.processed_page_count`,且 `server=local(managed)` 或 `local(self-hosted)`。
- 性能: `parse_server.duration.bucket.count`,且 `server=local(managed)` 或 `local(self-hosted)`。
- 模式: 由 `server=local(managed)` 或 `local(self-hosted)` 区分。
-- tier: `tier=medium`、`high`、`medium(default)` 或 `high(default)`。
+- tier: `tier=medium`、`high`、`xhigh`、`medium(default)`、`high(default)` 或 `xhigh(default)`。
Telemetry 自身:
@@ -494,7 +494,7 @@ P0 不一定实现所有候选 metric。裁剪时必须保留能回答以下问
1. 使用规模: WAI、DAU、parse 次数、文件数、页数。
2. Agent 入口: `caller=agent` 与 `caller=user` 的使用差异。
3. 调用通道: HTTP API、SDK、CLI、MCP、Web、App、watch 和后台任务的来源分布。
-4. 解析服务: 是否使用 parse-server,使用 `local(managed)`、`local(self-hosted)`、`remote(official)` 还是 `remote(custom)`,medium 还是 high。
+4. 解析服务: 是否使用 parse-server,使用 `local(managed)`、`local(self-hosted)`、`remote(official)` 还是 `remote(custom)`,以及具体解析 tier。
5. 主链路质量: parse、ingest、render、search index 的成功和失败。
6. 关键性能: parse 耗时、parse-server 耗时、queue wait、render 耗时的 bucket。
7. 隐私边界: remote 是否被请求、允许、拒绝,以及 remote 失败后是否 fallback 到 local。
diff --git a/docs/next/tiers.md b/docs/next/tiers.md
index 61566e58..0f25e0e6 100644
--- a/docs/next/tiers.md
+++ b/docs/next/tiers.md
@@ -2,7 +2,7 @@
状态: Draft
读者: CLI/API/SDK 使用者、Agent skill 作者、核心开发者
-范围: `flash`、`medium`、`high`、`extra_high` 解析 tier 的产品语义、默认选择策略、适用场景、质量边界和执行路径
+范围: `flash`、`medium`、`high`、`xhigh` 解析 tier 的产品语义、默认选择策略、适用场景、质量边界和执行路径
非目标: 固定具体模型名称或 backend 实现;定义 middle_json 字段级 schema
底稿: 用户讨论;旧路线图、旧 CLI 与旧设计底稿迁移内容
@@ -10,36 +10,38 @@
Tier 是用户可理解的解析档位,不是 backend 名称。它表达的是质量、速度、资源消耗和隐私路径之间的产品承诺。
-MinerU 当前定义四个公开 tier:
+MinerU 当前定义四个公开 tier。文档中使用面向用户的显示名;代码、CLI 参数、API 字段和 locator 中使用对应字面量。
-| Tier | 定位 | 一句话说明 |
-|------|------|------------|
-| `flash` | 快速发现与索引 | 纯 CPU、最快、质量最低,用于大量文件的低成本预处理 |
-| `medium` | 本地主力解析 | 基于模型,面向普通消费级电脑,质量和资源消耗折中 |
-| `high` | 最高质量解析 | MinerU 线上 API 的最高质量层级,也可在高端本地硬件上运行 |
-| `extra_high` | 专家最高档 | 本地或自部署高质量档位,面向更高成本和更强硬件 |
+| 显示名 | 字面量 | 定位 | 一句话说明 |
+|--------|--------|------|------------|
+| Flash | `flash` | 快速发现与索引 | 随 MinerU 默认安装,最快、质量最低,用于大量文件的低成本预处理 |
+| Medium | `medium` | 本地主力解析 | 需要额外依赖,CPU 可运行,GPU 可加速,质量和资源消耗折中 |
+| High | `high` | 高质量解析 | 需要 VLM 相关依赖和支持的本地加速器,也可由 MinerU 线上 API 提供 |
+| Extra High | `xhigh` | 专家最高档 | 与 High 硬件要求相同,但消耗更多算力和时间,面向更高质量要求 |
-`auto` 不再作为公开 tier 值。CLI 中不传 `--tier`、HTTP API 中省略 `tier` 或传 JSON `null`、Python SDK 中传 `None`,都表示使用默认选择策略。
+`auto` 不再作为公开 tier 值。CLI 中不传 `--tier`、HTTP API 中省略 `tier` 或传 JSON `null`、Python SDK 中传 `None`,都表示使用当前入口的默认选择策略。
核心原则:
-- `flash` 用于发现、预览和建立搜索索引,不是默认阅读质量。
-- 当 Agent 或用户决定读取某个文档时,如果没有指定 tier,默认选择当前可发现能力中最高的非 `flash` tier,最低可接受解析结果是 `medium`。
-- 默认选择策略在任何语境下都不会等价于 `flash`。
-- `high` 是当前质量最好的 tier,也是 `mineru.net/api` 对外提供的解析层级。
-- 本地运行 `high` 是正式支持能力,不是实验能力;它依赖高端 GPU / 加速器硬件和对应模型环境。
+- `flash` 用于发现、预览和建立搜索索引,不是 PDF/image 默认阅读质量。
+- 当 Agent 或用户决定读取 PDF/image 文档时,如果没有指定 tier,默认选择不能解析为 `flash`;有能力发现上下文时优先使用 `high`。
+- 默认选择策略在 PDF/image 质量解析语境下不会等价于 `flash`;Office/text/HTML 这类仅支持 flash tier 的输入按 [ADR-0024](decisions/0024-file-type-tier-normalization.md) 归一为 `flash` 语义。
+- `high` 是高质量 tier,也是 `mineru.net/api` 对外提供的解析层级。
+- `xhigh` 是当前公开 tier 中质量和成本最高的档位。
+- 本地运行 `high` 和 `xhigh` 是正式支持能力,不是实验能力;它们依赖 VLM 相关依赖、支持的本地加速器和足够的显存或统一内存。
- `mineru.net/api` 在相当长时间内只提供 `high`,不暴露低成本远端 `medium`。
- 不使用 `--remote` 时,MinerU 不会把文档发送到 `mineru.net/api`。
## 2. 实体 tier 区别
-| 维度 | `flash` | `medium` | `high` | `extra_high` |
+| 维度 | Flash (`flash`) | Medium (`medium`) | High (`high`) | Extra High (`xhigh`) |
|------|---------|------------|--------|--------------|
| 主要目标 | 快速扫大量文件,建立基础索引 | 在普通本地硬件上提供可接受的高质量解析 | 提供高质量解析 | 提供最高成本/最高质量档位 |
-| 底层原理 | 纯 CPU 实现 | 基于模型 | 基于更强模型 | 基于更高 effort 的模型路径 |
+| 安装依赖 | 随 MinerU 默认安装 | 需要额外 runtime 依赖 | 需要更多 runtime 依赖和 VLM 依赖 | 同 `high` |
+| 底层原理 | 纯 CPU 实现 | 基于模型 | 基于 VLM 的高质量模型路径 | 基于 VLM 的更高成本模型路径 |
| 质量 | 低 | 中 | 高 | 更高 |
-| 速度 | 最快 | 中等 | 较慢,取决于硬件和远端服务 | 最慢,取决于硬件和远端服务 |
-| 本地硬件要求 | 无 GPU / 加速器也可用 | 需要至少 16GB 总内存;GPU 可选,纯 CPU 可用但可能较慢 | 需要至少 16GB 总内存,并具备符合条件的本地加速器,或使用远端 | 同 `high`,通常需要更强硬件或更长等待 |
+| 速度 | 最快 | 中等 | 较慢,取决于硬件和远端服务 | 最慢,通常比 `high` 消耗更多算力和时间 |
+| 本地硬件要求 | 无特殊硬件要求 | 需要至少 16GB 总内存;CPU 可运行,GPU 可加速 | 需要至少 16GB 总内存,并具备支持的本地加速器和足够的显存或统一内存 | 同 `high` |
| 是否适合 watch 自动处理 | 是 | 一般不默认使用 | 否 | 否 |
| 是否适合用户主动阅读 | 仅在用户明确选择时 | 是,默认最低阅读质量 | 是,质量优先场景 | 是,专家质量优先场景 |
| 典型场景 | 文件发现、快速预览、搜索索引 | 本地隐私解析、普通文档阅读 | 复杂版面、学术论文、高价值文档 | 极高质量要求、专家批处理或自部署 |
@@ -48,44 +50,70 @@ MinerU 当前定义四个公开 tier:
当用户没有指定 tier,或在 HTTP API 中显式传入 JSON `null` 时,MinerU 使用默认选择策略。Python SDK 中的等价表达是 `tier=None`。
-MinerU 有 local parse-server,也有 remote parse-server。无论 local 还是 remote,parse-server 都应支持通过 API 发现当前 server 提供了哪些解析 tier。当前代码支持发现 `medium`、`high`、`extra_high` 等质量 tier。
+默认选择策略分两类场景。本节描述 PDF/image 质量解析的默认选择;Office/text/HTML 这类仅支持 flash tier 的输入见 [ADR-0024](decisions/0024-file-type-tier-normalization.md)。
-默认选择策略的含义是:在当前目标 parse-server 可发现的能力中,选择最高的非 `flash` tier。
+### 3.1 无能力列表的场景
+
+启动服务或直接解析时,如果当前入口没有可用 tier 列表可参考,默认 tier 是 `high`。
+
+典型场景:
+
+- `mineru-kit api-server` 未传 `--tier`。
+- `mineru-kit parse` local 模式未传 `--tier` / `--backend`。
+- Tool SDK 直接本地解析且无法做能力发现。
+
+这类场景的默认值不是 `xhigh`。`xhigh` 消耗更多算力和时间,需要用户显式指定,或由具备能力发现上下文的调用方在没有 `high` 时选择。
+
+### 3.2 有能力发现上下文的场景
+
+当调用某个 parse-server,或有等价的可用 tier 上下文时,默认选择策略基于当前可发现能力选择实体 tier。MinerU 有 local parse-server,也有 remote parse-server。无论 local 还是 remote,parse-server 都应支持通过 API 发现当前 server 提供了哪些解析 tier。当前代码支持发现 `medium`、`high`、`xhigh` 等质量 tier。
+
+这类场景的默认选择顺序是:
+
+```text
+high -> xhigh -> medium -> 报错
+```
+
+也就是说,`high` 是默认优先档位;`xhigh` 虽然质量最高,但不会在 `high` 同时可用时自动成为默认。只有没有 `high`、但有 `xhigh` 时,默认才选择 `xhigh`。
| 可发现能力 | 默认解析结果 |
|------------|-----------------|
| 只支持 `medium` | `medium` |
| 只支持 `high` | `high` |
-| 只支持 `extra_high` | `extra_high` |
+| 只支持 `xhigh` | `xhigh` |
| 同时支持 `medium` 和 `high` | `high` |
-| 同时支持 `medium`、`high` 和 `extra_high` | `extra_high` |
+| 同时支持 `high` 和 `xhigh` | `high` |
+| 同时支持 `medium` 和 `xhigh`,不支持 `high` | `xhigh` |
+| 同时支持 `medium`、`high` 和 `xhigh` | `high` |
| 只支持 `flash` 或没有可用能力 | 报错 |
-默认选择策略永远不会解析为 `flash`。如果系统找不到 `medium`、`high` 或 `extra_high`,应返回 `quality_tier_unavailable` 或等价结构化错误,而不是擅自用 `flash` 内容替代。错误码见 [错误码体系](errors.md)。
+PDF/image 默认选择策略不会解析为 `flash`。如果系统找不到 `medium`、`high` 或 `xhigh`,应返回 `quality_tier_unavailable` 或等价结构化错误,而不是擅自用 `flash` 内容替代。错误码见 [错误码体系](errors.md)。
+
+默认选择策略是请求时的选择逻辑,不是长期缓存语义。任务入队、缓存命中、产物目录和结果 metadata 应使用实际选择的实体 tier(例如 `medium`、`high` 或 `xhigh`),避免默认选择与实体 tier 产生重复缓存。
-默认选择策略是请求时的选择逻辑,不是长期缓存语义。任务入队、缓存命中、产物目录和结果 metadata 应使用实际选择的实体 tier(例如 `medium`、`high` 或 `extra_high`),避免默认选择与实体 tier 产生重复缓存。
+读取已有缓存时不使用这套解析默认顺序。`mineru read doc:{short_id}` 不带 `/tier:{tier}` 时不会创建新解析,应在已缓存的非 `flash` 结果中选择最高质量 tier,顺序为 `xhigh` -> `high` -> `medium`;没有非 `flash` 缓存时返回错误。
## 4. Flash
-`flash` 是纯 CPU tier,面向没有 GPU 或加速器硬件的用户。它的质量通常最低,但必须足够快。
+`flash` 随 MinerU 默认安装,面向没有额外 runtime 依赖、GPU 或加速器硬件的用户。它的质量通常最低,但必须足够快。
`flash` 的核心用途是支撑大量文件的自动发现和低成本预处理。MinerU 的 watch 机制会发现很多文件;在系统刚看到这些文件时,并不知道每个文件的价值,也不适合立即使用高算力方案处理。因此 watch 默认使用 `flash` 快速提取最基础内容,用于建立搜索索引和后续发现。
-P0 不做基于启发式的自动提示或自动排队升级。watch 使用 `flash` 后,如果需要在后台自动解析到 `medium`、`high` 或 `extra_high`,必须来自用户显式配置的 parsing-rules;系统不根据文件名、内容特征、搜索命中或“高价值文档”判断自行升级。
+P0 不做基于启发式的自动提示或自动排队升级。watch 使用 `flash` 后,如果需要在后台自动解析到 `medium`、`high` 或 `xhigh`,必须来自用户显式配置的 parsing-rules;系统不根据文件名、内容特征、搜索命中或“高价值文档”判断自行升级。
-`flash` 不应被当成默认阅读质量。当 Agent 或用户决定真正读取某个文档时,需求已经从“发现它”变成“尽可能准确地理解它”,此时未指定 tier 应使用默认选择策略,并至少解析到 `medium`。
+`flash` 不应被当成 PDF/image 默认阅读质量。当 Agent 或用户决定真正读取 PDF/image 文档时,需求已经从“发现它”变成“尽可能准确地理解它”,此时未指定 tier 应使用默认选择策略,并解析到可用的非 `flash` 质量 tier。Office/text/HTML 这类仅支持 flash tier 的输入没有质量 tier 分层,按 `flash` 语义处理。
只有在用户明确指定 `flash` 时,才返回 `flash` 的解析内容作为最终阅读结果。
## 5. Medium
-`medium` 是本地主力解析 tier,当前使用 `hybrid-engine` 的 `medium` effort。它是一系列本地模型串联的解析方案。
+`medium` 是本地主力解析 tier,当前使用 `hybrid-engine` 的 `medium` effort。它需要额外 runtime 依赖,是一系列本地模型串联的解析方案。
-`medium` 可以运行在纯 CPU、GPU、Apple Silicon 或 MinerU 支持的 AI 加速器环境上。GPU 和显存不是启用 `medium` 的硬门槛,但会影响速度、吞吐和稳定性。因此 `medium` 是一个算力消耗较低、质量中等、仍然基于模型的解析方案。
+`medium` 可以在 CPU 上运行,也可以由 GPU 加速。GPU 和显存不是启用 `medium` 的硬门槛,但会影响速度、吞吐和稳定性。因此 `medium` 是一个算力消耗较低、质量中等、仍然基于模型的解析方案。
`medium` 的核心价值是本地隐私解析:当用户不接受把文档发送到远端解析,同时硬件又不是特别高端时,`medium` 应成为本地可用的最佳默认方案。
-本地 managed `medium`、`high` 和 `extra_high` parse server 都要求至少 16GB 总内存。低于该基线时,不建议启用本地 managed 质量 tier;应考虑远端解析,或在用户明确接受低质量时显式使用 `flash`。
+本地 managed `medium`、`high` 和 `xhigh` parse server 都要求至少 16GB 总内存。低于该基线时,不建议启用本地 managed 质量 tier;应考虑远端解析,或在用户明确接受低质量时显式使用 `flash`。
## 6. High
@@ -93,19 +121,19 @@ P0 不做基于启发式的自动提示或自动排队升级。watch 使用 `fla
`high` 代表高质量解析能力。它既可以由 `mineru.net/api` 提供,也可以由本地高端硬件运行。
-本地 managed `high` 需要至少 16GB 总内存,并满足以下本地加速器条件之一:
+本地 managed `high` 需要安装 VLM 相关 runtime 依赖,要求至少 16GB 总内存,并满足以下本地加速器条件之一:
- Volta 或更新架构的 NVIDIA GPU,且可供 MinerU 使用的 VRAM 至少 8GB。
- Apple Silicon,且统一内存至少 16GB。
- MinerU 支持的特殊 AI 加速器,例如 `npu`、`gcu`、`musa`、`mlu` 或 `sdaa`。
-`high` 适合复杂版面、学术论文、高价值文档和用户明确追求最高质量的场景。它的代价是更高的算力、显存、等待时间或远端调用成本。
+`high` 适合复杂版面、学术论文、高价值文档和多数高质量解析场景。它的代价是更高的算力、显存、等待时间或远端调用成本。
## 7. Extra High
-`extra_high` 是当前公开 tier 中最高的本地/自部署档位,映射到 `hybrid-engine` 的 `extra_high` effort。
+`xhigh` 是当前公开 tier 中最高的本地/自部署档位。
-它适合极高质量要求、专家批处理或自部署服务。相对 `high`,它可能带来更长等待时间、更高显存/内存压力和更高运行成本。用户主动指定 `--tier extra_high`,或目标 parse-server 能力发现只暴露/优先暴露 `extra_high` 时,系统可以使用该 tier。
+它适合极高质量要求、专家批处理或自部署服务。`xhigh` 与 `high` 的本地硬件要求相同,也需要 VLM 相关 runtime 依赖;区别是 `xhigh` 会消耗更多算力,通常需要更长解析时间,并可能带来更高运行成本。用户主动指定 `--tier xhigh`,或目标 parse-server 能力发现只暴露/优先暴露 `xhigh` 时,系统可以使用该 tier。
## 8. 隐私优先与质量优先
@@ -119,9 +147,9 @@ MinerU 的 tier 策略同时遵守隐私优先和质量优先。
### 8.2 质量优先
-用户或 Agent 主动读取文档时,默认应解析到可用的非 `flash` 质量 tier。
+用户或 Agent 主动读取 PDF/image 文档时,默认应解析到可用的非 `flash` 质量 tier。
-如果 `medium`、`high` 和 `extra_high` 都不可用,且远端也不可用,系统应报错,而不是擅自把 `flash` 结果作为最终阅读结果返回。
+如果 `medium`、`high` 和 `xhigh` 都不可用,且远端也不可用,系统应报错,而不是擅自把 `flash` 结果作为最终阅读结果返回。
`flash` 结果可以用于索引、发现、预览和提示用户选择更高 tier;只有用户明确选择 `flash` 时,才可作为最终解析返回。
@@ -130,12 +158,15 @@ MinerU 的 tier 策略同时遵守隐私优先和质量优先。
| 请求 | 默认执行路径 |
|------|--------------|
| watch 自动发现文件 | 本地 `flash` |
-| watch 命中 parsing-rule | 按 rule 中的 tier、页码范围和 remote 配置执行;必须经过能力检查和隐私检查 |
-| 用户主动 parse,未指定 tier;HTTP API 传 JSON `null`;Python SDK 传 `None` | 解析为当前可发现的最高非 `flash` tier |
+| `mineru-kit api-server` 未传 `--tier` | 以 `high` 作为服务默认 tier |
+| `mineru-kit parse` local 模式未传 `--tier` / `--backend` | PDF/image 直接按 `high` 解析;Office/text/HTML 按 `flash` 语义处理 |
+| watch 命中 parsing-rule 且 rule 指定 tier | PDF/image 按 rule 中的 tier、页码范围和 remote 配置执行;Office/text/HTML 忽略 rule tier 和 remote,按 `flash` |
+| watch 命中 parsing-rule 但 rule 未指定 tier | PDF/image 按 `high` -> `xhigh` -> `medium` -> `flash` 选择;Office/text/HTML 按 `flash` |
+| 用户主动 parse,未指定 tier;HTTP API 传 JSON `null`;Python SDK 传 `None` | PDF/image 有能力发现上下文时按 `high` -> `xhigh` -> `medium` 选择;Office/text/HTML 按 [ADR-0024](decisions/0024-file-type-tier-normalization.md) 归一为 `flash` |
| 用户主动指定 `--tier flash` | 本地 `flash` |
| 用户主动指定 `--tier medium` | 本地 medium;不可用时报错 |
| 用户主动指定 `--tier high` | 本地 high;显式 remote 时使用 `mineru.net/api` high |
-| 用户主动指定 `--tier extra_high` | 本地或自部署 extra_high;不可用时报错 |
+| 用户主动指定 `--tier xhigh` | 本地或自部署 Extra High;不可用时报错 |
| 用户显式 `--remote` | 允许上传到 `mineru.net/api`,使用远端 `high` |
执行路径需要与 [系统架构](architecture.md) 中的 ParseWorker 路由保持一致。
@@ -145,10 +176,11 @@ MinerU 的 tier 策略同时遵守隐私优先和质量优先。
CLI、API 和 SDK 暴露 tier 时,应遵守同一语义:
- 对用户显示 tier,不显示具体 backend 名称作为主要选择项。
-- 公开 tier 取值包括 `flash`、`medium`、`high`、`extra_high`。
-- CLI 不传 `--tier`、HTTP API 省略 `tier` 或传 JSON `null`、Python SDK 传 `None`,表示使用默认选择策略。
-- 默认选择策略必须通过 parse-server 能力发现解析为非 `flash` 质量 tier。
-- 默认阅读质量不能静默降级到 `flash`。
+- 公开 tier 取值包括 `flash`、`medium`、`high`、`xhigh`。
+- CLI 不传 `--tier`、HTTP API 省略 `tier` 或传 JSON `null`、Python SDK 传 `None`,表示使用当前入口按文件类型定义的默认选择策略。
+- 没有能力列表的启动服务或直接解析场景默认使用 `high`。
+- PDF/image 有能力发现上下文时,默认选择策略按 `high` -> `xhigh` -> `medium` 解析为非 `flash` 质量 tier。
+- PDF/image 默认阅读质量不能静默降级到 `flash`。
- 当更高 tier 不可用时,应返回结构化错误和修复建议。
- 当用户显式选择 `flash` 时,可以返回 `flash` 内容。
- `--remote` 或等价字段必须是显式选择。
diff --git a/docs/next/workflows.md b/docs/next/workflows.md
index 25128f99..34c7b483 100644
--- a/docs/next/workflows.md
+++ b/docs/next/workflows.md
@@ -12,7 +12,7 @@
它串联以下专题:
- 术语以 [术语表](glossary.md) 为准。
-- 默认选择 / `flash` / `medium` / `high` / `extra_high` 的语义以 [解析 Tier](tiers.md) 为准。
+- 默认选择 / `flash` / `medium` / `high` / `xhigh` 的语义以 [解析 Tier](tiers.md) 为准。
- doclib、worker、SQLite 和 parse-server 的内部结构以 [系统架构](architecture.md) 为准。
- CLI 行为以 [CLI 规格](cli.md) 为准。
- v1 API 行为以 [Unified API](api.md) 为准。
@@ -36,7 +36,7 @@
| Doclib SDK | 本地文档库 SDK | 连接 doclib server,使用 parse/search/watch/config 能力。 |
| Tool SDK | 工具 SDK | 进程内直接解析文件,返回 `ParseResult`。 |
| doclib server | 本地文档库服务 | 入库、缓存、搜索、watch、配置、任务调度。 |
-| parse-server | 解析服务 | 无状态解析服务,提供 v1 Unified API,执行 `medium` / `high` / `extra_high` 等质量 tier。 |
+| parse-server | 解析服务 | 无状态解析服务,提供 v1 Unified API,执行 `medium` / `high` / `xhigh` 等质量 tier。 |
| Local Parse Server | 本地解析服务 | 用户可信环境内的 parse-server。 |
| Remote Parse Server | 远端解析服务 | `mineru.net/api` 或显式配置的远端兼容服务。 |
| Backend | 解析后端 | 实际解析实现,例如 `flash`、`pipeline`、`vlm`、`hybrid`。 |
@@ -47,8 +47,8 @@
这些规则在所有流程中都成立:
1. **隐私优先**: 未显式允许 remote 时,不上传用户文档。
-2. **质量优先**: 用户或 Agent 主动读取文档时,默认使用默认选择策略,且不会解析为 `flash`。
-3. **发现与阅读分离**: watch 可以自动使用 `flash`;主动阅读不能静默使用 `flash`。
+2. **质量优先**: 用户或 Agent 主动读取 PDF/image 文档时,默认使用默认选择策略,且不会解析为 `flash`。
+3. **发现与阅读分离**: watch 可以自动使用 `flash`;PDF/image 主动阅读不能静默使用 `flash`。
4. **结果记录实际 tier**: 默认选择是请求时选择逻辑,任务、缓存、产物和 metadata 记录实际使用的实体 tier。
5. **backend 只在专家层和 Tool SDK parser 层暴露**: Tool SDK 的直接 parser 可以接受专家 `backend` 参数;API-backed parser、Doclib SDK、doclib server API 和 v1 API 只面向 `tier`,不暴露 `backend`。
6. **缓存按内容和 tier 隔离**: 同一 `sha256 + tier` 的解析结果可以复用;不同 tier 的结果不能互相覆盖。
@@ -68,7 +68,7 @@
├─ mineru parse / Agent 主动读取
│ -> doclib ParseService
│ -> 查缓存
- │ -> 默认选择/flash/medium/high/extra_high 路由
+ │ -> 默认选择/flash/medium/high/xhigh 路由
│ -> ParseWorker
│ -> Tool SDK 或 parse-server
│ -> Middle JSON batch JSON
@@ -102,7 +102,8 @@ watch 的目标是发现文件、建立基础索引和支持后续搜索,不
| 场景 | 默认 tier |
|------|-----------|
| watch 自动发现 | `flash` |
-| parsing-rule 明确指定 | rule 中的 tier |
+| parsing-rule 明确指定 | PDF/image 使用 rule 中的 tier;Office/text/HTML 归一为 `flash` |
+| parsing-rule 未指定 tier | PDF/image 按 `high` -> `xhigh` -> `medium` -> `flash`;Office/text/HTML 归一为 `flash` |
### 5.3 步骤
@@ -279,7 +280,7 @@ client.parse("report.pdf")
### 6.2 默认目标
-主动读取的目标是尽可能准确地理解文档。未指定 tier 时,使用默认选择策略,并至少解析到 `medium`。
+主动读取 PDF/image 的目标是尽可能准确地理解文档。未指定 tier 时,使用默认选择策略,并解析到可用的非 `flash` 质量 tier。Office/text/HTML 没有质量 tier,未指定 tier 时归一为 `flash`。
### 6.3 步骤
@@ -288,7 +289,7 @@ client.parse("report.pdf")
3. 如果文件尚未入库,先同步执行 ingest,得到 `sha256`。
4. 确定页码范围、输出格式、等待策略和隐私偏好。
5. 如果用户未指定 tier,使用默认选择策略。
-6. 默认选择策略通过当前可用 parse-server 能力发现选择最高非 `flash` tier。
+6. PDF/image 默认选择策略通过当前可用 parse-server 能力发现,按 `high` -> `xhigh` -> `medium` 选择;Office/text/HTML 归一为 `flash`。
7. 将任务和缓存键落到实际使用的实体 tier。
8. 查询 `(sha256, tier, page_range)` 是否已有可复用结果。
9. 缓存命中则直接 render 并返回。
@@ -305,11 +306,11 @@ client.parse("report.pdf")
| 请求 | 实际行为 |
|------|----------|
-| 未指定 tier | 选择最高可用非 `flash` tier |
+| 未指定 tier | PDF/image 按 `high` -> `xhigh` -> `medium` 选择可用的非 `flash` tier;Office/text/HTML 归一为 `flash` |
| `tier=flash` | 显式使用本地 `flash` backend |
| `tier=medium` | 使用本地或自部署 parse-server 的 `medium` 能力 |
| `tier=high` | 使用本地 `high` 或 `mineru.net/api` 的 `high` 能力 |
-| `tier=extra_high` | 使用本地或自部署 parse-server 的 `extra_high` 能力 |
+| `tier=xhigh` | 使用本地或自部署 parse-server 的 `xhigh` 能力 |
结果只需要记录实际使用的 `tier`。如果默认选择最终选择 `high`,产物、缓存和 metadata 使用 `high`。
@@ -336,7 +337,7 @@ doclib 不持久化 Markdown、Content List 或 HTML。它们都是 CPU-only 的
### 6.7 约束
-- 如果只有 `flash` 可用,默认选择应失败,不静默返回 `flash`。
+- 对 PDF/image,如果只有 `flash` 可用,默认选择应失败,不静默返回 `flash`。
- 如果本地没有可用质量 tier 且未允许 remote,应返回可操作错误。
- 如果缓存中只有 `flash`,主动读取未指定 tier 不能直接命中该缓存。
- 如果用户显式 `tier=flash`,可以返回 `flash` 缓存或重新解析。
@@ -360,7 +361,7 @@ watch -> flash index -> search result -> Agent chooses document -> mineru parse
3. search result 返回路径、sha256、snippet、当前索引来源 tier。
4. Agent 选择具体文档。
5. Agent 发起主动 parse 请求。
-6. 请求未指定 tier 时使用默认选择策略。
+6. PDF/image 请求未指定 tier 时使用默认选择策略;Office/text/HTML 按 `flash` 语义处理。
7. doclib 检查是否已有可用质量 tier 缓存。
8. 如果没有,则创建高优先级 parse 任务。
9. 解析完成后返回可阅读输出,并写入更高质量索引。
@@ -397,7 +398,7 @@ marker 不应依赖自然语言提示。具体 marker 格式可在 CLI 或 Agent
1. 客户端创建 upload 或提供已有 `file_id`。
2. 客户端创建 parse job。
-3. 请求可以携带 `tier`;省略或传 JSON `null` 时使用默认选择策略。
+3. 请求可以携带 `tier`;省略或传 JSON `null` 时,PDF/image 使用默认选择策略,Office/text/HTML 按批量规则归一为 `flash`。
4. API service 做鉴权、配额和输入校验。
5. 调度到可用解析能力。
6. 解析服务生成 Middle JSON 和请求的输出格式。
@@ -487,7 +488,7 @@ doclib 解析产物按内容和实际使用的 tier 隔离。`parsed/` 目录下
11~20_1710002234000.json
high/
1~20_1710003234000.json
- extra_high/
+ xhigh/
1~20_1710004234000.json
images/
```
@@ -569,20 +570,12 @@ compaction 不生成 Markdown 或 Content List。
### 10.5 Metadata 更新
-文档 metadata 可由更高质量 tier 覆盖低质量 tier。
-
-建议优先级:
-
-```text
-flash < medium < high < extra_high
-```
+文档 metadata 可由更高质量 tier 覆盖低质量 tier,优先级以 [解析 Tier](tiers.md) 为准。
约束:
- `flash` 不应覆盖来自质量 tier 的 metadata。
-- `medium` 可以覆盖 `flash`。
-- `high` 可以覆盖 `medium` 和 `flash`。
-- `extra_high` 可以覆盖 `high`、`medium` 和 `flash`。
+- 质量 tier 可以覆盖低质量 tier 的 metadata。
### 10.6 搜索索引
@@ -596,7 +589,7 @@ FTS 更新可以在解析完成后临时从 ParseResult 或 Middle JSON 渲染 M
| 错误 | 典型原因 | 恢复建议 |
|------|----------|----------|
-| `quality_tier_unavailable` | 主动阅读需要高质量 tier,但只有 `flash` | 启动本地解析服务或允许远端解析 |
+| `quality_tier_unavailable` | PDF/image 主动阅读需要非 `flash` 质量 tier,但只有 `flash` | 启动本地解析服务或允许远端解析 |
| `no_engine` | 请求 tier 没有可用解析服务或解析后端 | 配置 local parse-server、调整 tier |
| `engine_unavailable` | 解析服务或解析后端暂不可用 | 稍后重试或重启 parse-server |
| `parse_server_unavailable` | Local/Remote Parse Server 不可达 | 检查 URL、进程、网络和 API Key |
@@ -688,7 +681,7 @@ mineru parse report.pdf --wait 60
前提:
-- 可发现 Local Parse Server 支持 `medium` 和 `high`。
+- 可发现 Local Parse Server 支持 `high`。
期望:
diff --git a/mineru/backend/hybrid/hybrid_analyze.py b/mineru/backend/hybrid/hybrid_analyze.py
index 3641442e..5b2c57d2 100644
--- a/mineru/backend/hybrid/hybrid_analyze.py
+++ b/mineru/backend/hybrid/hybrid_analyze.py
@@ -143,7 +143,7 @@ def _load_vlm_content_block() -> Any:
def _load_vlm_runtime() -> dict[str, Any]:
- """按需加载 VLM runtime 组件,确保只有 high/extra_high 路径触发 VLM 依赖。"""
+ """按需加载 VLM runtime 组件,确保只有 high/xhigh 路径触发 VLM 依赖。"""
from ...model.vlm.runtime import (
ModelSingleton,
_get_model_async,
@@ -1963,7 +1963,7 @@ def doc_analyze(
language: str = "ch",
model_path: str | None = None,
server_url: str | None = None,
- effort: Literal["medium", "high", "extra_high"] = DEFAULT_HYBRID_EFFORT,
+ effort: Literal["medium", "high", "xhigh"] = DEFAULT_HYBRID_EFFORT,
image_analysis: bool = True,
page_index_map: list[int] | None = None,
image_cache: ImagePayloadCache | None = None,
@@ -2126,7 +2126,7 @@ async def aio_doc_analyze(
language: str = "ch",
model_path: str | None = None,
server_url: str | None = None,
- effort: Literal["medium", "high", "extra_high"] = DEFAULT_HYBRID_EFFORT,
+ effort: Literal["medium", "high", "xhigh"] = DEFAULT_HYBRID_EFFORT,
image_analysis: bool = True,
page_index_map: list[int] | None = None,
image_cache: ImagePayloadCache | None = None,
diff --git a/mineru/backend/local_model_runtime.py b/mineru/backend/local_model_runtime.py
index 50dd681e..2b63101b 100644
--- a/mineru/backend/local_model_runtime.py
+++ b/mineru/backend/local_model_runtime.py
@@ -38,7 +38,7 @@ class AtomicModel:
TableOrientationCls = "table_ori_cls"
LOCAL_MODEL_INIT_LOCK = threading.RLock()
-# 这些锁保护 Hybrid medium/high/extra_high 共享的 atom model/native 模型推理调用,避免多线程同时进入同一个模型对象。
+# 这些锁保护 Hybrid medium/high/xhigh 共享的 atom model/native 模型推理调用,避免多线程同时进入同一个模型对象。
LOCAL_MODEL_LAYOUT_INFERENCE_LOCK = threading.RLock()
LOCAL_MODEL_MFR_INFERENCE_LOCK = threading.RLock()
LOCAL_MODEL_OCR_INFERENCE_LOCK = threading.RLock()
diff --git a/mineru/cli/commands/config.py b/mineru/cli/commands/config.py
index fbda9cd0..86547d84 100644
--- a/mineru/cli/commands/config.py
+++ b/mineru/cli/commands/config.py
@@ -100,7 +100,7 @@ def exclude_rules_remove(rule_id: int = typer.Argument(..., help="Rule id to rem
@parsing_rules_app.command("add")
def parsing_rules_add(
pattern: str = typer.Argument(..., help="Glob pattern to match"),
- tier: Tier | None = typer.Option(None, "--tier", help="Parse tier: flash, medium, high, extra_high"),
+ tier: Tier | None = typer.Option(None, "--tier", help="Parse tier: flash, medium, high, xhigh"),
pages: str | None = typer.Option(None, "--pages", help="Page range, e.g. all or 1~10"),
remote: bool = typer.Option(False, "--remote", help="Allow remote parsing"),
name: str | None = typer.Option(None, "--name", help="Rule name"),
diff --git a/mineru/cli/commands/parse.py b/mineru/cli/commands/parse.py
index 89b335b7..1b51e1f1 100644
--- a/mineru/cli/commands/parse.py
+++ b/mineru/cli/commands/parse.py
@@ -92,7 +92,7 @@ def parse_cmd(
tier: Tier | None = typer.Option(
None,
"--tier",
- help="Parse tier: flash, medium, high, extra_high (default: server decides)",
+ help="Parse tier: flash, medium, high, xhigh (default: server decides)",
),
pages: str = typer.Option(None, "-p", "--pages", help="Page range, e.g. '1~5' or 'all'"),
after: str = typer.Option(None, "--after", help="Continue reading after a content cursor"),
diff --git a/mineru/cli/commands/search.py b/mineru/cli/commands/search.py
index 5fdd063c..3653ddd8 100644
--- a/mineru/cli/commands/search.py
+++ b/mineru/cli/commands/search.py
@@ -17,11 +17,11 @@ FILE_EXTS = "pdf, png, jpg, jpeg, jp2, webp, gif, bmp, tiff, docx, pptx, xlsx, h
def search_cmd(
query: str = typer.Argument(..., help="Search query"),
file_type: str | None = typer.Option(None, "--type", help=f"File type filter: {FILE_TYPES}"),
- tier: Tier | None = typer.Option(None, "--tier", help="Exact search index tier: flash, medium, high, extra_high"),
+ tier: Tier | None = typer.Option(None, "--tier", help="Exact search index tier: flash, medium, high, xhigh"),
min_tier: Tier | None = typer.Option(
None,
"--min-tier",
- help="Minimum search index tier: flash, medium, high, extra_high",
+ help="Minimum search index tier: flash, medium, high, xhigh",
),
limit: int = typer.Option(20, "--limit", "-n", help="Max results"),
offset: int = typer.Option(0, "--offset", help="Result offset"),
diff --git a/mineru/cli_old/api_request.py b/mineru/cli_old/api_request.py
index 753d9740..9b223000 100644
--- a/mineru/cli_old/api_request.py
+++ b/mineru/cli_old/api_request.py
@@ -121,19 +121,28 @@ async def parse_request_form(
backend: Annotated[
str,
Form(
- description="""The backend for parsing:
-- hybrid-engine: Hybrid parsing via local computing power. Hybrid medium supports language-aware local OCR; use effort to switch medium/high/extra_high behavior.
-- hybrid-http-client: Hybrid parsing via remote computing power but requires a little local computing power(client suitable for openai-compatible servers). Hybrid medium supports language-aware local OCR; use effort to switch medium/high/extra_high behavior.""",
+ description=(
+ "The backend for parsing:\n"
+ "- hybrid-engine: Hybrid parsing via local computing power. Hybrid medium supports language-aware local OCR; "
+ "use effort to switch medium/high/xhigh behavior.\n"
+ "- hybrid-http-client: Hybrid parsing via remote computing power but requires a little local computing power"
+ "(client suitable for openai-compatible servers). Hybrid medium supports language-aware local OCR; "
+ "use effort to switch medium/high/xhigh behavior."
+ ),
json_schema_extra=BACKEND_SCHEMA_EXTRA,
),
] = DEFAULT_BACKEND,
effort: Annotated[
str,
Form(
- description="""(Adapted only for hybrid backend) Hybrid parsing effort:
-- medium: Local Hybrid processing without VLM calls. Supports language-aware local OCR and table OCR. Image/chart analysis is disabled.
-- high: Faster VLM parsing for most documents, balancing accuracy and efficiency. Image/chart analysis is disabled.
-- extra_high: Higher-accuracy parsing with image/chart analysis support, which may take longer.""",
+ description=(
+ "(Adapted only for hybrid backend) Hybrid parsing effort:\n"
+ "- medium: Local Hybrid processing without VLM calls. Supports language-aware local OCR and table OCR. "
+ "Image/chart analysis is disabled.\n"
+ "- high: Faster VLM parsing for most documents, balancing accuracy and efficiency. "
+ "Image/chart analysis is disabled.\n"
+ "- xhigh: Higher-accuracy parsing with image/chart analysis support, which may take longer."
+ ),
json_schema_extra=HYBRID_EFFORT_SCHEMA_EXTRA,
),
] = DEFAULT_HYBRID_EFFORT,
diff --git a/mineru/cli_old/client.py b/mineru/cli_old/client.py
index 31c76b9a..c9c0131d 100644
--- a/mineru/cli_old/client.py
+++ b/mineru/cli_old/client.py
@@ -1021,7 +1021,7 @@ async def run_orchestrated_cli(
Hybrid parsing effort:
medium: Local Hybrid processing without VLM calls. Image/chart analysis is disabled.
high: Faster VLM parsing for most documents, balancing accuracy and efficiency. Image/chart analysis is disabled.
- extra_high: Higher-accuracy parsing with image/chart analysis support, which may take longer.
+ xhigh: Higher-accuracy parsing with image/chart analysis support, which may take longer.
Without effort specified, high will be used by default.
Adapted only for the case where the backend is set to 'hybrid-*'.""",
)
diff --git a/mineru/cli_old/gradio_app.py b/mineru/cli_old/gradio_app.py
index 15b559c0..10b9844a 100644
--- a/mineru/cli_old/gradio_app.py
+++ b/mineru/cli_old/gradio_app.py
@@ -47,11 +47,11 @@ from mineru.cli_old.visualization import (
run_visualization_job,
)
from mineru.cli_old import api_client as _api_client
-from mineru.data.data_reader_writer.filebase import FileBasedDataWriter
from mineru.parser.api_client import MinerUApiParser
from mineru.parser.base import ParseResult
from mineru.parser.tier import ParserRuntimeOptions, runtime_options_for_tier
from mineru.render import render_content_list, render_markdown, render_structured_content
+from mineru.render.writer import FileBasedDataWriter
from mineru.utils.image_payload import validate_image_sidecar_path
from mineru.utils.pdf_document import PDFDocument
from mineru.utils.pdf_page_id import parse_page_range
@@ -240,7 +240,7 @@ STATUS_PROCESSING_ON_SERVER = "Processing on server"
STATUS_QUEUED_LOCALLY_PREFIX = "Queued locally:"
DEFAULT_GRADIO_TIER = "high"
-GRADIO_TIER_CHOICES = ("flash", "medium", "high", "extra_high")
+GRADIO_TIER_CHOICES = ("flash", "medium", "high", "xhigh")
STATUS_STEP_DEFINITIONS = [
("status_step_prepare", STATUS_PREPARING_REQUEST),
("status_step_check", STATUS_CHECKING_SERVER),
@@ -414,7 +414,9 @@ def default_v1_gradio_tier(tier_choices: tuple[str, ...]) -> str:
raise click.ClickException("MinerU v1 API did not advertise any supported tier.")
if DEFAULT_GRADIO_TIER in tier_choices:
return DEFAULT_GRADIO_TIER
- return tier_choices[0]
+ from ..types import select_default_quality_tier
+
+ return select_default_quality_tier(tier_choices) or tier_choices[0]
async def fetch_v1_tier_choices(http_client, base_url: str) -> tuple[str, ...]:
@@ -601,8 +603,8 @@ def select_tier_info_key(tier_choice: object) -> str:
return "tier_info_medium"
if tier_choice == "high":
return "tier_info_high"
- if tier_choice == "extra_high":
- return "tier_info_extra_high"
+ if tier_choice == "xhigh":
+ return "tier_info_xhigh"
return "tier_info_default"
@@ -1753,7 +1755,7 @@ def main(ctx,
"tier_info_flash": "Flash tier uses fast local text extraction.",
"tier_info_medium": "Medium tier uses local Hybrid parsing.",
"tier_info_high": "High tier uses higher quality Hybrid parsing.",
- "tier_info_extra_high": "Extra high tier uses maximum-quality Hybrid parsing.",
+ "tier_info_xhigh": "Extra High tier uses maximum-quality Hybrid parsing.",
"convert": "Convert",
"clear": "Clear",
"doc_preview": "Document preview",
@@ -1804,7 +1806,7 @@ def main(ctx,
"tier_info_flash": "flash 使用快速本地文本提取。",
"tier_info_medium": "medium 使用本地 Hybrid 解析。",
"tier_info_high": "high 使用更高质量的 Hybrid 解析。",
- "tier_info_extra_high": "extra_high 使用最高质量的 Hybrid 解析。",
+ "tier_info_xhigh": "xhigh 使用最高质量的 Hybrid 解析。",
"convert": "转换",
"clear": "清除",
"doc_preview": "文档预览",
diff --git a/mineru/doclib/background/parse_server_health.py b/mineru/doclib/background/parse_server_health.py
index 1ccfee37..eb48955d 100644
--- a/mineru/doclib/background/parse_server_health.py
+++ b/mineru/doclib/background/parse_server_health.py
@@ -63,7 +63,7 @@ def get_health() -> ParseServerHealth:
async def get_managed_parse_server_tier(config_svc: "ConfigService") -> Tier:
- """读取 managed parse-server tier;发现旧非法 override 时清理并回退到默认合法值。"""
+ """读取 managed parse-server tier;发现非法 override 时清理并回退到默认合法值。"""
key = "parse_server.local.managed_tier"
raw_tier = await config_svc.get(key) or CONFIG_DEFAULTS[key]
try:
diff --git a/mineru/doclib/background/watch.py b/mineru/doclib/background/watch.py
index 73baab57..fc2f01fb 100644
--- a/mineru/doclib/background/watch.py
+++ b/mineru/doclib/background/watch.py
@@ -10,7 +10,7 @@ from pathlib import Path
from watchfiles import awatch
from ..core.db import DatabaseManager
-from ..constants import DISCOVERABLE_EXTENSIONS, is_office_temp_lock_file
+from ...filetypes import DISCOVERABLE_EXTENSIONS, is_office_temp_lock_file
from ..services.config_svc import ConfigService
from ..services.parse_svc import ParseService
from ..services.scan_svc import ScanService
diff --git a/mineru/doclib/config_schema.py b/mineru/doclib/config_schema.py
index f835661b..c7129719 100644
--- a/mineru/doclib/config_schema.py
+++ b/mineru/doclib/config_schema.py
@@ -8,7 +8,7 @@ from ..errors import InvalidRequestError
from .config_defaults import CONFIG_DEFAULTS
LOCAL_PARSE_SERVER_MODES = ("disabled", "managed", "self_hosted")
-MANAGED_PARSE_SERVER_TIERS = ("medium", "high", "extra_high")
+MANAGED_PARSE_SERVER_TIERS = ("medium", "high", "xhigh")
URL_CONFIG_KEYS = ("parse_server.remote.url", "parse_server.local.self_hosted_url")
diff --git a/mineru/doclib/constants.py b/mineru/doclib/constants.py
index 7b80aed2..3b84c710 100644
--- a/mineru/doclib/constants.py
+++ b/mineru/doclib/constants.py
@@ -1,77 +1,7 @@
-"""Shared file type whitelists and constants."""
+"""Doclib configuration defaults and constants."""
from __future__ import annotations
-from pathlib import Path
-
-# ── file types ─────────────────────────────────────────────────────
-
-OFFICE_EXTENSIONS: set[str] = {
- "docx",
- "pptx",
- "xlsx",
-}
-
-LEGACY_OFFICE_EXTENSION_UPGRADES: dict[str, str] = {
- "doc": "docx",
- "ppt": "pptx",
- "xls": "xlsx",
-}
-
-IMAGE_EXTENSIONS: set[str] = {
- "bmp",
- "gif",
- "jp2",
- "jpeg",
- "jpg",
- "png",
- "tiff",
- "webp",
-}
-
-TEXT_EXTENSIONS: set[str] = {
- "csv",
- "md",
- "markdown",
- "rst",
- "tex",
- "txt",
-}
-
-DISCOVERABLE_EXTENSIONS: set[str] = {
- "pdf",
- *OFFICE_EXTENSIONS,
- "html",
- "htm",
- *TEXT_EXTENSIONS,
- # Unsupported legacy Office formats:
- # "doc",
- # "xls",
- # "ppt",
- # Unsupported document/e-book/archive-like formats:
- # "epub",
- # "key",
- # "mobi",
- # "numbers",
- # "ods",
- # "odt",
- # "pages",
- # "rtf",
- # Unsupported mail formats:
- # "eml",
- # "mbox",
-}
-
-PARSEABLE_EXTENSIONS: set[str] = {
- *DISCOVERABLE_EXTENSIONS,
- *IMAGE_EXTENSIONS,
-}
-
-
-def is_office_temp_lock_file(path: str | Path) -> bool:
- file_path = Path(path)
- return file_path.name.startswith("~$") and file_path.suffix.lower().lstrip(".") in OFFICE_EXTENSIONS
-
DEFAULT_EXCLUDE_PATTERNS: list[str] = [
"*/Library/*",
"*/.git/*",
diff --git a/mineru/doclib/core/db.py b/mineru/doclib/core/db.py
index 04164e58..43c954bc 100644
--- a/mineru/doclib/core/db.py
+++ b/mineru/doclib/core/db.py
@@ -11,7 +11,7 @@ import aiosqlite
from ...config import SQLiteConfig
from ..config_defaults import CONFIG_DEFAULTS
-SCHEMA_VERSION = 2
+SCHEMA_VERSION = 1
_MIGRATIONS_DIR = Path(__file__).resolve().parent.parent / "migrations"
_T = TypeVar("_T")
diff --git a/mineru/doclib/locators.py b/mineru/doclib/locators.py
index 12cee1aa..60d978dd 100644
--- a/mineru/doclib/locators.py
+++ b/mineru/doclib/locators.py
@@ -9,7 +9,7 @@ from ..types import Tier
_CURSOR_RE = re.compile(
r"^doc:(?P<short_id>[0-9a-fA-F]+)"
- r"/tier:(?P<tier>flash|medium|high|extra_high)"
+ r"/tier:(?P<tier>flash|medium|high|xhigh)"
r"/page:(?P<page_no>[1-9][0-9]*)"
r"(?:/block:(?P<block_no>[1-9][0-9]*)(?:/char:(?P<char_offset>0|[1-9][0-9]*))?)?$"
)
diff --git a/mineru/doclib/migrations/002_map_legacy_tiers.sql b/mineru/doclib/migrations/002_map_legacy_tiers.sql
deleted file mode 100644
index 06e3cd73..00000000
--- a/mineru/doclib/migrations/002_map_legacy_tiers.sql
+++ /dev/null
@@ -1,16 +0,0 @@
--- v002: Map legacy doclib tiers to the current public tier names.
-
-UPDATE parses SET tier = 'medium' WHERE tier = 'standard';
-UPDATE parses SET tier = 'high' WHERE tier = 'pro';
-
-UPDATE fts_contents SET tier = 'medium' WHERE tier = 'standard';
-UPDATE fts_contents SET tier = 'high' WHERE tier = 'pro';
-
-UPDATE docs SET meta_tier = 'medium' WHERE meta_tier = 'standard';
-UPDATE docs SET meta_tier = 'high' WHERE meta_tier = 'pro';
-
-UPDATE parsing_rules SET tier = 'medium' WHERE tier = 'standard';
-UPDATE parsing_rules SET tier = 'high' WHERE tier = 'pro';
-
-UPDATE config SET value = 'medium' WHERE key = 'parse_server.local.managed_tier' AND value = 'standard';
-UPDATE config SET value = 'high' WHERE key = 'parse_server.local.managed_tier' AND value = 'pro';
diff --git a/mineru/doclib/server.py b/mineru/doclib/server.py
index cc719a5a..cd5581cc 100644
--- a/mineru/doclib/server.py
+++ b/mineru/doclib/server.py
@@ -24,7 +24,7 @@ from ..parser.tier import TierDependencyError, ensure_tier_runtime_dependencies
from ..render import render_markdown
from ..render.markdown import blocks_to_markdown
from ..render.office.output import blocks_to_markdown as office_blocks_to_markdown
-from ..types import EMPTY_BBOX, TIER_ORDER, TIERS, Block, PageInfo, Span, Tier
+from ..types import EMPTY_BBOX, TIERS, Block, PageInfo, Span, Tier, select_highest_cached_tier
from ..utils.pdf_document import PDFDocument
from ..version import __version__
from .background.parse_server_health import get_health, get_managed_parse_server_tier
@@ -671,7 +671,7 @@ class DoclibServer(AsyncDoclibInterface):
short_id=doc["short_id"],
tier=tier,
page_range=page_range,
- after=_locator_after(cursor),
+ after=_locator_after(cursor, tier),
locator=_canonical_locator(doc["short_id"], tier, cursor),
context=context,
limit=limit,
@@ -1303,7 +1303,7 @@ class DoclibServer(AsyncDoclibInterface):
tiers: set[Tier] = {row["tier"] for row in rows if row["tier"] in TIERS and row["tier"] != "flash"}
if not tiers:
return None
- return max(tiers, key=lambda t: TIER_ORDER[t])
+ return select_highest_cached_tier(tiers)
async def _render_pdf_image_asset(self, plan: _ReadPlan, page: PageInfo) -> ContentAsset:
if plan.target is None:
@@ -1382,7 +1382,7 @@ class DoclibServer(AsyncDoclibInterface):
_READ_LOCATOR_RE = re.compile(
r"^doc:(?P<short_id>[0-9a-fA-F]+)"
- r"(?:/tier:(?P<tier>flash|medium|high|extra_high)"
+ r"(?:/tier:(?P<tier>flash|medium|high|xhigh)"
r"(?:/page:(?P<page_no>[1-9][0-9]*)"
r"(?:/block:(?P<block_no>[1-9][0-9]*)(?:/char:(?P<char_offset>0|[1-9][0-9]*))?)?)?)?$"
)
@@ -1414,12 +1414,12 @@ def _canonical_locator(short_id: str, tier: Tier, locator: _LocatorParts) -> str
return block_char_ref(short_id, tier, locator.page_no, locator.block_no, locator.char_offset)
-def _locator_after(locator: _LocatorParts) -> str | None:
+def _locator_after(locator: _LocatorParts, tier: Tier) -> str | None:
if locator.page_no is None:
return None
if locator.block_no is None:
return None
- return _canonical_locator(locator.short_id, locator.tier or "high", locator) if locator.char_offset is not None else None
+ return _canonical_locator(locator.short_id, tier, locator) if locator.char_offset is not None else None
def _locator_page_range(locator: _LocatorParts, doc: DocRow, context: int) -> str | None:
@@ -1531,10 +1531,10 @@ def _ensure_managed_parse_server_tier_available(tier: Tier, param: str) -> None:
def _validate_managed_parse_server_tier(value: str, param: str) -> Tier:
- if value not in ("flash", "medium", "high", "extra_high"):
+ if value not in ("medium", "high", "xhigh"):
raise InvalidRequestError(
"invalid_config_value",
- "parse_server.local.managed_tier must be one of: flash, medium, high, extra_high.",
+ "parse_server.local.managed_tier must be one of: medium, high, xhigh.",
param,
)
return cast(Tier, value)
diff --git a/mineru/doclib/services/parse_svc.py b/mineru/doclib/services/parse_svc.py
index 62eca52c..c4ff28c6 100644
--- a/mineru/doclib/services/parse_svc.py
+++ b/mineru/doclib/services/parse_svc.py
@@ -14,17 +14,19 @@ from typing import Literal, cast
from urllib.parse import urlparse
from ...errors import InvalidRequestError, MineruError
-from ...parser.api_client import _V1APIError
-from ...parser.base import ParseResult
-from ...types import TIER_ORDER, PageInfo, Tier
-from ..constants import (
+from ...filetypes import (
IMAGE_EXTENSIONS,
LEGACY_OFFICE_EXTENSION_UPGRADES,
OFFICE_EXTENSIONS,
PARSEABLE_EXTENSIONS,
TEXT_EXTENSIONS,
+ TIERED_PARSE_EXTENSIONS,
is_office_temp_lock_file,
+ select_parsing_rule_tier,
)
+from ...parser.api_client import _V1APIError
+from ...parser.base import ParseResult
+from ...types import QUALITY_TIERS, TIER_ORDER, PageInfo, Tier, select_default_quality_tier
from ..core.db import DatabaseManager
from ..core.file_io import FileStat, MetadataExtractionError, compute_sha256, extract_metadata, get_file_stat
from ..core.fts import FTSManager
@@ -72,9 +74,6 @@ DOC_TYPE_BY_EXT = {
**dict.fromkeys(IMAGE_EXTENSIONS, "image"),
}
-QUALITY_TIER_EXTENSIONS: set[str] = {"pdf", *IMAGE_EXTENSIONS}
-
-
FileRefreshStatus = Literal["known", "new", "changed", "missing", "deleted", "unreachable", "unsupported", "error"]
@@ -641,13 +640,21 @@ class ParseService:
# determine tier and page_range for initial parse
tier: Tier = "flash"
+ privacy = "local"
initial_page_range = default_parse_range(page_count)
# check parsing-rules
matched = await self.config_svc.match_rules(path, RULE_TYPE_PARSING_RULE)
if matched:
rule = matched[0]
- tier = rule.get("tier") or tier
+ rule_tier = cast(Tier | None, rule.get("tier"))
+ rule_remote = bool(rule.get("remote", False))
+ if ext in TIERED_PARSE_EXTENSIONS:
+ tier = rule_tier or _resolve_parsing_rule_default_tier(remote=rule_remote)
+ privacy = "remote" if rule_remote and tier != "flash" else "local"
+ else:
+ tier = "flash"
+ privacy = "local"
rule_page_range = rule.get("page_range")
if rule_page_range:
initial_page_range = expand_page_range(rule_page_range, page_count or 1)
@@ -659,8 +666,9 @@ class ParseService:
(sha256, now, path),
)
await self.db.execute(
- "INSERT INTO parses (sha256, tier, page_range, status, priority, created_at, updated_at) VALUES (?, ?, ?, ?, 0, ?, ?)",
- (sha256, tier, parse_page_range, PARSE_STATUS_PENDING, now, now),
+ "INSERT INTO parses (sha256, tier, page_range, status, privacy, priority, created_at, updated_at) "
+ "VALUES (?, ?, ?, ?, ?, 0, ?, ?)",
+ (sha256, tier, parse_page_range, PARSE_STATUS_PENDING, privacy, now, now),
)
await self._record_count("parse_task.created.count", dimensions={"tier": tier})
@@ -707,7 +715,11 @@ class ParseService:
raise MineruError("ingest_failed", "File could not be ingested.", "path")
sha256 = file_row["sha256"]
if sha256 is None:
- raise MineruError(file_row.get("error_code") or "ingest_failed", file_row.get("error_msg") or "File could not be ingested.", "path")
+ raise MineruError(
+ file_row.get("error_code") or "ingest_failed",
+ file_row.get("error_msg") or "File could not be ingested.",
+ "path",
+ )
doc = cast(DocRow | None, await self.db.fetchone("SELECT * FROM docs WHERE sha256=?", (sha256,)))
page_count = doc["page_count"] if doc else 1
short_id = doc["short_id"] if doc else None
@@ -715,7 +727,7 @@ class ParseService:
ext = file_row["ext"]
# ── resolve tier (before cache check) ──
- if remote and ext not in QUALITY_TIER_EXTENSIONS:
+ if remote and ext not in TIERED_PARSE_EXTENSIONS:
raise InvalidRequestError(
"remote_unsupported_for_file_type",
f"Remote parsing is only supported for PDF and image files; '{ext}' files use local flash parsing.",
@@ -724,10 +736,10 @@ class ParseService:
if remote and tier == "flash":
raise InvalidRequestError(
"tier_unsupported_for_remote",
- "--remote does not support tier 'flash'; use --tier medium, --tier high, or --tier extra_high.",
+ "--remote does not support tier 'flash'; use --tier medium, --tier high, or --tier xhigh.",
"tier",
)
- if tier in ("medium", "high", "extra_high") and ext not in QUALITY_TIER_EXTENSIONS:
+ if tier in QUALITY_TIERS and ext not in TIERED_PARSE_EXTENSIONS:
raise InvalidRequestError(
"tier_unsupported_for_file_type",
f"Tier '{tier}' is only supported for PDF and image files; '{ext}' files use --tier flash.",
@@ -735,7 +747,7 @@ class ParseService:
)
if ext in TEXT_EXTENSIONS:
return _text_response(sha256, short_id)
- if ext in QUALITY_TIER_EXTENSIONS:
+ if ext in TIERED_PARSE_EXTENSIONS:
requested_tier = tier or _resolve_default_tier(remote)
else:
requested_tier = "flash"
@@ -1366,26 +1378,33 @@ class ParseService:
def _resolve_default_tier(remote: bool = False) -> Tier:
- """从健康检查中选择最高可用质量 tier,顺序为 extra_high > high > medium。"""
+ """从健康检查中选择默认质量 tier,顺序为 high > xhigh > medium。"""
from ..background.parse_server_health import get_health
health = get_health()
supported = health.remote_supported_tiers if remote else health.local_supported_tiers
- for candidate in ("extra_high", "high", "medium"):
- if candidate in supported:
- return candidate
+ selected = select_default_quality_tier(supported)
+ if selected is not None:
+ return selected
actions = ["start a local parse-server"]
- if not remote and health.remote_healthy and any(
- tier in health.remote_supported_tiers for tier in ("extra_high", "high", "medium")
- ):
+ if not remote and health.remote_healthy and select_default_quality_tier(health.remote_supported_tiers) is not None:
actions.append("use --remote")
actions.append("explicitly pass --tier flash for text-only preview")
raise ParseFailure(
"quality_tier_unavailable",
- f"No medium, high, or extra_high engine available. You can {_format_action_list(actions)}.",
+ f"No medium, high, or xhigh engine available. You can {_format_action_list(actions)}.",
)
+def _resolve_parsing_rule_default_tier(remote: bool = False) -> Tier:
+ """Parsing-rule 是后台批量策略,允许 high -> xhigh -> medium -> flash。"""
+ from ..background.parse_server_health import get_health
+
+ health = get_health()
+ supported = health.remote_supported_tiers if remote else health.local_supported_tiers
+ return select_parsing_rule_tier(supported)
+
+
def _format_action_list(actions: list[str]) -> str:
if len(actions) == 1:
return actions[0]
@@ -1507,7 +1526,10 @@ def _remap_api_result_pages_to_page_range(result: ParseResult, page_range: str)
if len(requested_page_numbers) != len(result.pages):
raise ParseFailure(
"parse_page_remap_failed",
- f"Parse result page count does not match requested page_range: requested={page_range}, returned={actual_page_numbers}",
+ (
+ "Parse result page count does not match requested page_range: "
+ f"requested={page_range}, returned={actual_page_numbers}"
+ ),
)
for page, page_no in zip(result.pages, requested_page_numbers, strict=True):
page.page_idx = page_no - 1
diff --git a/mineru/doclib/services/scan_svc.py b/mineru/doclib/services/scan_svc.py
index 74f4c19f..2866e002 100644
--- a/mineru/doclib/services/scan_svc.py
+++ b/mineru/doclib/services/scan_svc.py
@@ -9,7 +9,7 @@ from pathlib import Path
from typing import Any, cast
from ...errors import InvalidRequestError, NotFoundError
-from ..constants import DISCOVERABLE_EXTENSIONS, is_office_temp_lock_file
+from ...filetypes import DISCOVERABLE_EXTENSIONS, is_office_temp_lock_file
from ..core.file_io import get_file_stat
from ..rows import PathRow, ScanRow, WatchTargetRow
from ..types import (
diff --git a/mineru/doclib/telemetry/constants.py b/mineru/doclib/telemetry/constants.py
index a7aebac4..547a313f 100644
--- a/mineru/doclib/telemetry/constants.py
+++ b/mineru/doclib/telemetry/constants.py
@@ -56,10 +56,10 @@ DIM_TIER_VALUES = frozenset(
"flash",
"medium",
"high",
- "extra_high",
+ "xhigh",
"medium(default)",
"high(default)",
- "extra_high(default)",
+ "xhigh(default)",
"unknown",
}
)
diff --git a/mineru/filetypes.py b/mineru/filetypes.py
new file mode 100644
index 00000000..78a7252a
--- /dev/null
+++ b/mineru/filetypes.py
@@ -0,0 +1,126 @@
+from __future__ import annotations
+
+from pathlib import Path
+
+from .types import QUALITY_TIER_SELECTION_ORDER, QUALITY_TIERS, Tier, validate_tier
+
+# ── file types ─────────────────────────────────────────────────────
+
+OFFICE_EXTENSIONS: set[str] = {
+ "docx",
+ "pptx",
+ "xlsx",
+}
+
+LEGACY_OFFICE_EXTENSION_UPGRADES: dict[str, str] = {
+ "doc": "docx",
+ "ppt": "pptx",
+ "xls": "xlsx",
+}
+
+IMAGE_EXTENSIONS: set[str] = {
+ "bmp",
+ "gif",
+ "jp2",
+ "jpeg",
+ "jpg",
+ "png",
+ "tiff",
+ "webp",
+}
+
+TEXT_EXTENSIONS: set[str] = {
+ "csv",
+ "md",
+ "markdown",
+ "rst",
+ "tex",
+ "txt",
+}
+
+HTML_EXTENSIONS: set[str] = {
+ "html",
+ "htm",
+}
+
+DISCOVERABLE_EXTENSIONS: set[str] = {
+ "pdf",
+ *OFFICE_EXTENSIONS,
+ *HTML_EXTENSIONS,
+ *TEXT_EXTENSIONS,
+ # Unsupported legacy Office formats:
+ # "doc",
+ # "xls",
+ # "ppt",
+ # Unsupported document/e-book/archive-like formats:
+ # "epub",
+ # "key",
+ # "mobi",
+ # "numbers",
+ # "ods",
+ # "odt",
+ # "pages",
+ # "rtf",
+ # Unsupported mail formats:
+ # "eml",
+ # "mbox",
+}
+
+PARSEABLE_EXTENSIONS: set[str] = {
+ *DISCOVERABLE_EXTENSIONS,
+ *IMAGE_EXTENSIONS,
+}
+
+TIERED_PARSE_EXTENSIONS: frozenset[str] = frozenset({"pdf", *IMAGE_EXTENSIONS})
+FLASH_ONLY_PARSE_EXTENSIONS: frozenset[str] = frozenset(
+ {
+ *OFFICE_EXTENSIONS,
+ *HTML_EXTENSIONS,
+ *TEXT_EXTENSIONS,
+ }
+)
+PARSING_RULE_TIER_SELECTION_ORDER: tuple[Tier, ...] = (*QUALITY_TIER_SELECTION_ORDER, "flash")
+
+
+def normalize_parse_extension(path_or_ext: str | Path) -> str:
+ text = str(path_or_ext)
+ if text.startswith("."):
+ return text.lower().lstrip(".")
+ suffix = Path(text).suffix
+ if suffix:
+ return suffix.lower().lstrip(".")
+ return text.lower().lstrip(".")
+
+
+def is_tiered_parse_extension(path_or_ext: str | Path) -> bool:
+ return normalize_parse_extension(path_or_ext) in TIERED_PARSE_EXTENSIONS
+
+
+def is_flash_only_parse_extension(path_or_ext: str | Path) -> bool:
+ return normalize_parse_extension(path_or_ext) in FLASH_ONLY_PARSE_EXTENSIONS
+
+
+def ensure_tier_supported_for_parse_extension(tier: Tier | None, path_or_ext: str | Path) -> None:
+ if tier not in QUALITY_TIERS or is_tiered_parse_extension(path_or_ext):
+ return
+ ext = normalize_parse_extension(path_or_ext)
+ raise ValueError(f"Tier '{tier}' is only supported for PDF and image files; '{ext}' files use tier 'flash'.")
+
+
+def batch_effective_parse_tier(tier: Tier, path_or_ext: str | Path) -> Tier:
+ if is_flash_only_parse_extension(path_or_ext):
+ return "flash"
+ return validate_tier(tier)
+
+
+def select_parsing_rule_tier(available_tiers: list[Tier] | tuple[Tier, ...] | set[Tier] | None = None) -> Tier:
+ available = set(available_tiers or PARSING_RULE_TIER_SELECTION_ORDER)
+ for candidate in PARSING_RULE_TIER_SELECTION_ORDER:
+ if candidate in available:
+ return candidate
+ return "flash"
+
+
+def is_office_temp_lock_file(path: str | Path) -> bool:
+ file_path = Path(path)
+ return file_path.name.startswith("~$") and file_path.suffix.lower().lstrip(".") in OFFICE_EXTENSIONS
diff --git a/mineru/kit/commands/api_server.py b/mineru/kit/commands/api_server.py
index 9610d52c..e758d88e 100644
--- a/mineru/kit/commands/api_server.py
+++ b/mineru/kit/commands/api_server.py
@@ -5,11 +5,12 @@ from typing import Literal, Sequence
import typer
from ...parser import api_server as parser_api_server
+from ...types import Tier
from ...utils.ocr_language import PUBLIC_OCR_LANGUAGES, validate_public_ocr_lang
from ..errors import exit_with_message
API_SERVER_LANGUAGES = PUBLIC_OCR_LANGUAGES
-API_SERVER_TIERS = ("flash", "medium", "high", "extra_high")
+API_SERVER_TIERS = ("flash", "medium", "high", "xhigh")
def _normalize_tier_options(tier: Sequence[str] | str | None) -> list[str]:
@@ -34,9 +35,7 @@ def api_server_cmd(
host: str = "127.0.0.1",
port: int = 8000,
upload_dir: str = "",
- tier: Sequence[Literal["flash", "medium", "high", "extra_high"]]
- | Literal["flash", "medium", "high", "extra_high"]
- | None = None,
+ tier: Sequence[Tier] | Tier | None = None,
concurrency: int = 1,
url_timeout: int = 60,
allow_local_source: bool = False,
diff --git a/mineru/kit/commands/parse.py b/mineru/kit/commands/parse.py
index d69bc651..8cbdf420 100644
--- a/mineru/kit/commands/parse.py
+++ b/mineru/kit/commands/parse.py
@@ -6,7 +6,9 @@ from typing import Literal
from ...parser import MinerUApiParser
from ...parser import parse as local_parse
-from ...utils.backend_options import DEFAULT_HYBRID_EFFORT, resolve_backend_and_effort
+from ...filetypes import ensure_tier_supported_for_parse_extension, is_flash_only_parse_extension
+from ...types import Tier
+from ...utils.backend_options import DEFAULT_HYBRID_EFFORT, effort_for_tier, resolve_backend_and_effort
from ...utils.ocr_language import validate_public_ocr_lang
from ..common import (
build_remote_api_url,
@@ -27,14 +29,14 @@ def parse_cmd(
pages: str | None = None,
format: Literal["markdown", "middle_json", "zip"] = "markdown",
verbose: bool = False,
- tier: Literal["flash", "medium", "high", "extra_high"] | None = None,
+ tier: Tier | None = None,
backend: str | None = None,
remote: bool = False,
remote_url: str | None = None,
api_key: str | None = None,
language: str = "ch",
ocr_mode: Literal["auto", "txt", "ocr"] = "auto",
- effort: Literal["medium", "high", "extra_high"] = DEFAULT_HYBRID_EFFORT,
+ effort: Literal["medium", "high", "xhigh"] = DEFAULT_HYBRID_EFFORT,
disable_image_analysis: bool = False,
) -> None:
if not inputs:
@@ -49,6 +51,7 @@ def parse_cmd(
"When input is multiple files or directories, --output must be a directory path.",
"output",
)
+ has_directory_input = any(path.is_dir() for path in raw_paths)
if len(raw_paths) > 1 and Path(output).expanduser().suffix:
exit_with_message(
"invalid_request",
@@ -73,19 +76,33 @@ def parse_cmd(
)
except ValueError as exc:
exit_with_message("invalid_request", str(exc), "backend")
- resolved_tier, resolved_backend = effective_local_tier_and_backend(tier, normalized_backend)
- if resolved_tier in {"medium", "high", "extra_high"}:
- normalized_effort = resolved_tier
- parse_one = partial(
- local_parse,
- tier=resolved_tier,
- backend=resolved_backend,
- language=normalized_language,
- ocr_mode=ocr_mode,
- effort=normalized_effort,
- disable_image_analysis=disable_image_analysis,
- page_range=pages or "",
- )
+ is_batch = has_directory_input or len(paths) > 1
+
+ def parse_one(path: Path) -> object:
+ path_tier: Tier
+ path_backend: str
+ path_effort = normalized_effort
+ if is_flash_only_parse_extension(path):
+ if not is_batch and (tier is not None or normalized_backend is not None):
+ resolved_tier, _resolved_backend = effective_local_tier_and_backend(tier, normalized_backend)
+ ensure_tier_supported_for_parse_extension(resolved_tier, path)
+ path_tier = "flash"
+ path_backend = "flash"
+ path_effort = DEFAULT_HYBRID_EFFORT
+ else:
+ path_tier, path_backend = effective_local_tier_and_backend(tier, normalized_backend)
+ if path_tier in {"medium", "high", "xhigh"}:
+ path_effort = effort_for_tier(path_tier)
+ return local_parse(
+ path,
+ tier=path_tier,
+ backend=path_backend,
+ language=normalized_language,
+ ocr_mode=ocr_mode,
+ effort=path_effort,
+ disable_image_analysis=disable_image_analysis,
+ page_range=pages or "",
+ )
for path in paths:
try:
diff --git a/mineru/kit/common.py b/mineru/kit/common.py
index dd5ffd1b..39a758fd 100644
--- a/mineru/kit/common.py
+++ b/mineru/kit/common.py
@@ -6,7 +6,7 @@ import json
import os
import zipfile
from pathlib import Path
-from typing import Literal
+from typing import Literal, TypeAlias
from ..parser.base import ParseResult
from ..render.writer import FileBasedDataWriter
@@ -15,7 +15,7 @@ from ..utils.image_payload import validate_image_sidecar_path
SupportedBundle = Literal["pipeline", "vlm", "all"]
KitFormat = Literal["markdown", "middle_json", "zip"]
-LocalTier = Literal["flash", "medium", "high", "extra_high"]
+LocalTier: TypeAlias = Tier
SUPPORTED_SUFFIXES = {
".pdf",
diff --git a/mineru/kit/main.py b/mineru/kit/main.py
index 51b3b8c3..56b72bd5 100644
--- a/mineru/kit/main.py
+++ b/mineru/kit/main.py
@@ -42,7 +42,7 @@ def parse_command(
pages: str | None = typer.Option(None, "-p", "--pages", help="Page range, e.g. '1~5' or 'all'"),
format: str = typer.Option("markdown", "-f", "--format", help="Output format: markdown, middle_json, zip"),
verbose: bool = typer.Option(False, "-v", "--verbose", help="Verbose output"),
- tier: str | None = typer.Option(None, "--tier", help="Parse tier: flash, medium, high, extra_high"),
+ tier: str | None = typer.Option(None, "--tier", help="Parse tier: flash, medium, high, xhigh"),
backend: str | None = typer.Option(None, "--backend", help="Expert backend override"),
remote: bool = typer.Option(False, "--remote", help="Use mineru.net official remote parse service"),
remote_url: str | None = typer.Option(None, "--remote-url", help="Use a custom remote parse service URL"),
@@ -83,7 +83,7 @@ def api_server_command(
tier: list[str] | None = typer.Option(
None,
"--tier",
- help="Server tier: flash, medium, high, extra_high; repeat to expose multiple tiers",
+ help="Server tier: flash, medium, high, xhigh; repeat to expose multiple tiers",
),
concurrency: int = typer.Option(1, "--concurrency", help="Maximum concurrent parse jobs"),
url_timeout: int = typer.Option(60, "--url-timeout", help="Timeout for URL source downloads"),
diff --git a/mineru/parser/__init__.py b/mineru/parser/__init__.py
index aeed9651..61c3fe46 100644
--- a/mineru/parser/__init__.py
+++ b/mineru/parser/__init__.py
@@ -3,6 +3,7 @@ from __future__ import annotations
from pathlib import Path
+from ..filetypes import ensure_tier_supported_for_parse_extension
from ..types import Tier
from .api_client import MinerUApiParser
from .base import MIDDLE_JSON_SCHEMA_VERSION, DocumentParser, ParseResult
@@ -64,12 +65,14 @@ def _build_parser(
) -> DocumentParser:
path = Path(path)
suffix = _resolve_input_suffix(path)
- runtime = resolve_runtime_options(tier=tier, backend=backend, effort=effort)
resolved_ocr_mode = method or ocr_mode
resolved_language = lang or language
resolved_image_analysis = (not disable_image_analysis) if image_analysis is None else image_analysis
if suffix in _OFFICE_SUFFIXES:
+ if tier is not None or backend is not None:
+ runtime = resolve_runtime_options(tier=tier, backend=backend, effort=effort)
+ ensure_tier_supported_for_parse_extension(runtime.tier, suffix)
parser_cls: type[DocumentParser] = {
"docx": DocxParser,
"pptx": PptxParser,
@@ -77,11 +80,15 @@ def _build_parser(
}[suffix]
return parser_cls()
elif suffix in _HTML_SUFFIXES:
+ if tier is not None or backend is not None:
+ runtime = resolve_runtime_options(tier=tier, backend=backend, effort=effort)
+ ensure_tier_supported_for_parse_extension(runtime.tier, suffix)
return HtmlParser()
if suffix not in _PDF_INPUT_SUFFIXES:
raise ValueError(f"Unsupported file type: {suffix or path.suffix or 'unknown'}")
+ runtime = resolve_runtime_options(tier=tier, backend=backend, effort=effort)
if runtime.backend.startswith("hybrid-"):
return PdfHybridParser(
backend=runtime.backend,
diff --git a/mineru/parser/api_client.py b/mineru/parser/api_client.py
index 77c008f0..da020fda 100644
--- a/mineru/parser/api_client.py
+++ b/mineru/parser/api_client.py
@@ -51,7 +51,7 @@ class MinerUApiParser(DocumentParser):
Constructor parameters:
- - ``tier`` → v1 ``tier`` (``"flash"`` / ``"medium"`` / ``"high"`` / ``"extra_high"``); ``None`` omits the field
+ - ``tier`` → v1 ``tier`` (``"flash"`` / ``"medium"`` / ``"high"`` / ``"xhigh"``); ``None`` omits the field
- ``page_range`` → per-file v1 ``page_range``
"""
diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.py
index adbccf49..cb885cd5 100644
--- a/mineru/parser/api_server.py
+++ b/mineru/parser/api_server.py
@@ -41,7 +41,8 @@ from pydantic import BaseModel, ConfigDict, Field
from starlette.datastructures import State
from ..render.writer import DataWriter
-from ..types import PageInfo, Tier, validate_tier
+from ..filetypes import batch_effective_parse_tier, is_flash_only_parse_extension
+from ..types import PageInfo, Tier, select_default_quality_tier, validate_tier
from ..utils.backend_options import DEFAULT_HYBRID_EFFORT
from ..utils.image_payload import validate_image_sidecar_path
from ..utils.ocr_language import PUBLIC_OCR_LANGUAGES, validate_public_ocr_lang
@@ -55,7 +56,7 @@ from .tier import (
runtime_options_for_tier,
)
-_API_SERVER_TIERS: tuple[Tier, ...] = ("flash", "medium", "high", "extra_high")
+_API_SERVER_TIERS: tuple[Tier, ...] = ("flash", "medium", "high", "xhigh")
_DEFAULT_API_SERVER_TIER: Tier = "high"
_API_SERVER_LANGUAGES = PUBLIC_OCR_LANGUAGES
_MANAGED_PARSE_SERVER_ENV = "MINERU_MANAGED_PARSE_SERVER"
@@ -1266,6 +1267,10 @@ def _source_name(source: FileSource, file_store: FileStore | None = None) -> str
return "unknown"
+def _job_has_only_flash_only_inputs(req: CreateJobRequest, file_store: FileStore) -> bool:
+ return all(is_flash_only_parse_extension(_source_name(entry.source, file_store)) for entry in req.files)
+
+
def _compact_page_numbers(page_numbers: list[int]) -> str:
if not page_numbers:
return ""
@@ -1391,14 +1396,18 @@ async def _run_job(
tmp_path.write_bytes(data)
page_range = entry.page_range or ""
+ effective_tier = batch_effective_parse_tier(rec.tier, fr.name)
+ effective_runtime = runtime_options_for_tier(effective_tier) if effective_tier != rec.tier else None
+ file_backend = effective_runtime.backend if effective_runtime is not None else server_backend
+ file_effort = effective_runtime.effort if effective_runtime is not None else effort
result = await parse_async(
str(tmp_path),
- tier=rec.tier,
- backend=server_backend,
+ tier=effective_tier,
+ backend=file_backend,
language=language,
ocr_mode=ocr_mode,
- effort=effort,
+ effort=file_effort,
disable_image_analysis=not image_analysis,
page_range=page_range,
)
@@ -1787,10 +1796,28 @@ async def create_job(
message=f"Unknown output format: {fmt}",
)
- # 按请求 tier 选择启动时预先解析好的 runtime,避免所有 job 共享默认 effort。
- body.tier = body.tier or request.app.state.default_tier
+ # 按请求 tier 选择启动时预先解析好的 runtime;全轻量输入可按 ADR-0024 直接归一到 flash 执行。
+ default_tier: Tier | None = request.app.state.default_tier
+ only_flash_only_inputs = _job_has_only_flash_only_inputs(body, file_store)
+ if body.tier is None and default_tier is None:
+ if only_flash_only_inputs:
+ body.tier = "flash"
+ else:
+ _raise_api_error(
+ 503,
+ error_type="engine_error",
+ code="quality_tier_unavailable",
+ message=(
+ "No medium, high, or xhigh tier available in this server. "
+ "Pass tier='flash' explicitly for flash parsing."
+ ),
+ )
+ else:
+ body.tier = body.tier or default_tier
runtime_options: dict[Tier, ParserRuntimeOptions] = request.app.state.tier_runtime_options
runtime = runtime_options.get(body.tier)
+ if runtime is None and only_flash_only_inputs:
+ runtime = runtime_options.get("flash") or runtime_options_for_tier("flash")
if runtime is None:
_raise_api_error(
400,
@@ -1926,7 +1953,7 @@ _OCR_MODES = ("auto", "txt", "ocr")
def _normalize_server_tiers(tier: Tier | list[Tier] | tuple[Tier, ...] | None) -> list[Tier]:
- """规范化 API server 启动 tier 列表,保留用户顺序并拒绝旧 standard/pro tier。"""
+ """规范化 API server 启动 tier 列表,保留用户顺序并拒绝非法 tier。"""
raw_tiers: list[Tier]
if tier is None:
raw_tiers = list(_API_SERVER_TIERS)
@@ -1964,10 +1991,10 @@ def _model_ids_and_tiers_for_server_tier(tier: Tier) -> tuple[list[str], list[Ti
"current_model": "hybrid-medium",
},
]
- if tier == "extra_high":
+ if tier == "xhigh":
return ["MinerU2.5-Pro-2604-1.2B", "MinerU-HTML"], [
{
- "id": "extra_high",
+ "id": "xhigh",
"description": "Hybrid maximum-accuracy parsing.",
"current_model": "MinerU2.5-Pro-2604-1.2B",
},
@@ -2040,7 +2067,7 @@ def create_app(
Directory for uploaded files and parse artifacts.
tier:
Server parsing tier. ``"flash"`` selects flash parsing; ``"medium"``,
- ``"high"`` and ``"extra_high"`` map to same-name Hybrid efforts.
+ ``"high"`` and ``"xhigh"`` map to Hybrid efforts.
concurrency:
Maximum concurrent parse jobs (default 1).
url_timeout:
@@ -2066,9 +2093,9 @@ def create_app(
server_tiers = _normalize_server_tiers(tier_input)
tier_runtime_options = _runtime_options_for_server_tiers(server_tiers)
server_tiers = list(tier_runtime_options)
- default_tier = _DEFAULT_API_SERVER_TIER if _DEFAULT_API_SERVER_TIER in tier_runtime_options else server_tiers[0]
- default_runtime = tier_runtime_options[default_tier]
- tier = default_tier
+ default_tier = select_default_quality_tier(tier_runtime_options)
+ default_runtime = tier_runtime_options[default_tier] if default_tier is not None else tier_runtime_options[server_tiers[0]]
+ tier = default_tier or server_tiers[0]
backend = default_runtime.backend
effort = default_runtime.effort
_preflight_runtime_dependencies(tier_runtime_options)
@@ -2212,7 +2239,7 @@ def create_app(
type=click.Choice(list(_API_SERVER_TIERS)),
help=(
"Server parsing tier; repeat to expose multiple tiers. "
- "Defaults to flash, medium, high, and extra_high; requests without tier default to high."
+ "Defaults to flash, medium, high, and xhigh; requests without tier default to high."
),
)
@click.option(
diff --git a/mineru/parser/pdf.py b/mineru/parser/pdf.py
index decb8bbb..8302272e 100644
--- a/mineru/parser/pdf.py
+++ b/mineru/parser/pdf.py
@@ -312,10 +312,10 @@ class PdfPipelineParser(PdfHybridParser):
class PdfVlmParser(PdfHybridParser):
- """保留旧 SDK 类名,内部统一委托 Hybrid extra_high 解析。"""
+ """保留旧 SDK 类名,内部统一委托 Hybrid xhigh 解析。"""
def __init__(self, **kwargs: Any) -> None:
- """将旧 PdfVlmParser 构造参数归一到 Hybrid extra_high,避免继续暴露独立 VLM backend。"""
+ """将旧 PdfVlmParser 构造参数归一到 Hybrid xhigh,避免继续暴露独立 VLM backend。"""
backend = kwargs.pop("backend", "vlm-engine")
kwargs.pop("effort", None)
resolved_backend, resolved_effort = resolve_backend_and_effort(backend, MAX_HYBRID_EFFORT)
diff --git a/mineru/parser/tier.py b/mineru/parser/tier.py
index 1bea33d7..d84ed48a 100644
--- a/mineru/parser/tier.py
+++ b/mineru/parser/tier.py
@@ -94,7 +94,7 @@ def backend_for_tier(tier: Tier) -> str:
"flash": "flash",
"medium": CANONICAL_HYBRID_ENGINE,
"high": CANONICAL_HYBRID_ENGINE,
- "extra_high": CANONICAL_HYBRID_ENGINE,
+ "xhigh": CANONICAL_HYBRID_ENGINE,
}
return mapping[tier]
@@ -105,7 +105,7 @@ def tier_for_backend(backend: str) -> Tier:
if raw_backend in LEGACY_PIPELINE_BACKEND_ALIASES:
return "medium"
if raw_backend in LEGACY_VLM_BACKEND_ALIASES:
- return "extra_high"
+ return "xhigh"
normalized_backend = normalize_backend(backend)
if normalized_backend == "flash":
return "flash"
@@ -129,11 +129,15 @@ def _backend_supports_tier(backend: str, tier: Tier) -> bool:
and raw_backend not in LEGACY_PIPELINE_BACKEND_ALIASES
and raw_backend not in LEGACY_VLM_BACKEND_ALIASES
)
- if tier == "extra_high":
+ if tier == "xhigh":
return is_hybrid_backend(normalized_backend) and raw_backend not in LEGACY_PIPELINE_BACKEND_ALIASES
return False
+def _tier_for_effort(effort: str) -> Tier:
+ return validate_tier(effort)
+
+
def resolve_tier_and_backend(tier: Tier | None = None, backend: str | None = None) -> tuple[Tier, str]:
"""将公开 tier 和本地专家 backend 解析为可执行 parser backend。"""
resolved_tier: Tier = validate_tier(tier) if tier is not None else "high"
@@ -185,7 +189,7 @@ def resolve_runtime_options(
explicit_tier=explicit_tier,
)
if not explicit_tier and resolved_backend != "flash":
- resolved_tier = validate_tier(resolved_effort)
+ resolved_tier = _tier_for_effort(resolved_effort)
return ParserRuntimeOptions(tier=resolved_tier, backend=resolved_backend, effort=resolved_effort)
@@ -203,7 +207,7 @@ def required_modules_for_tier(tier: Tier) -> list[str]:
tier = validate_tier(tier)
if tier == "medium":
return list(_STANDARD_REQUIRED_MODULES)
- if tier in {"high", "extra_high"}:
+ if tier in {"high", "xhigh"}:
return [
*_PRO_REQUIRED_MODULES_COMMON,
*_PRO_REQUIRED_MODULES_BY_PLATFORM.get(sys.platform, []),
diff --git a/mineru/types.py b/mineru/types.py
index f0df1be6..3947b1f4 100644
--- a/mineru/types.py
+++ b/mineru/types.py
@@ -1,6 +1,7 @@
# Copyright (c) Opendatalab. All rights reserved.
from __future__ import annotations
+from collections.abc import Iterable
from dataclasses import MISSING, Field, InitVar, dataclass, field, fields
from typing import Any, Iterator, Literal, TypeAlias, TypeVar, get_type_hints
@@ -11,32 +12,60 @@ Tier = Literal[
"flash",
"medium",
"high",
- "extra_high",
+ "xhigh",
]
TIERS: set[Tier] = {
"flash",
"medium",
"high",
- "extra_high",
+ "xhigh",
}
TIER_ORDER: dict[Tier, int] = {
"flash": 0,
"medium": 1,
"high": 2,
- "extra_high": 3,
+ "xhigh": 3,
}
+QUALITY_TIER_SELECTION_ORDER: tuple[Tier, ...] = ("high", "xhigh", "medium")
+QUALITY_TIERS: frozenset[Tier] = frozenset(QUALITY_TIER_SELECTION_ORDER)
+CACHED_TIER_SELECTION_ORDER: tuple[Tier, ...] = ("xhigh", "high", "medium", "flash")
+
def validate_tier(tier: str | None) -> Tier:
- """校验公开 tier 取值,保证入口只接受 flash/medium/high/extra_high。"""
+ """校验公开 tier 取值,保证入口只接受 flash/medium/high/xhigh。"""
normalized = (tier or "").strip().lower()
if normalized in TIERS:
return normalized # type: ignore[return-value]
raise ValueError(f"Unsupported tier '{tier}'. Supported tiers: {', '.join(TIERS)}")
+def _validated_tier_set(available_tiers: Iterable[object] | str) -> set[Tier]:
+ if isinstance(available_tiers, str):
+ return {validate_tier(available_tiers)}
+ return {validate_tier(str(item)) for item in available_tiers}
+
+
+def select_default_quality_tier(available_tiers: Iterable[object] | str) -> Tier | None:
+ """Select the default quality tier from discovered parse-server capabilities."""
+ available = _validated_tier_set(available_tiers)
+ for candidate in QUALITY_TIER_SELECTION_ORDER:
+ if candidate in available:
+ return candidate
+ return None
+
+
+def select_highest_cached_tier(available_tiers: Iterable[object] | str) -> Tier | None:
+ """Select the highest already-cached tier without creating a new parse."""
+ available = _validated_tier_set(available_tiers)
+ for candidate in CACHED_TIER_SELECTION_ORDER:
+ if candidate in available:
+ return candidate
+ return None
+
+
class BlockType:
IMAGE = "image"
IMAGE_BODY = "image_body"
diff --git a/mineru/utils/backend_options.py b/mineru/utils/backend_options.py
index d7213768..14dd15f3 100644
--- a/mineru/utils/backend_options.py
+++ b/mineru/utils/backend_options.py
@@ -6,7 +6,7 @@ from typing import Final
CANONICAL_HYBRID_ENGINE: Final = "hybrid-engine"
LOCAL_HYBRID_EFFORT: Final = "medium"
LAYOUT_HYBRID_EFFORT: Final = "high"
-MAX_HYBRID_EFFORT: Final = "extra_high"
+MAX_HYBRID_EFFORT: Final = "xhigh"
DEFAULT_BACKEND: Final = CANONICAL_HYBRID_ENGINE
DEFAULT_HYBRID_EFFORT: Final = LAYOUT_HYBRID_EFFORT
DEFAULT_EFFORT: Final = DEFAULT_HYBRID_EFFORT
@@ -29,7 +29,7 @@ HYBRID_EFFORT_CHOICES: Final[tuple[str, ...]] = (
HYBRID_EFFORT_BY_TIER: Final[dict[str, str]] = {
LOCAL_HYBRID_EFFORT: LOCAL_HYBRID_EFFORT,
LAYOUT_HYBRID_EFFORT: LAYOUT_HYBRID_EFFORT,
- MAX_HYBRID_EFFORT: MAX_HYBRID_EFFORT,
+ "xhigh": MAX_HYBRID_EFFORT,
}
BACKEND_SCHEMA_EXTRA: Final[dict[str, list[str]]] = {"enum": list(PUBLIC_BACKEND_CHOICES)}
HYBRID_EFFORT_SCHEMA_EXTRA: Final[dict[str, list[str]]] = {"enum": list(HYBRID_EFFORT_CHOICES)}
@@ -76,7 +76,7 @@ def normalize_public_backend(backend: str | None) -> str:
def validate_effort(effort: str | None) -> str:
- """校验 Hybrid effort 级别,只允许 medium/high/extra_high 三档。"""
+ """校验 Hybrid effort 级别,只允许 medium/high/xhigh 三档。"""
normalized = (effort or DEFAULT_EFFORT).strip().lower()
if normalized in HYBRID_EFFORT_CHOICES:
return normalized
@@ -93,7 +93,7 @@ def effort_for_tier(tier: str | None) -> str:
def resolve_backend_and_effort(backend: str | None, effort: str | None = None) -> tuple[str, str]:
- """同时解析 backend 与 effort,旧 pipeline/VLM backend 分别统一转为 Hybrid medium/extra_high。"""
+ """同时解析 backend 与 effort,旧 pipeline/VLM backend 分别统一转为 Hybrid medium/xhigh。"""
raw_backend = (backend or "").strip()
resolved_backend = normalize_backend(raw_backend)
resolved_effort = validate_effort(effort)
diff --git a/pyproject.toml b/pyproject.toml
index 91d2c7d9..cbb9f70d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -76,14 +76,14 @@ dev = [
"lxml-stubs",
]
test = [
- "mineru[core]",
+ "mineru[xhigh]",
"pytest",
"pytest-cov",
"coverage",
"fuzzywuzzy",
"tomli; python_version < '3.11'",
]
-standard = [
+medium = [
"ftfy>=6.3.1,<7",
"shapely>=2.0.7,<3",
"pyclipper>=1.3.0,<2",
@@ -91,12 +91,10 @@ standard = [
"torch>=2.6.0,<3",
"torchvision",
"transformers>=4.57.3,<5.0.0",
+ "safetensors>=0.4.0,<1",
]
-medium = [
- "mineru[standard]",
-]
-pro = [
- "mineru[standard]",
+high = [
+ "mineru[medium]",
"accelerate>=1.5.1",
"vllm>=0.10.1.1,<0.22.0 ; sys_platform == 'linux'",
"lmdeploy>=0.10.2,<0.12 ; sys_platform == 'win32'",
@@ -104,11 +102,8 @@ pro = [
"mlx<=0.31.1 ; sys_platform == 'darwin'",
"mlx-vlm>=0.3.3,<0.4 ; sys_platform == 'darwin'",
]
-high = [
- "mineru[pro]",
-]
-extra_high = [
- "mineru[pro]",
+xhigh = [
+ "mineru[high]",
]
vlm = [
@@ -127,26 +122,12 @@ mlx = [
"mlx-vlm>=0.3.3,<0.4",
"mlx<=0.31.1",
]
-pipeline = [
- "ftfy>=6.3.1,<7",
- "shapely>=2.0.7,<3",
- "pyclipper>=1.3.0,<2",
- "torch>=2.6.0,<3",
- "torchvision",
- "transformers>=4.57.3,<5.0.0",
- "safetensors>=0.4.0,<1",
-]
gradio = [
"gradio>=5.49.1,!=6.0.0,!=6.0.1,!=6.0.2,!=6.1.0,!=6.2.0,!=6.3.0,!=6.4.0,!=6.5.0,!=6.5.1,!=6.6.0,!=6.7.0,<6.9.0",
"gradio-pdf>=0.0.22",
]
-core = [
- "mineru[vlm]",
- "mineru[pipeline]",
- "mineru[gradio]",
-]
all = [
- "mineru[core]",
+ "mineru[gradio]",
"mineru[mlx] ; sys_platform == 'darwin'",
"mineru[vllm] ; sys_platform == 'linux'",
"mineru[lmdeploy] ; sys_platform == 'win32'",
diff --git a/tests/unittest/test_cli_next_command_design.py b/tests/unittest/test_cli_next_command_design.py
index 80b47597..089d0b37 100644
--- a/tests/unittest/test_cli_next_command_design.py
+++ b/tests/unittest/test_cli_next_command_design.py
@@ -714,7 +714,7 @@ def test_parse_wait_json_maps_invalid_api_key_param(monkeypatch: Any, tmp_path:
id=3,
sha256="a" * 64,
short_id="aaaaaaa",
- tier="pro",
+ tier="high",
page_range="1~1",
status="failed",
privacy="remote",
@@ -731,7 +731,7 @@ def test_parse_wait_json_maps_invalid_api_key_param(monkeypatch: Any, tmp_path:
def ensure_parse(self, request: Any) -> ParseResponse:
return ParseResponse(
sha256="a" * 64,
- tier="pro",
+ tier="high",
page_range="1~1",
status="pending",
wait_parse_ids=[3],
diff --git a/tests/unittest/test_doclib_app_startup.py b/tests/unittest/test_doclib_app_startup.py
index 63e80eab..bc708daf 100644
--- a/tests/unittest/test_doclib_app_startup.py
+++ b/tests/unittest/test_doclib_app_startup.py
@@ -54,20 +54,11 @@ def test_doclib_runtime_dependencies_are_in_base_install() -> None:
assert "watchfiles" in dependency_names
-def test_pdftext_dependency_is_capped_below_pagechars_api() -> None:
+def test_medium_extra_includes_preflight_runtime_dependencies() -> None:
pyproject_path = Path(__file__).resolve().parents[2] / "pyproject.toml"
pyproject = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
- dependencies = pyproject["project"]["dependencies"]
- pdftext_dependencies = [dependency for dependency in dependencies if dependency.lower().startswith("pdftext")]
-
- assert pdftext_dependencies == ["pdftext>=0.6.3,<0.7.0"]
-
-
-def test_standard_extra_includes_preflight_runtime_dependencies() -> None:
- pyproject_path = Path(__file__).resolve().parents[2] / "pyproject.toml"
- pyproject = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
- standard_dependencies = pyproject["project"]["optional-dependencies"]["standard"]
- dependency_names = {dependency.split(">", 1)[0].split("=", 1)[0].lower() for dependency in standard_dependencies}
+ medium_dependencies = pyproject["project"]["optional-dependencies"]["medium"]
+ dependency_names = {dependency.split(">", 1)[0].split("=", 1)[0].lower() for dependency in medium_dependencies}
module_to_distribution = {
"ftfy": "ftfy",
"pyclipper": "pyclipper",
@@ -80,7 +71,7 @@ def test_standard_extra_includes_preflight_runtime_dependencies() -> None:
missing = [
module_name
- for module_name in parser_tier.required_modules_for_tier("standard")
+ for module_name in parser_tier.required_modules_for_tier("medium")
if module_to_distribution[module_name] not in dependency_names
]
@@ -157,7 +148,7 @@ def test_config_set_managed_tier_preflights_even_when_mode_is_disabled(monkeypat
cfg = PatchedConfig(doclib={"data_dir": str(tmp_path), "sqlite": {"path": str(tmp_path / "doclib.db")}})
with TestClient(doclib_app.create_app(cfg)) as client:
- response = client.put("/api/v1/configs/parse_server.local.managed_tier", json={"value": "extra_high"})
+ response = client.put("/api/v1/configs/parse_server.local.managed_tier", json={"value": "xhigh"})
config_response = client.get("/api/v1/configs/parse_server.local.managed_tier")
assert response.status_code == 400
@@ -165,7 +156,7 @@ def test_config_set_managed_tier_preflights_even_when_mode_is_disabled(monkeypat
assert payload["error"]["code"] == "parse_server_dependency_missing"
assert payload["error"]["param"] == "parse_server.local.managed_tier"
assert "mlx" in payload["error"]["message"]
- assert "pip install 'mineru-next-dev[extra_high]'" in payload["error"]["message"]
+ assert "pip install 'mineru-next-dev[xhigh]'" in payload["error"]["message"]
assert config_response.json()["value"] == "high"
@@ -489,9 +480,7 @@ def test_managed_parse_server_startup_clears_invalid_tier_override(monkeypatch,
db = DatabaseManager(str(tmp_path / "doclib.db"))
asyncio.run(db.initialize())
asyncio.run(db.execute("INSERT INTO config (key, value) VALUES (?, ?)", ("parse_server.local.mode", "managed")))
- asyncio.run(
- db.execute("INSERT INTO config (key, value) VALUES (?, ?)", ("parse_server.local.managed_tier", "standard"))
- )
+ asyncio.run(db.execute("INSERT INTO config (key, value) VALUES (?, ?)", ("parse_server.local.managed_tier", "ultra")))
class _Proc:
pid = 12345
diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.py
index 1382dcbf..8cdf1b85 100644
--- a/tests/unittest/test_doclib_cache_semantics.py
+++ b/tests/unittest/test_doclib_cache_semantics.py
@@ -31,7 +31,7 @@ from mineru.doclib.core.db import DatabaseManager
from mineru.doclib.core.file_io import FileStat, get_file_stat
from mineru.doclib.core.fts import FTSManager
from mineru.doclib.locators import ContentCursor
-from mineru.doclib.server import DoclibServer, _ReadPlan
+from mineru.doclib.server import DoclibServer, _LocatorParts, _ReadPlan, _locator_after
from mineru.doclib.services import parse_svc as parse_svc_module
from mineru.doclib.services.cleanup_svc import CleanupService
from mineru.doclib.services.config_svc import ConfigService
@@ -41,6 +41,7 @@ from mineru.doclib.services.parse_svc import (
ParseService,
_local_parse_server_url,
_resolve_default_tier,
+ _resolve_parsing_rule_default_tier,
expand_page_range,
filter_pages_by_user_range,
load_pages_from_done_batches,
@@ -282,9 +283,9 @@ def test_parser_tier_backend_mapping_is_parser_layer_only() -> None:
assert backend_for_tier("flash") == "flash"
assert backend_for_tier("medium") == "hybrid-engine"
assert backend_for_tier("high") == "hybrid-engine"
- assert backend_for_tier("extra_high") == "hybrid-engine"
+ assert backend_for_tier("xhigh") == "hybrid-engine"
assert resolve_tier_and_backend(tier=None) == ("high", "hybrid-engine")
- assert resolve_tier_and_backend(tier="extra_high", backend="vlm-auto-engine") == ("extra_high", "hybrid-engine")
+ assert resolve_tier_and_backend(tier="xhigh", backend="vlm-auto-engine") == ("xhigh", "hybrid-engine")
def test_managed_api_server_args_use_tier_and_selected_port_for_process_start() -> None:
@@ -297,9 +298,9 @@ def test_managed_api_server_args_use_tier_and_selected_port_for_process_start()
"16580",
"--allow-local-source",
]
- assert api_server_args_for_tier("extra_high", host="127.0.0.2", port=16581) == [
+ assert api_server_args_for_tier("xhigh", host="127.0.0.2", port=16581) == [
"--tier",
- "extra_high",
+ "xhigh",
"--host",
"127.0.0.2",
"--port",
@@ -346,7 +347,7 @@ def test_default_tier_error_mentions_remote_when_remote_is_healthy(monkeypatch:
local_healthy=False,
local_supported_tiers=["flash"],
remote_healthy=True,
- remote_supported_tiers=["high", "extra_high"],
+ remote_supported_tiers=["high", "xhigh"],
)
monkeypatch.setattr("mineru.doclib.background.parse_server_health.get_health", lambda: health)
@@ -377,6 +378,31 @@ def test_default_tier_error_omits_remote_when_remote_is_unhealthy(monkeypatch: p
assert "--tier flash" in exc_info.value.message
+def test_parsing_rule_default_tier_allows_flash_fallback(monkeypatch: pytest.MonkeyPatch) -> None:
+ health = ParseServerHealth(local_supported_tiers=["medium", "xhigh"])
+ monkeypatch.setattr("mineru.doclib.background.parse_server_health.get_health", lambda: health)
+
+ assert _resolve_parsing_rule_default_tier() == "xhigh"
+
+ health.local_supported_tiers = ["medium", "high", "xhigh"]
+ assert _resolve_parsing_rule_default_tier() == "high"
+
+ health.local_supported_tiers = ["flash"]
+ assert _resolve_parsing_rule_default_tier() == "flash"
+
+
+def test_read_without_tier_uses_highest_cached_tier() -> None:
+ class _DB:
+ async def fetchall(self, sql: str, params: tuple[Any, ...]) -> list[dict[str, str]]:
+ assert sql == "SELECT tier FROM parses WHERE sha256=? AND status=? GROUP BY tier"
+ assert params == ("a" * 64, "done")
+ return [{"tier": "flash"}, {"tier": "medium"}, {"tier": "high"}, {"tier": "xhigh"}]
+
+ server = DoclibServer(SimpleNamespace(db=_DB()))
+
+ assert asyncio.run(server._default_read_tier("a" * 64)) == "xhigh"
+
+
def test_managed_local_parse_server_url_uses_health_managed_url() -> None:
health = ParseServerHealth(managed_url="http://127.0.0.1:16582")
@@ -560,7 +586,7 @@ def test_managed_parse_server_restart_clears_invalid_tier_override(monkeypatch:
class _ConfigSvc:
def __init__(self) -> None:
- self.value = "pro"
+ self.value = "ultra"
self.unset_keys: list[str] = []
async def get(self, key: str) -> str:
@@ -689,12 +715,12 @@ def test_managed_parse_server_tier_change_detection_triggers_restart(monkeypatch
monkeypatch.setattr(checker, "_try_restart_managed", _restart)
health = ParseServerHealth(running_managed_tier="high")
- restarted = asyncio.run(checker._try_restart_managed_for_tier_change(health, "extra_high"))
+ restarted = asyncio.run(checker._try_restart_managed_for_tier_change(health, "xhigh"))
unchanged = asyncio.run(checker._try_restart_managed_for_tier_change(health, "high"))
assert restarted is True
assert unchanged is False
- assert calls == [("tier-change", "tier change high->extra_high", False)]
+ assert calls == [("tier-change", "tier change high->xhigh", False)]
def test_managed_parse_server_tier_change_restart_uses_desired_tier(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -704,7 +730,7 @@ def test_managed_parse_server_tier_change_restart_uses_desired_tier(monkeypatch:
class _ConfigSvc:
async def get(self, key: str) -> str:
assert key == "parse_server.local.managed_tier"
- return "extra_high"
+ return "xhigh"
class _Proc:
pid = 24680
@@ -716,10 +742,10 @@ def test_managed_parse_server_tier_change_restart_uses_desired_tier(monkeypatch:
events.append("stop")
def _start(*, tier: Tier, managed_cfg: ManagedParseServerConfig, log_cfg: LogConfig | None, marker: str) -> tuple[_Proc, str]:
- assert tier == "extra_high"
+ assert tier == "xhigh"
assert managed_cfg.host == "127.0.0.2"
assert log_cfg is None
- assert marker == "tier change high->extra_high"
+ assert marker == "tier change high->xhigh"
events.append("start")
return _Proc(), "http://127.0.0.2:16582"
@@ -740,14 +766,14 @@ def test_managed_parse_server_tier_change_restart_uses_desired_tier(monkeypatch:
checker._try_restart_managed(
health,
reason="tier-change",
- marker="tier change high->extra_high",
+ marker="tier change high->xhigh",
count_restart=False,
)
)
assert events == ["stop", "start"]
assert health.managed_proc.pid == 24680
- assert health.running_managed_tier == "extra_high"
+ assert health.running_managed_tier == "xhigh"
assert health.restart_count == 2
@@ -856,7 +882,7 @@ def test_remote_api_target_prefers_config_api_key_over_env(monkeypatch: pytest.M
parse_lock_timeout_sec=1800,
)
- base_url, api_key, via = await service._resolve_api_target("remote", "pro")
+ base_url, api_key, via = await service._resolve_api_target("remote", "high")
assert base_url == "https://mineru.net/api"
assert api_key == "config-key"
@@ -1059,7 +1085,7 @@ def test_request_parse_explicit_image_ingests_and_queues_parse(tmp_path: Path, m
@pytest.mark.parametrize("ext", ["txt", "html", "docx", "pptx", "xlsx"])
[email protected]("tier", ["high", "extra_high"])
[email protected]("tier", ["high", "xhigh"])
def test_request_parse_rejects_quality_tiers_for_non_pdf_image_inputs(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
@@ -1106,6 +1132,58 @@ def test_request_parse_rejects_quality_tiers_for_non_pdf_image_inputs(
asyncio.run(_run())
+ ("ext", "expected_tier", "expected_privacy"),
+ [
+ ("pdf", "high", "remote"),
+ ("html", "flash", "local"),
+ ],
+)
+def test_refresh_file_applies_parsing_rule_effective_tier_and_privacy(
+ tmp_path: Path,
+ monkeypatch: pytest.MonkeyPatch,
+ ext: str,
+ expected_tier: Tier,
+ expected_privacy: str,
+) -> None:
+ class _RuleConfig:
+ async def match_rules(self, path: str, rule_type: str) -> list[dict[str, Any]]:
+ return [{"tier": "high", "page_range": "1", "remote": True}]
+
+ async def _run() -> None:
+ db = DatabaseManager(str(tmp_path / "doclib.db"))
+ await db.initialize()
+ service = ParseService(
+ db=db,
+ fts=FTSManager(db),
+ config_svc=_RuleConfig(),
+ data_dir=str(tmp_path / "data"),
+ parse_lock_timeout_sec=1800,
+ )
+ source = tmp_path / f"sample.{ext}"
+ source.write_text("%PDF-1.7\n" if ext == "pdf" else "<p>content</p>", encoding="utf-8")
+
+ async def _metadata(path: str) -> dict[str, Any]:
+ return {
+ "page_count": 1,
+ "title": None,
+ "author": None,
+ "subject": None,
+ "keywords": None,
+ "is_image_based": 0,
+ }
+
+ monkeypatch.setattr(parse_svc_module, "extract_metadata", _metadata)
+
+ refreshed = await service.refresh_file(str(source), ensure_ingested=True)
+ assert refreshed.file is not None
+ parse_rows = await db.fetchall("SELECT tier, privacy, page_range FROM parses")
+
+ assert parse_rows == [{"tier": expected_tier, "privacy": expected_privacy, "page_range": "1"}]
+
+ asyncio.run(_run())
+
+
@pytest.mark.parametrize("ext", ["txt", "html", "docx", "pptx", "xlsx"])
def test_request_parse_rejects_remote_for_non_pdf_image_inputs(
tmp_path: Path,
@@ -1822,8 +1900,8 @@ def test_search_filters_by_tier_min_tier_and_file_type(tmp_path: Path) -> None:
now = 1000
docs = [
("1" * 64, "flash", "pdf", "flash.pdf", 2),
- ("2" * 64, "high", "pdf", "standard.pdf", 12),
- ("3" * 64, "extra_high", "docx", "pro.docx", 23),
+ ("2" * 64, "high", "pdf", "high.pdf", 12),
+ ("3" * 64, "xhigh", "docx", "xhigh.docx", 23),
]
for sha256, tier, file_type, filename, page_count in docs:
@@ -1848,9 +1926,9 @@ def test_search_filters_by_tier_min_tier_and_file_type(tmp_path: Path) -> None:
assert [row["short_id"] for row in exact_results] == ["2" * 7]
assert [row["page_count"] for row in exact_results] == [12]
assert min_total == 2
- assert {row["tier"] for row in min_results} == {"high", "extra_high"}
+ assert {row["tier"] for row in min_results} == {"high", "xhigh"}
assert type_total == 1
- assert [row["filename"] for row in type_results] == ["pro.docx"]
+ assert [row["filename"] for row in type_results] == ["xhigh.docx"]
assert [row["short_id"] for row in type_results] == ["3" * 7]
assert [row["page_count"] for row in type_results] == [23]
@@ -3507,7 +3585,7 @@ def test_process_doc_preserves_remote_api_error_code(tmp_path: Path) -> None:
task = {
"id": 1,
"sha256": sha256,
- "tier": "pro",
+ "tier": "high",
"page_range": "1",
"status": "parsing",
"privacy": "remote",
@@ -3742,6 +3820,12 @@ def test_load_pages_from_done_batches_keeps_existing_image_sidecar(tmp_path: Pat
assert sidecar.read_bytes() == b"existing-sidecar"
+def test_locator_after_uses_resolved_tier_when_locator_tier_is_absent() -> None:
+ locator = _LocatorParts(short_id="eeeeeee", tier=None, page_no=1, block_no=2, char_offset=8)
+
+ assert _locator_after(locator, "xhigh") == "doc:eeeeeee/tier:xhigh/page:1/block:2/char:8"
+
+
def test_progressive_markdown_uses_public_image_sidecar_prefix(tmp_path: Path) -> None:
sha256 = "e" * 64
tier = "high"
@@ -3870,7 +3954,7 @@ def test_doclib_office_image_asset_transcodes_to_requested_format(tmp_path: Path
def test_doclib_office_image_asset_missing_sidecar_reports_asset_not_available(tmp_path: Path) -> None:
sha256 = "f" * 64
- tier = "standard"
+ tier = "medium"
image_path = "figures/missing.png"
image_span = Span(type=ContentType.IMAGE, bbox=(1, 1, 20, 20), image_path=image_path)
body = Block(
@@ -3888,7 +3972,7 @@ def test_doclib_office_image_asset_missing_sidecar_reports_asset_not_available(t
tier=tier,
page_range=None,
after=None,
- locator="doc:fffffff/tier:standard/page:1/block:1",
+ locator="doc:fffffff/tier:medium/page:1/block:1",
context=0,
limit=30000,
format="image",
diff --git a/tests/unittest/test_kit_commands.py b/tests/unittest/test_kit_commands.py
index c7a5be48..c46fe02f 100644
--- a/tests/unittest/test_kit_commands.py
+++ b/tests/unittest/test_kit_commands.py
@@ -373,14 +373,14 @@ def test_api_server_forwards_repeated_tiers(monkeypatch: Any) -> None:
monkeypatch.setattr(api_server.parser_api_server.main, "main", _fake_main)
- result = runner.invoke(app, ["api-server", "--tier", "medium", "--tier", "extra_high"])
+ result = runner.invoke(app, ["api-server", "--tier", "medium", "--tier", "xhigh"])
assert result.exit_code == 0
assert seen["prog_name"] == "mineru-kit api-server"
assert seen["standalone_mode"] is False
assert [seen["args"][index + 1] for index, item in enumerate(seen["args"]) if item == "--tier"] == [
"medium",
- "extra_high",
+ "xhigh",
]
@@ -782,6 +782,59 @@ def test_parse_forwards_backend_alias_and_effort(monkeypatch: Any, tmp_path: Pat
assert seen["effort"] == "high"
+def test_parse_rejects_single_office_input_with_quality_tier(monkeypatch: Any, tmp_path: Path) -> None:
+ source = tmp_path / "demo.docx"
+ output = tmp_path / "out.md"
+ source.write_bytes(b"docx")
+
+ def _fake_local_parse(*args: Any, **kwargs: Any) -> ParseResult:
+ pytest.fail("single lightweight input with quality tier should fail before parsing")
+
+ monkeypatch.setattr(parse, "local_parse", _fake_local_parse)
+
+ result = runner.invoke(app, ["parse", str(source), "-o", str(output), "--tier", "high"])
+
+ assert result.exit_code == 1
+ assert "Tier 'high' is only supported for PDF and image files" in " ".join(result.output.split())
+
+
+def test_parse_batch_normalizes_office_quality_tier_to_flash(monkeypatch: Any, tmp_path: Path) -> None:
+ pdf = tmp_path / "demo.pdf"
+ html = tmp_path / "page.html"
+ output = tmp_path / "out"
+ pdf.write_bytes(b"%PDF-1.7\n")
+ html.write_text("<p>content</p>", encoding="utf-8")
+ calls: list[dict[str, Any]] = []
+
+ class _Result:
+ def markdown(self) -> str:
+ return "# demo\n"
+
+ def images(self) -> dict[str, bytes]:
+ return {}
+
+ def to_json(self) -> str:
+ return '{"pages":[]}'
+
+ def save(self, writer: Any) -> None:
+ writer.write_string("markdown.md", self.markdown())
+ writer.write_string("middle_json.json", self.to_json())
+
+ def _fake_local_parse(path: Path, **kwargs: Any) -> _Result:
+ calls.append({"path": path, **kwargs})
+ return _Result()
+
+ monkeypatch.setattr(parse, "local_parse", _fake_local_parse)
+
+ result = runner.invoke(app, ["parse", str(pdf), str(html), "-o", str(output), "--tier", "high"])
+
+ assert result.exit_code == 0
+ assert [(call["path"].name, call["tier"], call["backend"]) for call in calls] == [
+ ("demo.pdf", "high", "hybrid-engine"),
+ ("page.html", "flash", "flash"),
+ ]
+
+
def test_parse_remote_requests_image_cache(monkeypatch: Any, tmp_path: Path) -> None:
source = tmp_path / "demo.pdf"
output = tmp_path / "out.md"
@@ -906,10 +959,10 @@ def test_gradio_tier_selection_derives_v1_runtime() -> None:
"backend": "hybrid-engine",
"effort": "high",
}
- assert gradio_app.resolve_gradio_runtime_options("extra_high").as_kwargs() == {
- "tier": "extra_high",
+ assert gradio_app.resolve_gradio_runtime_options("xhigh").as_kwargs() == {
+ "tier": "xhigh",
"backend": "hybrid-engine",
- "effort": "extra_high",
+ "effort": "xhigh",
}
@@ -919,16 +972,16 @@ def test_gradio_extracts_supported_tiers_from_v1_tiers_payload() -> None:
payload = {
"data": [
{"id": "flash"},
- {"id": "extra_high"},
+ {"id": "xhigh"},
{"id": "experimental"},
{"id": "medium"},
{"id": "high"},
- {"id": "extra_high"},
+ {"id": "xhigh"},
]
}
- assert gradio_app.extract_v1_tier_choices(payload) == ("flash", "extra_high", "medium", "high")
- assert gradio_app.default_v1_gradio_tier(("flash", "extra_high", "medium", "high")) == "high"
+ assert gradio_app.extract_v1_tier_choices(payload) == ("flash", "xhigh", "medium", "high")
+ assert gradio_app.default_v1_gradio_tier(("flash", "xhigh", "medium", "high")) == "high"
def test_gradio_rejects_v1_tiers_payload_without_supported_tiers() -> None:
@@ -1289,7 +1342,7 @@ def test_parse_forwards_flash_backend(monkeypatch: Any, tmp_path: Path) -> None:
assert output.read_text(encoding="utf-8") == "# demo\n"
-def test_cli_old_legacy_vlm_branch_maps_to_hybrid_extra_high(monkeypatch: Any, tmp_path: Path) -> None:
+def test_cli_old_legacy_vlm_branch_maps_to_hybrid_xhigh(monkeypatch: Any, tmp_path: Path) -> None:
from mineru.cli_old import common
seen: dict[str, Any] = {}
@@ -1306,7 +1359,7 @@ def test_cli_old_legacy_vlm_branch_maps_to_hybrid_extra_high(monkeypatch: Any, t
monkeypatch.setattr(common, "get_vlm_engine", lambda inference_engine="auto", is_async=False: "vllm-engine")
def _fake_process_hybrid(*args: Any, **kwargs: Any) -> None:
- """记录 legacy VLM 输入最终进入 Hybrid extra_high 分支。"""
+ """记录 legacy VLM 输入最终进入 Hybrid xhigh 分支。"""
seen["backend"] = args[3]
seen["hybrid_backend"] = args[5]
seen["kwargs"] = kwargs
@@ -1323,7 +1376,7 @@ def test_cli_old_legacy_vlm_branch_maps_to_hybrid_extra_high(monkeypatch: Any, t
)
assert seen["hybrid_backend"] == "vllm-engine"
- assert seen["kwargs"]["effort"] == "extra_high"
+ assert seen["kwargs"]["effort"] == "xhigh"
assert seen["kwargs"]["image_analysis"] is True
assert not hasattr(common, "_process_vlm")
@@ -1466,7 +1519,7 @@ def test_process_hybrid_medium_calls_analyzer_per_file(monkeypatch: Any, tmp_pat
assert [item[0] for item in outputs] == ["a.pdf", "b.pdf"]
-def test_cli_old_async_legacy_vlm_branch_maps_to_hybrid_extra_high(monkeypatch: Any, tmp_path: Path) -> None:
+def test_cli_old_async_legacy_vlm_branch_maps_to_hybrid_xhigh(monkeypatch: Any, tmp_path: Path) -> None:
from mineru.cli_old import common
seen: dict[str, Any] = {}
@@ -1483,7 +1536,7 @@ def test_cli_old_async_legacy_vlm_branch_maps_to_hybrid_extra_high(monkeypatch:
monkeypatch.setattr(common, "get_vlm_engine", lambda inference_engine="auto", is_async=True: "vllm-async-engine")
async def _fake_async_process_hybrid(*args: Any, **kwargs: Any) -> None:
- """记录异步 legacy VLM 输入最终进入 Hybrid extra_high 分支。"""
+ """记录异步 legacy VLM 输入最终进入 Hybrid xhigh 分支。"""
seen["backend"] = args[3]
seen["hybrid_backend"] = args[5]
seen["kwargs"] = kwargs
@@ -1502,7 +1555,7 @@ def test_cli_old_async_legacy_vlm_branch_maps_to_hybrid_extra_high(monkeypatch:
)
assert seen["hybrid_backend"] == "vllm-async-engine"
- assert seen["kwargs"]["effort"] == "extra_high"
+ assert seen["kwargs"]["effort"] == "xhigh"
assert seen["kwargs"]["image_analysis"] is True
assert not hasattr(common, "_async_process_vlm")
diff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.py
index 8a459a03..0b458796 100644
--- a/tests/unittest/test_parser_api_contract.py
+++ b/tests/unittest/test_parser_api_contract.py
@@ -38,7 +38,7 @@ from mineru.parser.api_server import (
main,
)
from mineru.parser.base import ParseResult
-from mineru.types import Block, Line, PageInfo, Span
+from mineru.types import Block, Line, PageInfo, Span, TIERS, validate_tier
from mineru.utils.image_payload import ImagePayloadCache
runner = CliRunner()
@@ -127,7 +127,7 @@ print("ok")
def test_validate_effort_rejects_low_and_maps_legacy_backends() -> None:
- """校验 Hybrid effort 只接受 medium/high/extra_high 三档。"""
+ """校验 Hybrid effort 只接受 medium/high/xhigh 三档。"""
from mineru.utils.backend_options import (
HYBRID_EFFORT_CHOICES,
effort_for_tier,
@@ -135,16 +135,16 @@ def test_validate_effort_rejects_low_and_maps_legacy_backends() -> None:
validate_effort,
)
- assert HYBRID_EFFORT_CHOICES == ("medium", "high", "extra_high")
+ assert HYBRID_EFFORT_CHOICES == ("medium", "high", "xhigh")
assert effort_for_tier("medium") == "medium"
assert effort_for_tier("high") == "high"
- assert effort_for_tier("extra_high") == "extra_high"
+ assert effort_for_tier("xhigh") == "xhigh"
with pytest.raises(ValueError, match="Unsupported effort 'low'"):
validate_effort("low")
- with pytest.raises(ValueError, match="Unsupported tier 'standard'"):
- effort_for_tier("standard")
- assert resolve_backend_and_effort("vlm-engine", "medium") == ("hybrid-engine", "extra_high")
- assert resolve_backend_and_effort("pipeline", "extra_high") == ("hybrid-engine", "medium")
+ with pytest.raises(ValueError, match="Unsupported tier 'ultra'"):
+ effort_for_tier("ultra")
+ assert resolve_backend_and_effort("vlm-engine", "medium") == ("hybrid-engine", "xhigh")
+ assert resolve_backend_and_effort("pipeline", "xhigh") == ("hybrid-engine", "medium")
def test_tier_runtime_options_map_hybrid_effort() -> None:
@@ -166,13 +166,20 @@ def test_tier_runtime_options_map_hybrid_effort() -> None:
"backend": "hybrid-engine",
"effort": "high",
}
- assert runtime_options_for_tier("extra_high").as_kwargs() == {
- "tier": "extra_high",
+ assert runtime_options_for_tier("xhigh").as_kwargs() == {
+ "tier": "xhigh",
"backend": "hybrid-engine",
- "effort": "extra_high",
+ "effort": "xhigh",
}
- with pytest.raises(ValueError, match="Unsupported tier 'standard'"):
- runtime_options_for_tier("standard")
+
+
+def test_public_tier_literals_include_xhigh() -> None:
+ from mineru.parser.tier import runtime_options_for_tier
+
+ assert "xhigh" in TIERS
+ assert validate_tier("xhigh") == "xhigh"
+ with pytest.raises(ValueError, match="Unsupported tier 'ultra'"):
+ runtime_options_for_tier("ultra")
def test_api_client_builds_file_page_range_without_options(tmp_path: Path) -> None:
@@ -327,7 +334,7 @@ def test_api_client_can_request_zip_for_image_cache(tmp_path: Path) -> None:
def test_api_client_uses_zip_for_staging_when_model_output_requested() -> None:
parser = MinerUApiParser(
api_url="https://staging.mineru.org.cn/api",
- tier="extra_high",
+ tier="xhigh",
include_model_output=True,
)
@@ -337,7 +344,7 @@ def test_api_client_uses_zip_for_staging_when_model_output_requested() -> None:
def test_api_client_uses_zip_for_staging_when_image_cache_requested() -> None:
parser = MinerUApiParser(
api_url="https://staging.mineru.org.cn/api",
- tier="extra_high",
+ tier="xhigh",
include_images=True,
)
@@ -348,21 +355,21 @@ def test_api_client_uses_tier_without_backend_semantics(tmp_path: Path) -> None:
pdf = tmp_path / "demo.pdf"
pdf.write_bytes(b"%PDF-1.7\n")
- parser = MinerUApiParser(api_url="http://localhost:8000", tier="extra_high")
+ parser = MinerUApiParser(api_url="http://localhost:8000", tier="xhigh")
payload = parser._build_payload({"type": "local", "path": str(pdf)}, "")
- assert payload["tier"] == "extra_high"
+ assert payload["tier"] == "xhigh"
assert not hasattr(parser, "backend")
[email protected]("tier", ["standard", "pro"])
-def test_api_client_rejects_old_tier_names(tier: str) -> None:
[email protected]("tier", ["ultra", "experimental"])
+def test_api_client_rejects_invalid_tier_names(tier: str) -> None:
with pytest.raises(ValueError, match=f"Unsupported tier '{tier}'"):
MinerUApiParser(api_url="http://localhost:8000", tier=tier) # type: ignore[arg-type]
def test_api_client_uses_middle_json_format_for_staging() -> None:
- parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="extra_high")
+ parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="xhigh")
assert parser._output_formats() == ["middle_json"]
@@ -1298,7 +1305,7 @@ def test_api_server_rejects_local_source_by_default(tmp_path: Path, monkeypatch:
with TestClient(app) as client:
response = client.post(
"/v1/parse/jobs",
- json={"files": [{"source": {"type": "local", "path": str(source)}}]},
+ json={"tier": "flash", "files": [{"source": {"type": "local", "path": str(source)}}]},
)
assert response.status_code == 400
@@ -1330,6 +1337,7 @@ def test_api_server_rejects_inline_source_over_configured_limit(tmp_path: Path,
response = client.post(
"/v1/parse/jobs",
json={
+ "tier": "flash",
"files": [
{
"source": {
@@ -1356,7 +1364,7 @@ def test_api_server_rejects_plain_http_url_source_by_default(tmp_path: Path, mon
with TestClient(app) as client:
response = client.post(
"/v1/parse/jobs",
- json={"files": [{"source": {"type": "url", "url": "http://example.test/demo.pdf"}}]},
+ json={"tier": "flash", "files": [{"source": {"type": "url", "url": "http://example.test/demo.pdf"}}]},
)
assert response.status_code == 400
@@ -1427,7 +1435,7 @@ def test_api_server_unhandled_exceptions_use_error_envelope(tmp_path: Path, monk
def test_create_app_does_not_read_runtime_settings_from_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
_stub_api_server_dependency_preflight(monkeypatch)
- monkeypatch.setenv("MINERU_TIER", "extra_high")
+ monkeypatch.setenv("MINERU_TIER", "xhigh")
monkeypatch.setenv("MINERU_BACKEND", "hybrid-auto-engine")
monkeypatch.setenv("MINERU_CONCURRENCY", "9")
monkeypatch.setenv("MINERU_URL_TIMEOUT", "99")
@@ -1584,6 +1592,76 @@ def test_api_server_rendered_outputs_do_not_return_image_sidecars(
assert "images" not in output_files.model_dump(by_alias=True, exclude_none=True)
+def test_api_server_run_job_normalizes_lightweight_file_tier_to_flash(
+ monkeypatch: pytest.MonkeyPatch,
+ tmp_path: Path,
+) -> None:
+ calls: list[dict[str, object]] = []
+
+ async def fake_parse_async(*args: object, **kwargs: object) -> ParseResult:
+ calls.append({"path": args[0], **kwargs})
+ return ParseResult(pages=[PageInfo(page_idx=0, _backend="html")])
+
+ monkeypatch.setattr("mineru.parser.api_server.parse_async", fake_parse_async)
+ file_store = FileStore(tmp_path / "api-files")
+ source = tmp_path / "demo.html"
+ source.write_text("<p>content</p>", encoding="utf-8")
+ request = CreateJobRequest.model_validate(
+ {
+ "files": [{"source": {"type": "local", "path": str(source)}}],
+ "tier": "high",
+ "output_formats": ["middle_json"],
+ }
+ )
+ rec = api_server.JobStore().create(request, file_store)
+
+ asyncio.run(
+ api_server._run_job(
+ rec,
+ request,
+ file_store,
+ server_backend="hybrid-engine",
+ language="ch",
+ ocr_mode="auto",
+ image_analysis=True,
+ effort="high",
+ allow_local_source=True,
+ )
+ )
+
+ assert [(call["tier"], call["backend"], call["effort"]) for call in calls] == [("flash", "flash", "medium")]
+ assert rec.tier == "high"
+ assert rec.files[0].status == "completed"
+
+
[email protected](("request_tier", "response_tier"), [("high", "high"), (None, "flash")])
+def test_api_server_accepts_lightweight_job_without_requested_quality_runtime(
+ monkeypatch: pytest.MonkeyPatch,
+ tmp_path: Path,
+ request_tier: str | None,
+ response_tier: str,
+) -> None:
+ async def fake_parse_async(*args: object, **kwargs: object) -> ParseResult:
+ return ParseResult(pages=[PageInfo(page_idx=0, _backend="html")])
+
+ monkeypatch.setattr("mineru.parser.api_server.parse_async", fake_parse_async)
+ source = tmp_path / "demo.html"
+ source.write_text("<p>content</p>", encoding="utf-8")
+ app = create_app(upload_dir=str(tmp_path / "api"), tier=["flash"], allow_local_source=True)
+
+ payload: dict[str, object] = {
+ "files": [{"source": {"type": "local", "path": str(source)}}],
+ "output_formats": ["middle_json"],
+ }
+ if request_tier is not None:
+ payload["tier"] = request_tier
+
+ response = TestClient(app).post("/v1/parse/jobs", json=payload)
+
+ assert response.status_code == 202
+ assert response.json()["tier"] == response_tier
+
+
def test_api_server_middle_json_preserves_backend_for_client_rendering(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
@@ -2020,7 +2098,7 @@ def test_api_server_tier_selects_compatible_backend(tmp_path: Path, monkeypatch:
flash_app = create_app(upload_dir=str(tmp_path / "flash"), tier="flash")
medium_app = create_app(upload_dir=str(tmp_path / "medium"), tier="medium")
high_app = create_app(upload_dir=str(tmp_path / "high"), tier="high")
- extra_high_app = create_app(upload_dir=str(tmp_path / "extra_high"), tier="extra_high")
+ xhigh_app = create_app(upload_dir=str(tmp_path / "xhigh"), tier="xhigh")
assert flash_app.state.tier == "flash"
assert flash_app.state.backend == "flash"
@@ -2033,10 +2111,10 @@ def test_api_server_tier_selects_compatible_backend(tmp_path: Path, monkeypatch:
assert high_app.state.backend == "hybrid-engine"
assert high_app.state.effort == "high"
assert [tier["id"] for tier in high_app.state.tiers] == ["high"]
- assert extra_high_app.state.tier == "extra_high"
- assert extra_high_app.state.backend == "hybrid-engine"
- assert extra_high_app.state.effort == "extra_high"
- assert [tier["id"] for tier in extra_high_app.state.tiers] == ["extra_high"]
+ assert xhigh_app.state.tier == "xhigh"
+ assert xhigh_app.state.backend == "hybrid-engine"
+ assert xhigh_app.state.effort == "xhigh"
+ assert [tier["id"] for tier in xhigh_app.state.tiers] == ["xhigh"]
def test_api_server_defaults_to_all_quality_tiers(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -2047,7 +2125,7 @@ def test_api_server_defaults_to_all_quality_tiers(tmp_path: Path, monkeypatch: p
assert app.state.default_tier == "high"
assert app.state.backend == "hybrid-engine"
assert app.state.effort == "high"
- assert [tier["id"] for tier in app.state.tiers] == ["flash", "medium", "high", "extra_high"]
+ assert [tier["id"] for tier in app.state.tiers] == ["flash", "medium", "high", "xhigh"]
assert app.state.tier_runtime_options["flash"].as_kwargs() == {
"tier": "flash",
"backend": "flash",
@@ -2063,23 +2141,23 @@ def test_api_server_defaults_to_all_quality_tiers(tmp_path: Path, monkeypatch: p
"backend": "hybrid-engine",
"effort": "high",
}
- assert app.state.tier_runtime_options["extra_high"].as_kwargs() == {
- "tier": "extra_high",
+ assert app.state.tier_runtime_options["xhigh"].as_kwargs() == {
+ "tier": "xhigh",
"backend": "hybrid-engine",
- "effort": "extra_high",
+ "effort": "xhigh",
}
def test_api_server_multi_tier_state_and_metadata(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""校验同一个 API server 可发布多个 tier,并在包含 high 时以 high 作为默认 tier。"""
_stub_api_server_dependency_preflight(monkeypatch)
- app = create_app(upload_dir=str(tmp_path), tier=["medium", "high", "extra_high"])
+ app = create_app(upload_dir=str(tmp_path), tier=["medium", "high", "xhigh"])
assert app.state.tier == "high"
assert app.state.default_tier == "high"
assert app.state.backend == "hybrid-engine"
assert app.state.effort == "high"
- assert [tier["id"] for tier in app.state.tiers] == ["medium", "high", "extra_high"]
+ assert [tier["id"] for tier in app.state.tiers] == ["medium", "high", "xhigh"]
assert app.state.model_ids == ["Hybrid-Medium", "MinerU-HTML", "MinerU2.5-Pro-2604-1.2B"]
assert app.state.tier_runtime_options["medium"].as_kwargs() == {
"tier": "medium",
@@ -2091,24 +2169,24 @@ def test_api_server_multi_tier_state_and_metadata(tmp_path: Path, monkeypatch: p
"backend": "hybrid-engine",
"effort": "high",
}
- assert app.state.tier_runtime_options["extra_high"].as_kwargs() == {
- "tier": "extra_high",
+ assert app.state.tier_runtime_options["xhigh"].as_kwargs() == {
+ "tier": "xhigh",
"backend": "hybrid-engine",
- "effort": "extra_high",
+ "effort": "xhigh",
}
def test_api_server_multi_tier_http_metadata(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""校验 /v1/tiers 与 /v1/models 返回启动时声明的全部 tier 能力。"""
_stub_api_server_dependency_preflight(monkeypatch)
- app = create_app(upload_dir=str(tmp_path), tier=["flash", "medium", "high", "extra_high"])
+ app = create_app(upload_dir=str(tmp_path), tier=["flash", "medium", "high", "xhigh"])
with TestClient(app) as client:
tiers_response = client.get("/v1/tiers")
models_response = client.get("/v1/models")
assert tiers_response.status_code == 200
- assert [tier["id"] for tier in tiers_response.json()["data"]] == ["flash", "medium", "high", "extra_high"]
+ assert [tier["id"] for tier in tiers_response.json()["data"]] == ["flash", "medium", "high", "xhigh"]
assert models_response.status_code == 200
assert [model["id"] for model in models_response.json()["data"]] == [
"MinerU-Flash",
@@ -2193,12 +2271,12 @@ def test_api_server_single_tier_rejects_unavailable_tier(tmp_path: Path, monkeyp
"/v1/parse/jobs",
json={
"files": [{"source": {"type": "local", "path": str(source)}}],
- "tier": "extra_high",
+ "tier": "xhigh",
},
)
assert response.status_code == 400
- assert "Tier 'extra_high' not available in this server" in response.text
+ assert "Tier 'xhigh' not available in this server" in response.text
def test_api_server_preflights_medium_tier_dependencies(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
@@ -2223,7 +2301,7 @@ def test_api_server_preflights_medium_tier_dependencies(monkeypatch: pytest.Monk
]
-def test_api_server_preflights_extra_high_tier_dependencies_for_platform(
+def test_api_server_preflights_xhigh_tier_dependencies_for_platform(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
imported_modules: list[str] = []
@@ -2235,7 +2313,7 @@ def test_api_server_preflights_extra_high_tier_dependencies_for_platform(
monkeypatch.setattr(importlib, "import_module", fake_import_module)
monkeypatch.setattr(parser_tier.sys, "platform", "darwin")
- create_app(upload_dir=str(tmp_path), tier="extra_high")
+ create_app(upload_dir=str(tmp_path), tier="xhigh")
assert imported_modules == [
"ftfy",
@@ -2274,13 +2352,13 @@ def test_api_server_cli_reports_dependency_preflight_without_traceback(monkeypat
monkeypatch.setattr(parser_tier.importlib_metadata, "packages_distributions", lambda: {"mineru": ["mineru-next-dev"]})
monkeypatch.setattr(parser_tier.sys, "platform", "darwin")
- result = runner.invoke(main, ["--tier", "extra_high"])
+ result = runner.invoke(main, ["--tier", "xhigh"])
assert result.exit_code == 1
assert result.output == (
- "Error: Parse server cannot start for tier 'extra_high'; missing runtime dependencies: mlx. "
+ "Error: Parse server cannot start for tier 'xhigh'; missing runtime dependencies: mlx. "
"Install optional dependencies for this tier in the same Python environment as MinerU, "
- "for example: pip install 'mineru-next-dev[extra_high]'.\n"
+ "for example: pip install 'mineru-next-dev[xhigh]'.\n"
)
assert "Traceback" not in result.output
@@ -2303,7 +2381,7 @@ def test_build_parser_forwards_effort_to_hybrid_parser(tmp_path: Path) -> None:
assert parser.effort == "high"
-def test_build_parser_maps_legacy_vlm_backend_to_hybrid_extra_high(tmp_path: Path) -> None:
+def test_build_parser_maps_legacy_vlm_backend_to_hybrid_xhigh(tmp_path: Path) -> None:
pdf = tmp_path / "demo.pdf"
pdf.write_bytes(b"%PDF-1.7\n")
@@ -2311,7 +2389,7 @@ def test_build_parser_maps_legacy_vlm_backend_to_hybrid_extra_high(tmp_path: Pat
assert parser.__class__.__name__ == "PdfHybridParser"
assert parser.backend == "hybrid-engine"
- assert parser.effort == "extra_high"
+ assert parser.effort == "xhigh"
def test_build_parser_maps_legacy_pipeline_backend_to_hybrid_medium(tmp_path: Path) -> None:
@@ -2432,7 +2510,7 @@ def test_pdf_engine_resolvers_keep_http_client_backend() -> None:
assert parser_pdf._resolve_hybrid_backend("hybrid-http-client", is_async=True) == "http-client"
-def test_pdf_vlm_parser_compat_delegates_to_hybrid_extra_high(monkeypatch: pytest.MonkeyPatch) -> None:
+def test_pdf_vlm_parser_compat_delegates_to_hybrid_xhigh(monkeypatch: pytest.MonkeyPatch) -> None:
calls: list[tuple[str, bool]] = []
backends: list[str] = []
efforts: list[str] = []
@@ -2470,7 +2548,7 @@ def test_pdf_vlm_parser_compat_delegates_to_hybrid_extra_high(monkeypatch: pytes
assert async_model_output == []
assert calls == [("hybrid-engine", False), ("hybrid-engine", True)]
assert backends == ["sync-backend", "async-backend"]
- assert efforts == ["extra_high", "extra_high"]
+ assert efforts == ["xhigh", "xhigh"]
def test_pdf_hybrid_parser_passes_call_mode_to_backend_resolver(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -2592,9 +2670,9 @@ def test_api_server_cli_defaults_to_all_quality_tiers(monkeypatch: pytest.Monkey
assert result.exit_code == 0
assert seen == {
- "tiers": ["flash", "medium", "high", "extra_high"],
+ "tiers": ["flash", "medium", "high", "xhigh"],
"default_tier": "high",
- "effort_by_tier": {"flash": "medium", "medium": "medium", "high": "high", "extra_high": "extra_high"},
+ "effort_by_tier": {"flash": "medium", "medium": "medium", "high": "high", "xhigh": "xhigh"},
}
@@ -2611,18 +2689,18 @@ def test_api_server_cli_accepts_repeated_tier_list(monkeypatch: pytest.MonkeyPat
monkeypatch.setattr("uvicorn.Server.run", _fake_run)
- result = runner.invoke(main, ["--tier", "medium", "--tier", "extra_high", "--host", "0.0.0.0", "--port", "15984"])
+ result = runner.invoke(main, ["--tier", "medium", "--tier", "xhigh", "--host", "0.0.0.0", "--port", "15984"])
assert result.exit_code == 0
assert seen == {
- "tiers": ["medium", "extra_high"],
- "default_tier": "medium",
- "effort_by_tier": {"medium": "medium", "extra_high": "extra_high"},
+ "tiers": ["medium", "xhigh"],
+ "default_tier": "xhigh",
+ "effort_by_tier": {"medium": "medium", "xhigh": "xhigh"},
}
-def test_api_server_cli_rejects_old_tier_names() -> None:
- result = runner.invoke(main, ["--tier", "standard"])
+def test_api_server_cli_rejects_invalid_tier_names() -> None:
+ result = runner.invoke(main, ["--tier", "ultra"])
assert result.exit_code != 0
assert "Invalid value for '--tier'" in result.output
@@ -2659,7 +2737,7 @@ def test_api_server_cli_help_exposes_tier_only_runtime_selection() -> None:
assert "flash" in normalized_output
assert "medium" in normalized_output
assert "high" in normalized_output
- assert "extra_high" in normalized_output
+ assert "xhigh" in normalized_output
assert "--backend" not in normalized_output
assert "--effort" not in normalized_output
assert "hybrid-engine" not in normalized_output
diff --git a/tests/unittest/test_parser_routing.py b/tests/unittest/test_parser_routing.py
index c9f248b5..896a0ce6 100644
--- a/tests/unittest/test_parser_routing.py
+++ b/tests/unittest/test_parser_routing.py
@@ -22,6 +22,21 @@ def test_build_parser_prefers_html_extension_when_content_guess_is_plain_text(
assert isinstance(parser, HtmlParser)
[email protected]("tier", ["medium", "high", "xhigh"])
+def test_build_parser_rejects_quality_tier_for_html_input(
+ tmp_path: Path,
+ monkeypatch: pytest.MonkeyPatch,
+ tier: str,
+) -> None:
+ html_file = tmp_path / "sample.html"
+ html_file.write_text("<div>hello</div>", encoding="utf-8")
+
+ monkeypatch.setattr("mineru.utils.guess_suffix_or_lang.guess_suffix_by_path", lambda path: "txt")
+
+ with pytest.raises(ValueError, match=f"Tier '{tier}' is only supported for PDF and image files"):
+ _build_parser(html_file, tier=tier) # type: ignore[arg-type]
+
+
def test_build_parser_prefers_xlsx_extension_when_content_guess_is_legacy_doc(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,