主题
已弃用
本页记录的是已弃用的 Extract v1 API。新的接入请使用 Extract v2;改造已有的 v1 代码请见v1 到 v2 迁移指南。
总体性能最佳实践
要让抽取成功率最高:
调试时先用最强的模型:排查抽取问题时,请用
PREMIUM模式配上强的解析/抽取模型。模型选择对抽取成功率影响很大 —— 可选型号见可用模型。如果用强模型抽取成功,再往下降级就能定位是哪些具体字段在低配模式下出问题。例如BALANCED模式只抽到 10 个数组元素里的 5 个,可以通过改动抽取目标 解决。但若连最好的模型也抽不出来,问题多半出在你的 schema 设计上(例如字段描述含糊)。# Start debugging with a powerful configuration extraction_config = { "mode": "PREMIUM", "parse_model": "anthropic-sonnet-4.5", "extraction_model": "openai-gpt-5" }先小后大、反复迭代:先用数据或 schema 的一个子集验证抽取思路,在 schema 描述上反复打磨(例如加示例、加格式说明),把准确度做上去再扩大规模。
设计清晰、聚焦的 schema:宁可要精准的短描述,也不要那种试图包办一切的冗长字段。见schema 设计 与避免复杂的字段变换。
善用文档结构:用页范围、抽取目标、章节与切块策略来优化处理。见选项。
有策略地组合工具:LlamaExtract 擅长从文档里抽取信息。请把力气花在这个长处上,计算类与校验类的工作交给配套工具(例如繁重的计算放在后处理步骤里做)。
从表格与有序列表抽取
情形: 处理含表格、电子表格(CSV/Excel)或实体有序列表的文档时,你希望每一行、每一项都被完整且准确地抽出来。
使用 PER_TABLE_ROW 抽取目标:如果你只想从表格或实体有序列表里抽取、转换数据,就用 PER_TABLE_ROW 抽取目标。它逐行处理,从而覆盖完整、结果准确。
# Optimal: Use PER_TABLE_ROW for tabular data extraction
extraction_config = {
"extraction_target": "PER_TABLE_ROW",
}schema 里还有表格之外的元素时: 如果你的 schema 含有需要从表格外抽取的字段(例如文档元数据、页眉或概要信息),有两种做法:
拆分抽取任务:表格数据与非表格元素分别跑抽取(前者用
PER_TABLE_ROW)。# First extraction: Get document-level metadata metadata_result = client.extraction.extract.extract( file_id=file_id, schema=metadata_schema, config={ "extraction_target": "PER_DOCUMENT" } ) # Second extraction: Get table row data table_result = client.extraction.extract.extract( file_id=file_id, schema=table_row_schema, config={ "extraction_target": "PER_TABLE_ROW" "page_range": "5-10" # Adjust these accordingly to send pages with the table }, )在 PREMIUM 模式使用推理模型:若要在一次处理中同时抽出表格与非表格元素,请在
PREMIUM模式下使用gpt-5或gpt-5-mini这类抽取模型。注意这种做法会更慢。extraction_config = { "extraction_model": "openai-gpt-5", "mode": "PREMIUM" }
避免复杂的字段变换
不要把业务逻辑写进字段描述里。先抽出干净的数据,再在你的应用代码中做计算。
# ❌ Problematic: Too much logic in the field description
problematic_field = {
"calculated_score": {
"type": "number",
"description": "If revenue > 1M, multiply by 0.8, else if revenue < 500K multiply by 1.2, otherwise use the base score from table 3, but only if the date is after 2020 and the category is not 'exempt'"
}
}
# ✅ Better: Simple extraction, handle logic separately
better_schema = {
"revenue": {"type": "number", "description": "Total revenue in dollars"},
"base_score": {"type": "number", "description": "Base score value from the scoring table"},
"date": {"type": "string", "description": "Date in YYYY-MM-DD format"},
"category": {"type": "string", "description": "Business category"}
}
# Then handle calculations in your application code:
def calculate_final_score(extracted_data):
revenue = extracted_data["revenue"]
if revenue > 1000000:
return extracted_data["base_score"] * 0.8
elif revenue < 500000:
return extracted_data["base_score"] * 1.2
return extracted_data["base_score"]