导出 Document AI 模型构建¶
您可以将 Document AI 模型构建导出到内部暂存区。这样会导出文档文件,并生成注释文件。然后,您可以将导出的数据用于多种用途,例如创建 Snowflake 数据集,并使用 AI_EXTRACT 函数提取信息。
先决条件¶
要使用 Document AI,您必须具有所需的权限。有关权限的更多信息,请参阅 设置 Document AI。
要导出 Document AI 模型构建,您必须在目标暂存区上具有 WRITE 权限。
备注
目标暂存区必须是内部暂存区。
导出 Document AI 模型构建¶
登录 Snowsight。
In the navigation menu, select AI & ML » AI Studio.
在 Document Processing Playground 旁边,选择 Open。在 Document Processing Playground 中,要访问 Document AI,请选择 Go to Document AI model builds。
选择仓库。
显示现有模型构建的列表。
选择模型构建名称旁边的 ...`(更多)菜单,然后选择 :ui:`Export。
在出现的 Export Build 对话框中,从列表中选择一个目标暂存区,然后选择 Export 进行确认。
当导出过程完成后,通过选择 Close 来关闭对话框。
备注
您可以在导出过程完成之前关闭对话框。关闭对话框不会取消导出过程。
模型构建会被导出到目标暂存区中。这意味着目标暂存区目录现在包含该 Document AI 模型构建最新版本的所有文档,以及
annotations.jsonl文件。
注释文件¶
当您导出 Document AI 模型构建时,annotations.jsonl 文件会在目标暂存区目录中生成。对于每个您导出的文档,该文件包含以下信息:
file:选择使用 时默认使用的角色和仓库。文件名标识符prompt:JSON 架构,用于描述提示内容annotatedResponse:选择使用 时默认使用的角色和仓库。符合该架构格式的用户响应modelResponse:选择使用 时默认使用的角色和仓库。未被用户修改的响应
请参考 annotations.jsonl 文件中的以下示例行:
{
"file": "13c36c6a8c98acc95b797f03cc4c6d38.pdf",
"prompt": {
"type": "object",
"properties": {
"table": {
"description": "earning statement",
"type": "object",
"properties": {
"deductions": {
"description": "deductions",
"type": "array"
},
"current total": {
"description": "current total",
"type": "array"
}
}
},
"name": {
"description": "what is the name",
"type": "array"
},
"address": {
"description": "what is the address",
"type": "array"
}
}
},
"annotatedResponse": {
"table": {
"deductions": [
"9,897.82",
"CPP",
"El",
"INCOME TAX",
"UNION DUES",
"LIFE INSURANCE",
"LONG TERM DISABILITY",
"CANADA SAVING BONDS"
],
"current total": [
"None",
"65.03",
"28.62",
"305.90",
"10.84",
"4.94",
"7.01",
"8.00"
]
},
"name": [
"ACME"
],
"address": [
"200 billing rd, suite 100, needham, MA 02494"
]
},
"modelResponse": {}
}
处理导出的数据¶
导出 Document AI 模型构建后,您可以使用导出的数据创建一个表,以便进一步处理:
为注释文件创建文件格式:
CREATE OR REPLACE FILE FORMAT my_json TYPE = 'JSON';
创建表:
CREATE OR REPLACE TABLE exported_data_table AS ( SELECT input_file.$1:file AS file, input_file.$1:prompt AS prompt, input_file.$1:annotatedResponse AS response FROM '@docai_db.docai_schema.docai_stage/docai_test_2025_10_03_16_00_10/annotations.jsonl' (FILE_FORMAT => my_json) input_file WHERE response != '{}' );
现在,您可以将导出的数据转换为数据集以便在 Snowflake 中进一步使用,或使用这些数据运行 AI_EXTRACT 函数:
为导出的数据创建数据集:
CREATE DATASET my_dataset; ALTER DATASET my_dataset ADD VERSION 'v2' FROM ( SELECT CONCAT('@docai_db.docai_schema.docai_stage/docai_test_2025_10_03_16_00_10/', file) AS file, prompt, response FROM exported_data_table );
有关数据集的更多信息,请参阅 Snowflake 数据集。
使用导出的数据运行 AI_EXTRACT:
SELECT AI_EXTRACT ( file => TO_FILE('@docai_db.docai_schema.docai_stage/docai_test_2025_10_03_16_00_10', my_table.file), responseFormat => PARSE_JSON('{ "schema": ' || TO_VARIANT(my_table.prompt) || '}') ) FROM docai_db.docai_schema.exported_data_table AS my_table;