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
docs: clarify hybrid forced vlm block routing
myhloli92d67835b1c4
diff --git a/docs/superpowers/specs/2026-07-08-hybrid-doc-analyze-refactor-design.md b/docs/superpowers/specs/2026-07-08-hybrid-doc-analyze-refactor-design.mdindex 67b660be..5ec4961e 100644--- a/docs/superpowers/specs/2026-07-08-hybrid-doc-analyze-refactor-design.md+++ b/docs/superpowers/specs/2026-07-08-hybrid-doc-analyze-refactor-design.md@@ -36,17 +36,18 @@## 决策表-| effort | 主结构来源 | `parse_mode=ocr` 文本来源 | `parse_mode=txt` 文本来源 | inline formula MFR | OCR det | OCR rec |-| --- | --- | --- | --- | --- | --- | --- |-| `medium` | 小模型 layout | 小模型 OCR det + rec | PDF native text | `ocr/txt` 都需要 | 需要 | 仅 `ocr` |-| `high` | 小模型 layout 约束 VLM | VLM block OCR | PDF native text | 仅 `txt` | 需要 | 不需要 |-| `extra_high` | VLM two-step 原生结果 | VLM block OCR | PDF native text | 仅 `txt` | 需要 | 不需要 |+| effort | 主结构来源 | `parse_mode=ocr` 文本来源 | `parse_mode=txt` 文本来源 | 强制 VLM 解析块 | inline formula MFR | OCR det | OCR rec |+| --- | --- | --- | --- | --- | --- | --- | --- |+| `medium` | 小模型 layout | 小模型 OCR det + rec | PDF native text | 无 VLM | `ocr/txt` 都需要 | 需要 | 仅 `ocr` |+| `high` | 小模型 layout 约束 VLM | VLM block OCR | PDF native text + VLM 结构块 | `index` / `code` / 行间公式 / `table` | 仅 `txt` | 需要 | 不需要 |+| `extra_high` | VLM two-step 原生结果 | VLM block OCR | PDF native text + VLM 结构块 | `code` / 行间公式 / `table` | 仅 `txt` | 需要 | 不需要 |由表可得:- `use_vlm_text_content = parse_mode == "ocr" and effort in {"high", "extra_high"}`- `needs_mfr = parse_mode == "txt" or effort == "medium"`- `needs_ocr_rec = parse_mode == "ocr" and effort == "medium"`+- `parse_mode == "txt"` 不等于所有内容都走 PDF native text;只有可由 PDF native 回填的文本类块应被 VLM 跳过,强制 VLM 解析块必须继续交给 VLM。## 内部策略对象@@ -63,6 +64,8 @@ class _HybridAnalyzePlan:needs_mfr: boolneeds_ocr_rec: boolextractor: Literal["medium_local", "high_with_layout", "extra_high_two_step"]+ forced_vlm_block_types: frozenset[str]+ vlm_not_extract_list: tuple[str, ...] | None```该对象只在 `hybrid_analyze.py` 内部使用,不作为公开 API。@@ -82,6 +85,7 @@ class _HybridAnalyzePlan:- 先调用 `validate_effort(effort)`。- 按决策表返回 `_HybridAnalyzePlan`。+- `vlm_not_extract_list` 不能无条件等同于未来可能扩展的 `NOT_EXTRACT_TYPES`;它必须排除当前 plan 的 `forced_vlm_block_types`,避免误把 `index` / `code` / 行间公式 / `table` 交给 PDF native 或空内容回填。### 2. Runtime 初始化@@ -120,13 +124,15 @@ class _HybridAnalyzePlan:- 使用 `images_layout_res` 构造 `blocks_list`。- 调用 `predictor.batch_extract_with_layout(...)`。- `parse_mode=ocr` 时不传 `not_extract_list`,由 VLM 完成 block OCR。-- `parse_mode=txt` 时传 `not_extract_list=list(NOT_EXTRACT_TYPES)`,文本由 PDF native text 补齐。+- `parse_mode=txt` 时只跳过可由 PDF native 回填的文本类块;`index`、`code`、行间公式、`table` 必须留给 VLM 解析。`extra_high_two_step`:- 调用 `predictor.batch_two_step_extract(...)`。- `parse_mode=ocr` 时不传 `not_extract_list`,由 VLM 完成 block OCR。-- `parse_mode=txt` 时传 `not_extract_list=list(NOT_EXTRACT_TYPES)`,文本由 PDF native text 补齐。+- `parse_mode=txt` 时只跳过可由 PDF native 回填的文本类块;`code`、行间公式、`table` 必须留给 VLM 解析。++`image_analysis` 继续只在 `extra_high` 中生效,`medium` 和 `high` 强制关闭,避免低/中资源路径隐式触发更重的 VLM 图像分析。### 5. Sidecar 增强@@ -146,6 +152,8 @@ OCR rec 只在 `plan.needs_ocr_rec=True` 时执行:`high/extra_high + ocr` 的 OCR det sidecar 只保留空文本行提示,不能覆盖 VLM content。+`high/extra_high + txt` 的 inline formula MFR 只为 PDF native 文本类块补行内公式;已经强制 VLM 解析的 `code`、行间公式、`table` 内容仍以 VLM 输出为准。+### 6. Append 与 finalize`append_pages(...)` 继续调用 `blocks_to_page_info(...)`,但传入的 `_ocr_enable` 可以保持当前兼容形态,对下游语义更清楚的变量是 `use_vlm_text_content`。@@ -187,9 +195,9 @@ OCR rec 只在 `plan.needs_ocr_rec=True` 时执行:- `medium` 不加载 VLM runtime。- `high + ocr` 调 `batch_extract_with_layout`,不跑 MFR/rec,`use_vlm_text_content=True`。-- `high + txt` 调 `batch_extract_with_layout`,传 `not_extract_list`,跑 MFR,不跑 rec。+- `high + txt` 调 `batch_extract_with_layout`,传 `not_extract_list`,跑 MFR,不跑 rec,并断言 `index` / `code` / 行间公式 / `table` 不在跳过列表中。- `extra_high + ocr` 调 `batch_two_step_extract`,不跑 MFR/rec,`use_vlm_text_content=True`。-- `extra_high + txt` 调 `batch_two_step_extract`,传 `not_extract_list`,跑 MFR,不跑 rec。+- `extra_high + txt` 调 `batch_two_step_extract`,传 `not_extract_list`,跑 MFR,不跑 rec,并断言 `code` / 行间公式 / `table` 不在跳过列表中。- `medium + ocr` 跑 OCR det + OCR rec + MFR。### 回归测试@@ -228,5 +236,7 @@ git diff --check- `medium` 的低资源边界不能被破坏,任何 VLM import 都不能进入 medium 路径。- `high/extra_high + ocr` 不应触发 MFR 或 OCR-rec。- `high/extra_high + txt` 必须保留 inline formula MFR,否则 PDF native text 路径会丢失行内公式补偿。+- `high + txt` 必须强制 VLM 解析 `index`、`code`、行间公式和 `table`,不能因 `not_extract_list` 扩展而退化为 PDF native 回填。+- `extra_high + txt` 必须强制 VLM 解析 `code`、行间公式和 `table`,不能因 `not_extract_list` 扩展而退化为 PDF native 回填。- `INDEX -> TEXT` 的归一仍应留在 `MagicModel` 内容构造完成之后,不能提前转换。- 新增函数和方法必须包含中文注释,方便 review。