カテゴリ:

: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?']
    
  • 2つの文字列(特徴名と抽出する情報)を含む配列の配列。例:

    [['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です。

  • 出力の最大長は1つの質問あたり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