主题
已弃用
本页记录的是已弃用的 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-flash | None | 对中等复杂度、不含密集表格的文档处理很快 | ✓ |
gemini-2.5-flash-lite | None | 快速的小模型,与 Gemini 2.0 Flash 相当 | |||
gemini-2.5-flash | +15 cred. / page | Gemini 2.0 Flash 的后继,性能有提升 | |||
openai-gpt-4-1 | +25 cred. | - | |||
gemini-2.5-pro | +55 cred. | 适合视觉复杂的文档 | |||
| 抽取模型 | 不可配置 | ||||
| PREMIUM | 解析模型 | gemini-2.5-pro | None | 适合视觉复杂的文档、密集表格等 | |
openai-gpt-4-1 | None | - | |||
anthropic-haiku-4.5 | +25 cred. / page | 适合视觉复杂的文档 | ✓ | ||
anthropic-sonnet-4.5 | +45 cred. / page | 对复杂版式做高性能解析 | |||
| 抽取模型 | openai-gpt-4-1 | None | - | ✓ | |
openai-gpt-5-mini | None | 更长的上下文保持与推理 | |||
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"1
设置各项配置的方法如下:
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
}
)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
首先安装 TypeScript SDK:
终端窗口
npm install @llamaindex/llama-cloud zod1
设置各项配置的方法如下:
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
},
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
首先安装遗留版 Python SDK:
终端窗口
pip install llama-cloud-services1
设置各项配置的方法如下:
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)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
}
}'1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
配置参考
| 选项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| schema 对齐 | |||
extraction_target | string | ”PER_DOC” | 抽取范围:PER_DOC、PER_PAGE、PER_TABLE_ROW |
| 模型设置 | |||
extraction_mode | string | ”MULTIMODAL” | 处理模式:FAST、BALANCED、MULTIMODAL(默认)、PREMIUM |
parse_model | string | null | 覆盖解析模型(可选) |
extract_model | string | null | 覆盖抽取模型(可选) |
| 系统提示词 | |||
system_prompt | string | null | 额外的系统级指示 |
| 页范围与上下文 | |||
page_range | string | null | 要抽取的页号/范围(从 1 开始,例如 “1,3,5-7”) |
num_pages_context | integer | null | 长文档中作为上下文传入的页数 |
| 元数据扩展 | |||
cite_sources | boolean | false | 开启来源引用 |
use_reasoning | boolean | false | 开启抽取推理(FAST 模式不可用) |
confidence_scores | boolean | false | 开启置信度得分(仅 MULTIMODAL/PREMIUM) |
| 高级选项 | |||
chunk_mode | string | ”PAGE” | 文档切块策略:PAGE、SECTION |
high_resolution_mode | boolean | false | 开启高分辨率处理 |
invalidate_cache | boolean | false | 绕过已缓存的结果 |
注意:像 confidence_scores 这样的选项只在特定抽取模式下可用。细节见上文各选项的说明。