Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: add backend options and normalization functions for VLM and hybrid engines
myhloli8b4103d8b3b9
diff --git a/docs/en/usage/cli_tools.md b/docs/en/usage/cli_tools.mdindex 01d93c1f..a1f02912 100644--- a/docs/en/usage/cli_tools.md+++ b/docs/en/usage/cli_tools.md@@ -12,8 +12,9 @@ Options:-o, --output PATH Output directory (required)--api-url TEXT MinerU FastAPI base URL; if omitted, `mineru` starts a temporary local `mineru-api`-m, --method [auto|txt|ocr] Parsing method: auto (default), txt, ocr (pipeline and hybrid* backend only)- -b, --backend [pipeline|hybrid-auto-engine|hybrid-http-client|vlm-auto-engine|vlm-http-client]- Parsing backend (default: hybrid-auto-engine)+ -b, --backend [pipeline|vlm-engine|hybrid-engine|vlm-http-client|hybrid-http-client]+ Parsing backend (default: hybrid-engine)+ --effort [medium|high] Hybrid parsing effort (default: medium)-l, --lang [ch|ch_server|ch_lite|en|korean|japan|chinese_cht|ta|te|ka|th|el|latin|arabic|east_slavic|cyrillic|devanagari]Specify document language (improves OCR accuracy, pipeline and hybrid* backend only)-u, --url TEXT OpenAI-compatible backend URL passed through to the server when using http-client@@ -21,6 +22,9 @@ Options:-e, --end INTEGER Ending page number for parsing (0-based)-f, --formula BOOLEAN Enable formula parsing (default: enabled)-t, --table BOOLEAN Enable table parsing (default: enabled)+ --image-analysis BOOLEAN Enable image/chart analysis for VLM and hybrid+ backends. Hybrid medium effort automatically+ disables image/chart analysis (default: enabled)--client-side-output-generation BOOLEANGenerate Markdown and content lists locallyfrom server-returned middle JSON, images, and@@ -190,10 +194,6 @@ Here are the environment variables and their descriptions:<= 3 GB | 2<= 2 GB | 1-- `MINERU_HYBRID_FORCE_PIPELINE_ENABLE`:- * Used to force the text extraction part in `hybrid-*` backends to be processed using small models.- * Defaults to `false`. Can be set to `true` via environment variable to enable this feature, thereby reducing hallucinations in certain extreme cases.-- `MINERU_VL_MODEL_NAME`:* Used to specify the model name for the vlm/hybrid backend, allowing you to designate the model required for MinerU to run when multiple models exist on a remote openai-server.diff --git a/docs/zh/usage/cli_tools.md b/docs/zh/usage/cli_tools.mdindex e99d780b..a8c792fd 100644--- a/docs/zh/usage/cli_tools.md+++ b/docs/zh/usage/cli_tools.md@@ -12,8 +12,9 @@ Options:-o, --output PATH 输出目录(必填)--api-url TEXT MinerU FastAPI 服务地址;不传时自动拉起本地临时 mineru-api-m, --method [auto|txt|ocr] 解析方法:auto(默认)、txt、ocr(仅用于 pipeline 与 hybrid* 后端)- -b, --backend [pipeline|hybrid-auto-engine|hybrid-http-client|vlm-auto-engine|vlm-http-client]- 解析后端(默认为 hybrid-auto-engine)+ -b, --backend [pipeline|vlm-engine|hybrid-engine|vlm-http-client|hybrid-http-client]+ 解析后端(默认为 hybrid-engine)+ --effort [medium|high] Hybrid 解析强度(默认:medium)-l, --lang [ch|ch_server|ch_lite|en|korean|japan|chinese_cht|ta|te|ka|th|el|latin|arabic|east_slavic|cyrillic|devanagari]指定文档语言(可提升 OCR 准确率,仅用于 pipeline 与 hybrid* 后端)-u, --url TEXT 当使用 http-client 时,传给服务端后端的 OpenAI 兼容地址@@ -21,6 +22,8 @@ Options:-e, --end INTEGER 结束解析的页码(从 0 开始)-f, --formula BOOLEAN 是否启用公式解析(默认开启)-t, --table BOOLEAN 是否启用表格解析(默认开启)+ --image-analysis BOOLEAN 是否启用 VLM 与 hybrid 的图片/图表分析;Hybrid+ medium 强度会自动关闭图片/图表分析(默认开启)--client-side-output-generation BOOLEAN在客户端基于服务端返回的 middle JSON、图片与原文件生成 Markdown 和 content list(默认关闭)@@ -183,10 +186,6 @@ MinerU命令行工具的某些参数存在相同功能的环境变量配置,<= 3 GB | 2<= 2 GB | 1-- `MINERU_HYBRID_FORCE_PIPELINE_ENABLE`:- * 用于强制将 hybrid-* 后端中的 文本提取部分使用 小模型 进行处理- * 默认为`false`,可通过环境变量设置为`true`来启用该功能,从而在某些极端情况下减少幻觉的发生。-- `MINERU_VL_MODEL_NAME`:* 用于指定 vlm/hybrid 后端使用的模型名称,这将允许您在同时存在多个模型的远程openai-server中指定 MinerU 运行所需的模型。diff --git a/mineru/utils/backend_options.py b/mineru/utils/backend_options.pynew file mode 100644index 00000000..9d4dc27e--- /dev/null+++ b/mineru/utils/backend_options.py@@ -0,0 +1,77 @@+# Copyright (c) Opendatalab. All rights reserved.+from __future__ import annotations++from typing import Final++CANONICAL_VLM_ENGINE: Final = "vlm-engine"+CANONICAL_HYBRID_ENGINE: Final = "hybrid-engine"+DEFAULT_BACKEND: Final = CANONICAL_HYBRID_ENGINE+DEFAULT_HYBRID_EFFORT: Final = "medium"+DEFAULT_EFFORT: Final = DEFAULT_HYBRID_EFFORT++LOCAL_BACKEND_CHOICES: Final[tuple[str, ...]] = (+ "pipeline",+ CANONICAL_VLM_ENGINE,+ CANONICAL_HYBRID_ENGINE,+)+HTTP_CLIENT_BACKEND_CHOICES: Final[tuple[str, ...]] = (+ "vlm-http-client",+ "hybrid-http-client",+)+HYBRID_EFFORT_CHOICES: Final[tuple[str, ...]] = ("medium", "high")++BACKEND_ALIASES: Final[dict[str, str]] = {+ "vlm-auto-engine": CANONICAL_VLM_ENGINE,+ "hybrid-auto-engine": CANONICAL_HYBRID_ENGINE,+}++SUPPORTED_BACKENDS: Final[tuple[str, ...]] = (+ "pipeline",+ "flash",+ CANONICAL_VLM_ENGINE,+ "vlm-auto-engine",+ "vlm-http-client",+ "vlm-transformers",+ "vlm-vllm-engine",+ "vlm-vllm-async-engine",+ "vlm-lmdeploy-engine",+ "vlm-mlx-engine",+ CANONICAL_HYBRID_ENGINE,+ "hybrid-auto-engine",+ "hybrid-http-client",+ "hybrid-transformers",+ "hybrid-vllm-engine",+ "hybrid-vllm-async-engine",+ "hybrid-lmdeploy-engine",+ "hybrid-mlx-engine",+)++SUPPORTED_EFFORTS: Final[tuple[str, ...]] = HYBRID_EFFORT_CHOICES+++def normalize_backend(backend: str | None) -> str:+ """规范化公开 backend 名称,并保留旧 auto-engine 名称作为兼容别名。"""+ normalized = (backend or "").strip()+ if normalized in BACKEND_ALIASES:+ return BACKEND_ALIASES[normalized]+ if normalized in SUPPORTED_BACKENDS:+ return normalized+ raise ValueError(f"Unsupported backend '{backend}'. Supported backends: {', '.join(SUPPORTED_BACKENDS)}")+++def validate_effort(effort: str | None) -> str:+ """校验 Hybrid effort 级别,入口层统一使用 medium 作为默认值。"""+ normalized = (effort or DEFAULT_EFFORT).strip().lower()+ if normalized in SUPPORTED_EFFORTS:+ return normalized+ raise ValueError(f"Unsupported effort '{effort}'. Supported efforts: {', '.join(SUPPORTED_EFFORTS)}")+++def is_vlm_backend(backend: str) -> bool:+ """判断规范化后的 backend 是否属于 VLM 后端族。"""+ return normalize_backend(backend).startswith("vlm-")+++def is_hybrid_backend(backend: str) -> bool:+ """判断规范化后的 backend 是否属于 Hybrid 后端族。"""+ return normalize_backend(backend).startswith("hybrid-")