Files
AIclinicalresearch/docs/02-通用能力层/02-文档处理引擎/README.md
HaHafeng dc6b292308 docs(asl): Complete Tool 3 extraction workbench V2.0 development plan (v1.5)
ASL Tool 3 Development Plan:
- Architecture blueprint v1.5 (6 rounds of architecture review, 13 red lines)
- M1/M2/M3 sprint checklists (Skeleton Pipeline / HITL Workbench / Dynamic Template Engine)
- Code patterns cookbook (9 chapters: Fan-out, Prompt engineering, ACL, SSE dual-track, etc.)
- Key patterns: Fan-out with Last Child Wins, Optimistic Locking, teamConcurrency throttling
- PKB ACL integration (anti-corruption layer), MinerU Cache-Aside, NOTIFY/LISTEN cross-pod SSE
- Data consistency snapshot for long-running extraction tasks

Platform capability:
- Add distributed Fan-out task pattern development guide (7 patterns + 10 anti-patterns)
- Add system-level async architecture risk analysis blueprint
- Add PDF table extraction engine design and usage guide (MinerU integration)
- Add table extraction source code (TableExtractionManager + MinerU engine)

Documentation updates:
- Update ASL module status with Tool 3 V2.0 plan readiness
- Update system status document (v6.2) with latest milestones
- Add V2.0 product requirements, prototypes, and data dictionary specs
- Add architecture review documents (4 rounds of review feedback)
- Add test PDF files for extraction validation

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 22:49:16 +08:00

9.8 KiB
Raw Blame History

文档处理引擎

能力定位: 通用能力层
复用率: 86% (6个模块依赖)
优先级: P0
状态: V2 — pymupdf4llm (全文) + MinerU (表格) 双引擎架构
最后更新: 2026-02-23


📋 能力概述

文档处理引擎是平台的核心基础能力,将各类文档统一转换为 LLM 友好的 Markdown 格式,为知识库构建、文献分析、数据导入等场景提供基础支撑。

设计目标

  1. 多格式支持 - 覆盖医学科研领域 20+ 种文档格式
  2. LLM 友好输出 - 统一输出结构化 Markdown
  3. 表格精准提取 - MinerU VLM 引擎支持合并单元格、数值 100% 保真V2 新增)
  4. 可扩展架构 - 方便添加新格式支持

🔄 重大更新2026-02-23

V2: PDF 表格提取引擎 — 统一抽象 + 多引擎可插拔

新建 PDF 表格提取引擎,核心理念:使用者只需提交 PDF、获取结构化表格无需关心底层引擎实现

已完成 8 篇真实医学文献的首轮对比测试pymupdf4llm / MinerU / DeepSeekMinerU Cloud API 作为首个接入引擎:

对比项 pymupdf4llm MinerU API (VLM) DeepSeek LLM
结构化表格检出 3 个 (12.5%) 28 个 (100%) 24 个 (85%)
合并单元格 rowspan/colspan ⚠️ 文字描述
数值精度 100% 保真 ⚠️ 可能翻译
综合评分 2.7/5 4.6/5 3.4/5

V2 分层架构(全文 + 表格 分离):

引擎 定位 适用场景
pymupdf4llm 全文文本提取 标题摘要初筛、PKB 入库、全文检索
PDF 表格提取引擎 结构化表格 全文复筛、系统综述、Meta 分析

表格提取引擎候选 (可插拔)

引擎 状态 特点
MinerU Cloud API (VLM) 已接入 (默认) 表格结构最完整
Qwen3-VL 📋 待评测 多模态理解最强
PaddleOCR-VL 1.5 📋 待评测 医学场景案例多,免费额度最多
Qwen-OCR + Qwen-Long 📋 待评测 成本最低
Docling (IBM) 📋 待评测 MIT 开源,离线部署

详见:PDF 表格提取引擎设计方案

V1 (2026-01-20): PDF 文本提取升级

变更 旧方案 新方案
工具 PyMuPDF + Nougat pymupdf4llm
表格处理 基础文本 Markdown 表格
多栏布局 手动处理 自动重排
依赖复杂度 GPU

📊 支持格式

格式覆盖矩阵

分类 格式 推荐工具 优先级 状态
文档类 PDF pymupdf4llm P0
Word (.docx) mammoth P0
PPT (.pptx) python-pptx P1
纯文本 直接读取 P0
表格类 Excel (.xlsx) pandas + openpyxl P0
CSV pandas P0
SAS/SPSS/Stata pandas + pyreadstat P2 🔜
网页类 HTML beautifulsoup4 + markdownify P1
引用类 BibTeX/RIS bibtexparser / rispy P1
医学类 DICOM pydicom P2 🔜

📊 依赖模块

6个模块依赖86%复用率):

模块 用途 核心格式
ASL - AI智能文献 文献 PDF 提取 PDF
PKB - 个人知识库 知识库文档上传 PDF, Word, Excel
DC - 数据清洗 数据导入 Excel, CSV
SSA - 智能统计分析 数据导入 Excel, CSV, SAS/SPSS
ST - 统计分析工具 数据导入 Excel, CSV
RVW - 稿件审查 稿件文档提取 Word, PDF

🏗️ 技术架构

V2 双引擎架构

┌──────────────────────────────────────────────────────────────┐
│                    文档处理引擎 (V2)                           │
├──────────────────────────────────────────────────────────────┤
│                                                              │
│  ┌─────────────────────┐  ┌─────────────────────────────┐   │
│  │  全文文本提取 (V1)   │  │  PDF 表格提取引擎 (V2 新增)  │   │
│  │                     │  │                             │   │
│  │  pymupdf4llm        │  │  统一抽象层 (可插拔引擎)     │   │
│  │  ─────────────      │  │  ─────────────────────      │   │
│  │  • PDF → Markdown   │  │  当前: MinerU VLM           │   │
│  │  • 速度快、免费      │  │  待测: Qwen3-VL / Paddle   │   │
│  │  • 不依赖网络       │  │  待测: Qwen-OCR / Docling   │   │
│  │                     │  │  • 统一 ExtractedTable 输出  │   │
│  └─────────────────────┘  └─────────────────────────────┘   │
│                                                              │
│  ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐   │
│  │   Word    │ │    PPT    │ │   Excel   │ │    CSV    │   │
│  │  mammoth  │ │python-pptx│ │  pandas   │ │  pandas   │   │
│  └───────────┘ └───────────┘ └───────────┘ └───────────┘   │
├──────────────────────────────────────────────────────────────┤
│           输出: Markdown 文本 / HTML 结构化表格                │
└──────────────────────────────────────────────────────────────┘

目录结构

extraction_service/
├── main.py                    - FastAPI 主服务
├── document_processor.py      - 统一入口
├── processors/
│   ├── pdf_processor.py       - PDF 处理 (pymupdf4llm)
│   ├── docx_processor.py      - Word 处理 (mammoth)
│   ├── pptx_processor.py      - PPT 处理 (python-pptx)
│   ├── excel_processor.py     - Excel 处理 (pandas)
│   ├── csv_processor.py       - CSV 处理 (pandas)
│   ├── html_processor.py      - HTML 处理 (markdownify)
│   └── reference_processor.py - 文献引用处理
└── requirements.txt

💡 快速使用

基础用法

from document_processor import DocumentProcessor

# 创建处理器
processor = DocumentProcessor()

# 转换任意文档为 Markdown
md = processor.to_markdown("research_paper.pdf")
md = processor.to_markdown("report.docx")
md = processor.to_markdown("data.xlsx")

PDF 表格提取

import pymupdf4llm

# PDF 转 Markdown自动保留表格结构
md_text = pymupdf4llm.to_markdown(
    "paper.pdf",
    page_chunks=True,    # 按页分块
    write_images=True,   # 提取图片
)

📚 API 端点

POST /api/extract/pdf      - PDF 文本提取
POST /api/extract/docx     - Word 文本提取
POST /api/extract/txt      - TXT 文本提取
POST /api/extract/excel    - Excel 表格提取
POST /api/extract/pptx     - PPT 文本提取(新增)
POST /api/extract/html     - HTML 文本提取(新增)
GET  /health               - 健康检查

📦 核心依赖

# PDF
pymupdf4llm>=0.0.10

# Word
mammoth>=1.6.0

# PPT
python-pptx>=0.6.23

# Excel/CSV
pandas>=2.0.0
openpyxl>=3.1.2
tabulate>=0.9.0

# HTML
beautifulsoup4>=4.12.0
markdownify>=0.11.6

# 文献引用
bibtexparser>=1.4.0
rispy>=0.7.0

🔗 相关文档


📅 更新日志

2026-02-23 PDF 表格提取引擎升级 (V2)

  • 🆕 新建 PDF 表格提取引擎 — 统一抽象层,底层引擎可插拔
  • 🆕 MinerU Cloud API (VLM) 作为首个接入引擎 (默认)
  • 🆕 完成 pymupdf4llm / MinerU / DeepSeek 三方对比测试 (8 篇医学文献)
  • 📊 MinerU 综合评分 4.6/5作为默认引擎
  • 📋 后续评测计划Qwen3-VL / PaddleOCR-VL / Qwen-OCR+Qwen-Long / Docling
  • 📝 创建 PDF 表格提取引擎设计方案
  • 🏗️ 确立分层架构pymupdf4llm (全文文本) + PDF 表格提取引擎 (结构化表格)

2026-01-20 架构升级

  • 🆕 PDF 处理升级为 pymupdf4llm
  • 🆕 移除 Nougat 依赖
  • 🆕 新增统一处理器架构
  • 🆕 新增 PPT、HTML、文献引用格式支持
  • 📝 创建详细设计方案文档

2025-11-06 初始版本

  • 基础 PDF/Word/Excel 处理
  • Python 微服务架构

维护人: 技术架构师