# 9.2 文档处理与知识库

IDP (Intelligent Document Processing) 是企业自动化的“深水区”。 传统 OCR 只能把图片转成文字，但还是非结构化的。Claude 的视觉能力和长文本理解能力，使其能够将非结构化文档转化为 **结构化数据 (JSON)**。

## 9.2.1 场景案例：非标合同抽取

一家投资机构每天收到上百份 PDF 格式的商业计划书 (BP) 和财务报表，格式各异。

### 传统方案 vs Claude 方案

| 维度        | 传统 OCR + 正则表达式 | Claude Vision + JSON Mode |
| --------- | -------------- | ------------------------- |
| **格式适应性** | 极差，换个模板就挂      | 极强，基于语义理解                 |
| **表格提取**  | 经常错位           | 能完美理解跨页表格                 |
| **手写体识别** | 困难             | 极高准确率                     |
| **推理能力**  | 无（只能提取表面文字）    | 有（能计算“同比增长率”）             |

## 9.2.2 实战：复杂财务报表提取

假设我们有一张这种扫描件（图片），里面包含一个复杂的“资产负债表”，甚至有跨页和合并单元格。

### Input Prompt

> “这张图片是公司的资产负债表。请提取其中的关键财务数据，并验证数据是否平衡（资产 = 负债 + 所有者权益）。如果发现不平衡，请在 `validation_error` 字段中标注。请严格按照以下 JSON Schema 输出。”

### Output JSON

```json
{
  "company_name": "Future Tech Inc.",
  "report_date": "2025-12-31",
  "currency": "USD",
  "assets": {
    "current_assets": {
      "cash": 5000000,
      "accounts_receivable": 2000000,
      "inventory": 1500000
    },
    "non_current_assets": {
      "property_plant_equipment": 10000000,
      "intangible_assets": 500000
    },
    "total_assets": 19000000
  },
  "liabilities": {
    "current_liabilities": 4000000,
    "long_term_liabilities": 5000000,
    "total_liabilities": 9000000
  },
  "equity": {
    "share_capital": 8000000,
    "retained_earnings": 2000000,
    "total_equity": 10000000
  },
  "validation": {
    "is_balanced": true,
    "calculation": "19000000 = 9000000 + 10000000"
  }
}
```

**Claude 的神奇之处在于**：即使原图中没有显式写出 `total_assets` 的数字，它也能通过计算推导出来；或者如果原图数字有误（扫描模糊导致），它能根据会计恒等式发现并标记。

## 9.2.3 场景案例：企业知识库的语义增强

很多公司积累了大量的 Wiki，但传统关键词搜索经常搜不到。

RAG（检索增强生成）把企业文档变成可检索的知识库，让 Claude 基于检索到的片段作答并标注来源：

```mermaid
graph LR
    subgraph OFF["离线：构建索引"]
        D["企业文档 / Wiki"] --> C["分块"] --> E["向量化"] --> V[("向量库")]
    end
    Q["用户提问"] --> R["语义检索<br/>Top-K 相关片段"]
    V --> R
    R --> M(("Claude<br/>要求逐条引用"))
    M --> A["带来源溯源的回答<br/>(Ref: Doc, Page X)"]
```

### 语义搜索与引用溯源

Anthropic API 引入了更精准的 **Citation** 能力（支持 Claude 3.5 及后续模型）。在 RAG 系统中，我们要求 Claude 不仅回答，还要告诉我们“你是看哪一行知道的”。

**User Question**: “公司差旅标准里，打车费有限额吗？”

**Claude Response**:

> 根据《员工差旅管理制度 V2.0》第 4 章第 2 条：
>
> 1. 一般员工在一线城市（北上广深）打车限额为 **150元/天**。`(Ref: doc_travel_policy.pdf, page 12, para 3)`
> 2. 如果加班至 22:00 以后，通过企业用车平台打车 **不设上限**。`(Ref: doc_travel_policy.pdf, page 12, para 5)`

**技术实现**: 在 System Prompt 中强制要求：`Every claim must be followed by a citation like [Source: Doc Name, Page X].`

## 9.2.4 最佳实践：Human-in-the-Loop Review

尽管 Claude 很强，但在处理财务数据（Invoice Processing）时，准确率要求是 100%。

**基于置信度的混合工作流**:

1. **AI 处理**: Claude 提取发票信息，并输出一个 `confidence_score` (0.0 - 1.0)。
2. **自动分流**:
   * `score > 0.98`: **直通** -> 自动调用 API 录入 SAP 系统。
   * `score <= 0.98`: **人工审核** -> 推送到审核人员界面。
3. **UI 辅助**: 在人工审核界面，使用 bounding box 将 Claude 提取的区域在原图上高亮显示，审核员只需肉眼扫一眼，确认数字无误点击“通过”。这比纯人工录入快 10 倍。

***

如果说文档处理是把“死数据”变活，那么数据分析就是从“活数据”中挖掘黄金。 Claude 不仅能看懂 Excel，还能自己写 SQL 查数据库，这就是 **Text-to-Insight**。

➡️ [数据分析助手](/claude_guide/di-si-bu-fen-shi-zhan-pian/09_practical/9.3_data_analysis.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/claude_guide/di-si-bu-fen-shi-zhan-pian/09_practical/9.2_doc_processing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
