Skip to content
LlamaParse 文档版本 跟随上游 源快照 3d7708ac 更新于 2026-10-16

已弃用

本页记录的是已弃用的 Extract v1 API。新的接入请使用 Extract v2;改造已有的 v1 代码请见v1 到 v2 迁移指南。

创建新的抽取智能体时,schema 是最重要的部分。不过还有几个选项也会显著影响抽取过程。

schema 对齐与抽取目标

这些选项决定你的 schema 如何被应用到文档上:

  • Extraction Target:决定抽取的范围与粒度。可选项:

    • PER_DOC(默认):schema 应用到整份文档,返回单个 JSON 对象
    • PER_PAGE:schema 独立应用到每一页,返回一个 JSON 对象数组(每页一个)
    • PER_TABLE_ROW:schema 应用到有序列表中的每个实体(表格行、项目符号列表等),返回一个 JSON 对象数组(每个实体一个)

    各模式何时使用,详见核心概念页。

重要设置

模型设置

  • Extraction Mode:所用的抽取模式,可为 FAST、BALANCED、MULTIMODAL 或 PREMIUM。默认是 MULTIMODAL。FAST 适合只需 OCR、不做 AI 解析的简单文档 —— 它是最快的模式。BALANCED 在多数文档上兼顾速度与准确度。MULTIMODAL(默认)适合文字、简单表格与图片混杂的视觉型文档。PREMIUM 用于从复杂表格与信息密集的文档里抽数据 —— 它凭借更强的 OCR、复杂的表格/表头与版面检测提供最高准确度。

  • Parse Model:文档解析所用的模型。不填则用该抽取模式的默认模型。解析模型只有在 MULTIMODAL 与 PREMIUM 模式下可配。各模式可用模型见下表。

  • Extract Model:数据抽取所用的模型。不填则用该抽取模式的默认模型。抽取模型只有在 PREMIUM 模式下可配。可用模型见下表。

各抽取模式的可用模型

抽取模式模型类型可用模型额外 credit说明默认
FAST-不可配置
BALANCED-不可配置
MULTIMODAL解析模型gemini-2.0-flashNone对中等复杂度、不含密集表格的文档处理很快✓
gemini-2.5-flash-liteNone快速的小模型,与 Gemini 2.0 Flash 相当
gemini-2.5-flash+15 cred. / pageGemini 2.0 Flash 的后继,性能有提升
openai-gpt-4-1+25 cred.-
gemini-2.5-pro+55 cred.适合视觉复杂的文档
抽取模型不可配置
PREMIUM解析模型gemini-2.5-proNone适合视觉复杂的文档、密集表格等
openai-gpt-4-1None-
anthropic-haiku-4.5+25 cred. / page适合视觉复杂的文档✓
anthropic-sonnet-4.5+45 cred. / page对复杂版式做高性能解析
抽取模型openai-gpt-4-1None-✓
openai-gpt-5-miniNone更长的上下文保持与推理
openai-gpt-5+30 cred.更长的上下文保持与推理(++)

系统提示词

  • System Prompt:给抽取智能体的任何额外系统级指示。注意:字段级的说明、few-shot 示例与格式要求等应当通过 schema 的字段描述来传递。

页范围与上下文窗口

  • 页范围:用逗号分隔的页号或范围(从 1 开始计数)指定要从哪些页抽取。例如 1,3,5-7,9 表示抽取第 1、3 页、第 5 到 7 页以及第 9 页;也可以用 1-3,8-10 抽取前三页与第 8 到 10 页。页号从 1 开始,即第一页是 1。当你只需要从大文档的特定章节抽取数据时,这个选项很有用。

  • Context Window:为长文档抽取传入多少页作为上下文。当你需要从大文档抽取、又需要周边页的上下文时很有用。用 SDK 里的 ExtractConfig.num_pages_context 参数配置。取值较大时,周边文档能更多地保持完整,需要一次性看到跨页表格或整张发票时更有帮助;取值较小时会更激进地推进文件,需要你穷尽覆盖密集列表时更合适。

元数据扩展

提供更多元数据与洞见的额外抽取能力,见 元数据扩展 页,它涵盖:

  • Citations:为抽取字段追溯来源
  • Reasoning:解释抽取决策
  • Confidence Scores:量化的置信度指标

这些扩展会在 extraction_metadata 字段里返回额外元数据,但可能影响处理时长。

其他高级选项

这些功能目前在界面里位于 Advanced Settings 之下。

  • Chunk Mode:当大文档超出上下文限制时,控制文档如何被切开以便处理。二选一:

    • PAGE:每页各自作为一个块处理(默认)
    • SECTION:按内容结构(如标题与自然边界)把文档切成语义小节。用 SDK 里的 ExtractConfig.chunk_mode 参数配置。
  • High Resolution Mode:启用高分辨率处理,以便在小字与细节上取得更好准确度。它会提升 OCR 质量、以更高分辨率处理文档页。用 SDK 里的 ExtractConfig.high_resolution_mode 参数启用。警告:这会拖慢抽取的处理时长,只在确有需要时使用。

  • Invalidate Cache:清掉缓存结果并完整重跑。默认情况下 LlamaExtract 会把解析结果缓存 48 小时;开启此项可绕过缓存、确保全新处理,这会产生新的计费。用 SDK 里的 ExtractConfig.invalidate_cache 参数启用。

设置配置选项

在创建抽取智能体时,你可以用 REST API 或 Python SDK 设置这些选项。

SDK

  • Python
  • TypeScript
  • Python(legacy)

首先安装 Python SDK:

终端窗口

pip install "llama-cloud<2.0"

设置各项配置的方法如下:

from llama_cloud import LlamaCloud, AsyncLlamaCloud

client = LlamaCloud(api_key="your_api_key")

schema = {
    "type": "object",
    "properties": {
        "company_name": {"type": "string", "description": "Name of the company"},
        "revenue": {"type": "number", "description": "Annual revenue in USD"}
    }
}

file_obj = client.files.create(file="path/to/your/document.pdf", purpose="extract")
file_id = file_obj.id

result = client.extraction.extract(
    file_id=file_id,
    data_schema=schema,
    config={
        "extraction_target": "PER_DOC",          # PER_DOC, PER_PAGE, PER_TABLE_ROW
        "extraction_mode": "MULTIMODAL",         # FAST, BALANCED, MULTIMODAL, PREMIUM
        "parse_model": None,                     # Optional: override parse model
        "extract_model": None,                   # Optional: override extract model
        "system_prompt": "Focus on the most recent financial data",
        "page_range": "1-5,10-15",               # Extract from specific pages
        "num_pages_context": 3,                  # Number of context pages for long docs
        "cite_sources": True,                    # Enable citations
        "use_reasoning": True,                   # Enable reasoning (not available in FAST mode)
        "confidence_scores": True,               # Enable confidence scores (MULTIMODAL/PREMIUM only)
        "chunk_mode": "PAGE",                    # PAGE, SECTION
        "high_resolution_mode": True,            # Enable for better OCR
        "invalidate_cache": False,               # Set to True to bypass cache
    }
)

首先安装 TypeScript SDK:

终端窗口

npm install @llamaindex/llama-cloud zod

设置各项配置的方法如下:

import fs from 'fs';
import LlamaCloud from '@llamaindex/llama-cloud';

const client = new LlamaCloud({
  apiKey: 'your_api_key',
});

const schema = {
  type: 'object',
  properties: {
    company_name: { type: 'string', description: 'Name of the company' },
    revenue: { type: 'number', description: 'Annual revenue in USD' },
  },
};

const fileObj = await client.files.create({
  file: fs.createReadStream('path/to/your/document.pdf'),
  purpose: 'extract',
});
const fileId = fileObj.id;

const result = await client.extraction.extract({
  fileId: fileId,
  dataSchema: schema,
  config: {
    extraction_target: 'PER_DOC',          // PER_DOC, PER_PAGE, PER_TABLE_ROW
    extraction_mode: 'MULTIMODAL',         // FAST, BALANCED, MULTIMODAL, PREMIUM
    parse_model: null,                     // Optional: override parse model
    extract_model: null,                   // Optional: override extract model
    system_prompt: 'Focus on the most recent financial data',
    page_range: '1-5,10-15',               // Extract from specific pages
    num_pages_context: 3,                   // Number of context pages for long docs
    cite_sources: true,                    // Enable citations
    use_reasoning: true,                   // Enable reasoning (not available in FAST mode)
    confidence_scores: true,               // Enable confidence scores (MULTIMODAL/PREMIUM only)
    chunk_mode: 'PAGE',                    // PAGE, SECTION
    high_resolution_mode: true,            // Enable for better OCR
    invalidate_cache: false,               // Set to True to bypass cache
  },
});

首先安装遗留版 Python SDK:

终端窗口

pip install llama-cloud-services

设置各项配置的方法如下:

from llama_cloud_services import LlamaExtract
from llama_cloud import ExtractConfig, ExtractMode, ChunkMode, ExtractTarget

# Initialize the client
extract = LlamaExtract(api_key="YOUR_API_KEY")

# Define your schema
schema = {
    "type": "object",
    "properties": {
        "company_name": {"type": "string", "description": "Name of the company"},
        "revenue": {"type": "number", "description": "Annual revenue in USD"}
    }
}

# Create extraction configuration
config = ExtractConfig(
    # Schema alignment
    extraction_target=ExtractTarget.PER_DOC,   # PER_DOC, PER_PAGE

    # Model settings
    extraction_mode=ExtractMode.MULTIMODAL,    # FAST, BALANCED, MULTIMODAL, PREMIUM
    parse_model=None,                          # Optional: override parse model
    extract_model=None,                        # Optional: override extract model

    # System prompt
    system_prompt="Focus on the most recent financial data",

    # Page range and context
    page_range="1-5,10-15",                    # Extract from specific pages
    num_pages_context=3,                       # Number of context pages for long docs

    # Metadata extensions (see Metadata Extensions page for details)
    cite_sources=True,                         # Enable citations
    use_reasoning=True,                        # Enable reasoning (not available in FAST mode)
    confidence_scores=True,                    # Enable confidence scores (MULTIMODAL/PREMIUM only)

    # Advanced options
    chunk_mode=ChunkMode.PAGE,                 # PAGE, SECTION
    high_resolution_mode=True,                 # Enable for better OCR
    invalidate_cache=False,                    # Set to True to bypass cache
)

# Create extraction agent with configuration
agent = extract.create_agent(
    name="Financial Data Extractor",
    data_schema=schema,
    config=config
)

# Extract from a document
result = agent.extract("your-document.pdf")
print(result.data)

REST API

在创建抽取智能体时,你也可以用 REST API 设置这些选项:

终端窗口

curl -X 'POST' \
  'https://api.cloud.llamaindex.ai/api/v1/extraction/extraction-agents' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Financial Data Extractor",
    "data_schema": {
      "type": "object",
      "properties": {
        "company_name": {"type": "string", "description": "Name of the company"},
        "revenue": {"type": "number", "description": "Annual revenue in USD"}
      }
    },
    "config": {
      "extraction_target": "PER_DOC",
      "extraction_mode": "MULTIMODAL",
      "parse_model": null,
      "extract_model": null,
      "system_prompt": "Focus on the most recent financial data",
      "page_range": "1-5,10-15",
      "num_pages_context": 3,
      "cite_sources": true,
      "use_reasoning": true,
      "confidence_scores": true,
      "chunk_mode": "PAGE",
      "high_resolution_mode": true,
      "invalidate_cache": false
    }
  }'

配置参考

选项类型默认值说明
schema 对齐
extraction_targetstring”PER_DOC”抽取范围:PER_DOC、PER_PAGE、PER_TABLE_ROW
模型设置
extraction_modestring”MULTIMODAL”处理模式:FAST、BALANCED、MULTIMODAL(默认)、PREMIUM
parse_modelstringnull覆盖解析模型(可选)
extract_modelstringnull覆盖抽取模型(可选)
系统提示词
system_promptstringnull额外的系统级指示
页范围与上下文
page_rangestringnull要抽取的页号/范围(从 1 开始,例如 “1,3,5-7”)
num_pages_contextintegernull长文档中作为上下文传入的页数
元数据扩展
cite_sourcesbooleanfalse开启来源引用
use_reasoningbooleanfalse开启抽取推理(FAST 模式不可用)
confidence_scoresbooleanfalse开启置信度得分(仅 MULTIMODAL/PREMIUM)
高级选项
chunk_modestring”PAGE”文档切块策略:PAGE、SECTION
high_resolution_modebooleanfalse开启高分辨率处理
invalidate_cachebooleanfalse绕过已缓存的结果

注意:像 confidence_scores 这样的选项只在特定抽取模式下可用。细节见上文各选项的说明。

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。