AI Skills AI技能 5h ago Updated 1h ago 更新于 1小时前 46

I Tried to Prove DocLang Beats Markdown for PDF→LLM. The Data Said Otherwise. 我试图证明DocLang在PDF转LLM方面胜过Markdown,但数据说了反话

A converter-independent experiment comparing Markdown vs DocLang for PDF-to-LLM pipelines found identical answer accuracy (100% on facts, 87.5% on structure) across both formats when the full document fits in context DocLang costs 1.5×–2.6× more tokens than Markdown (16,232 vs 6,348 tokens) due to XML wrapper overhead and bounding-box location elements, with zero accuracy gain on this document The DocLang output was structurally flat because the parser failed to recover exhibit hierarchy from th 实验对比PDF转Markdown与DocLang格式,在单文档全上下文问答场景下,两者答案准确率完全相同(事实题100%,结构题87.5%) DocLang格式成本显著更高:原生DocLang消耗16,232 tokens(Markdown的2.56倍),即使去除定位信息仍有9,288 tokens(1.46倍) DocLang的"结构化优势"未能发挥,因解析器未能从扫描PDF中恢复文档层级,导致DocLang输出实际是扁平结构 Markdown在定位准确性上与DocLang持平甚至更优(86.7% vs 73.3%),DocLang的bbox信息反而分散模型注意力 DocLang的价值场景在

60
Hot 热度
72
Quality 质量
65
Impact 影响力

Analysis 深度分析

TL;DR

  • A converter-independent experiment comparing Markdown vs DocLang for PDF-to-LLM pipelines found identical answer accuracy (100% on facts, 87.5% on structure) across both formats when the full document fits in context
  • DocLang costs 1.5×–2.6× more tokens than Markdown (16,232 vs 6,348 tokens) due to XML wrapper overhead and bounding-box location elements, with zero accuracy gain on this document
  • The DocLang output was structurally flat because the parser failed to recover exhibit hierarchy from the scanned PDF, meaning DocLang carried no structural advantage over Markdown on this input
  • Markdown outperformed DocLang on localization for structure questions (75% vs 62.5%), with bounding-box elements actively distracting the model
  • DocLang's value lies in retrieval over large corpora, documents with recovered structure, round-trip fidelity for complex elements (tables, forms), and pixel-accurate provenance citations — not in single-document full-context Q&A

Why It Matters

This experiment directly addresses a critical decision point for anyone building RAG systems or document Q&A pipelines: the choice of text representation between the mature, lightweight Markdown format and the newer AI-native DocLang. The findings challenge the assumption that structured markup automatically yields better LLM performance, and instead show that representation choice must be matched to the specific use case — full-context Q&A favors Markdown, while retrieval, provenance, and complex document elements favor DocLang.

Technical Details

  • Experimental design: A single 15-page scanned construction RFP PDF was parsed once into a DoclingDocument, then serialized into three arms (Markdown, native DocLang, DocLang without location elements) using docling-core's first-party serializers — eliminating converter-maturity bias
  • Model and evaluation: GPT-5.4-mini via Azure OpenAI in JSON mode with the full document in the system prompt; two question sets (15 fact questions × 3 trials, 8 structure questions × 2 trials) graded by an LLM judge against gold answers and gold locations
  • Token overhead breakdown: Native DocLang at 16,232 tokens (2.56× Markdown) driven primarily by <location> bounding-box elements (four per content block); even stripped of locations, DocLang remained 1.46× larger due to XML tag overhead (~46% over Markdown's ## and blank-line conventions)
  • Localization results: DocLang tied Markdown on fact-set location accuracy (86.7%) but dropped to 73.3% without location elements; on structure questions, DocLang's bbox elements actively hurt performance (62.5% vs Markdown's 75%)
  • Root cause of flat output: Docling's layout model parsed the scanned PDF without recovering exhibit hierarchy — all headings were serialized as level="2" with no <group> containers, and running page headers were repeated ~12 times as genuine heading elements

Industry Insight

  • Don't default to DocLang for full-context document Q&A: If your use case fits a single document in the context window, Markdown is the strictly dominant choice — same accuracy, significantly lower cost and latency. Reserve DocLang for cases where its structural features are actually exercised by the parser.
  • Parser quality is the bottleneck, not the format: DocLang's theoretical advantages (hierarchical grouping, addressable chunks, provenance) are entirely dependent on the upstream parser recovering that structure. Invest in parser tuning or post-processing (e.g., rebuilding section trees for born-digital PDFs) before expecting format-level gains.
  • DocLang's real competitive edge is retrieval and fidelity, not generation: For corpus-scale RAG where structural chunk boundaries prevent running-header bleed, for documents with tables/forms/checkboxes that Markdown mangles, and for applications requiring pixel-accurate citations back to source PDFs, DocLang's token overhead is justified — this experiment explicitly did not test those regimes.

TL;DR

  • 实验对比PDF转Markdown与DocLang格式,在单文档全上下文问答场景下,两者答案准确率完全相同(事实题100%,结构题87.5%)
  • DocLang格式成本显著更高:原生DocLang消耗16,232 tokens(Markdown的2.56倍),即使去除定位信息仍有9,288 tokens(1.46倍)
  • DocLang的"结构化优势"未能发挥,因解析器未能从扫描PDF中恢复文档层级,导致DocLang输出实际是扁平结构
  • Markdown在定位准确性上与DocLang持平甚至更优(86.7% vs 73.3%),DocLang的bbox信息反而分散模型注意力
  • DocLang的价值场景在于:需要像素级溯源、复杂表格/表单处理、检索场景的结构化分块,而非单文档全量问答

为什么值得看

本文通过严谨的对照实验(同一解析器、同一文档、同一模型)揭示了DocLang格式在典型RAG场景下的真实表现,打破了"结构化格式必然优于Markdown"的假设。对AI从业者而言,这提供了宝贵的格式选型依据,避免在成本敏感场景盲目采用新格式。

技术解析

  • 实验设计:使用真实15页建筑RFP扫描PDF,通过DoclingDocument统一解析后,由docling-core的官方序列化器分别生成Markdown和DocLang格式,确保对比公平性
  • 模型与评估:采用gpt-5.4-mini(Azure OpenAI),JSON模式,整文档放入系统提示;设置事实题(15题×3次)和结构题(8题×2次),由LLM裁判对照标准答案和标准位置评分
  • 成本分析:DocLang原生格式因每个内容块包含4个坐标元素,导致token开销达Markdown的2.56倍;即使去除定位信息,XML标签本身仍带来46%的额外开销
  • 定位表现:DocLang在事实题定位准确率达86.7%(与Markdown持平),但在结构题上仅62.5%(Markdown为75%),bbox信息反而造成干扰
  • 根本原因:Docling的布局模型未能从扫描PDF中恢复文档层级结构,导致DocLang输出为扁平结构(所有heading均为level="2",无嵌套),丧失了结构化格式的核心价值

行业启示

  • 格式选型应匹配场景:单文档全上下文问答场景下Markdown是更优选择;DocLang更适合需要溯源定位、处理复杂排版、或检索场景下的结构化分块
  • 解析质量决定格式上限:DocLang的结构化优势依赖于解析器能否恢复文档层级,当前扫描PDF解析技术尚未成熟,盲目采用新格式可能得不偿失
  • 成本意识需贯穿始终:1.5-2.6倍的token开销在单文档场景下无收益,但在大规模检索管线中可能因更精准的分块和定位而翻转,需根据实际规模评估ROI

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

LLM 大模型 RAG 检索增强生成 Evaluation 评测 Research 科学研究