类别:

:doc:`/sql-reference/functions-string`(AI 函数)

AI_EXTRACT

从输入字符串或文件中提取信息。

语法

从输入字符串中提取信息:

AI_EXTRACT( <text>, <responseFormat> )
Copy
AI_EXTRACT( text => <text>,
            responseFormat => <responseFormat> )
Copy

从文件中提取信息:

AI_EXTRACT( <file>, <responseFormat> )
Copy
AI_EXTRACT( file => <file>,
            responseFormat => <responseFormat> )
Copy

实参

text

用于提取的输入字符串。

file

用于提取的 FILE

支持的文件格式:

  • PDF

  • PNG

  • PPTX

  • EML

  • DOC、DOCX

  • JPEG、JPG

  • HTM、HTML

  • TEXT、TXT

  • TIF、TIFF

文件的大小必须小于 100 MB。

responseFormat

信息将以下列响应格式之一提取:

  • 简单对象架构,用于映射特征名称和待提取信息,例如:

    {'name': 'What is the last name of the employee?', 'address': 'What is the address of the employee?'}
    
  • 包含要提取的信息的字符串数组,例如:

    ['What is the last name of the employee?', 'What is the address of the employee?']
    
  • 包含两个字符串(功能名称和要提取的信息)的数组的数组,例如:

    [['name', 'What is the last name of the employee?'], ['address', 'What is the address of the employee?']]
    
  • 包含要提取的功能名称和信息的字符串数组,以冒号(“:”)分隔,例如:

    ['name: What is the last name of the employee?', 'address: What is the address of the employee?']
    

备注

您可以用自然语言提问,也可以描述要提取的信息(例如城市、街道、ZIP 代码),例如:

['address': 'City, street, ZIP', 'name': 'First and last name']

返回

包含所提取信息的 JSON 对象。

访问控制要求

用户必须使用已被授予 SNOWFLAKE.CORTEX_USER 数据库角色 的角色。有关授予此权限的信息,请参阅 所需权限

使用说明

  • 支持以下语言:

    • 阿拉伯语

    • 孟加拉语

    • 缅甸语

    • 宿务语

    • 中文

    • 捷克语

    • 荷兰语

    • 英语

    • 法语

    • 德语

    • 希伯来语

    • 印地语

    • 印尼语

    • 意大利语

    • 日语

    • 高棉语

    • 韩语

    • 老挝语

    • 马来语

    • 波斯语

    • 波兰语

    • 葡萄牙语

    • 俄语

    • 西班牙语

    • 他加禄语

    • 泰语

    • 土耳其语

    • 乌尔都语

    • 越南语

  • 文档的长度不得超过 125 页。

  • 可以提取的特征数上限为 100。

  • 每个问题的最大输出长度为 512 个词元。

  • 要提取列表,请在每个问题的开头添加 List:。例如:

    [['languages', 'List: What languages are supported for AI_EXTRACT?']]
    
  • 在使用通过冒号分隔特征名称和待提取信息的响应格式时,特征名称内不能包含冒号(“:”),例如:

    ['location: Where does the employee live?', 'name:employee: What is the first name of the employee?']
    
  • 不支持置信度分数。

示例

以下示例从输入文本中提取信息:

SELECT AI_EXTRACT(
 text => 'John Smith lives in San Francisco and works for Snowflake',
 responseFormat => {'name': 'What is the first name of the employee?', 'city': 'What is the address of the employee?'}
);
Copy

以下示例从输入文本中提取和解析信息:

SELECT AI_EXTRACT(
 text => 'John Smith lives in San Francisco and works for Snowflake',
 responseFormat => PARSE_JSON('{"name": "What is the first name of the employee?", "address": "What is the address of the employee?"}')
);
Copy

以下示例从 document.pdf 文件中提取信息:

SELECT AI_EXTRACT(
  file => TO_FILE('@db.schema.files','document.pdf'),
  responseFormat => [['name', 'What is the first name of the employee?'], ['city', 'Where does the employee live?']]
);
Copy

以下示例从暂存区上的所有文件中提取信息:

SELECT AI_EXTRACT(
  file => TO_FILE('@db.schema.files', relative_path),
  responseFormat => [
    'What is this document?',
    'How would you classify this document?'
  ]
) FROM DIRECTORY (@db.schema.files);
Copy
语言: 中文