- カテゴリ:
:doc:`/sql-reference/functions-string`(AI 関数)
AI_EXTRACT¶
入力文字列またはファイルから情報を抽出します。
構文¶
入力文字列から情報を抽出する:
AI_EXTRACT( <text>, <responseFormat> )
AI_EXTRACT( text => <text>,
responseFormat => <responseFormat> )
ファイルから情報を抽出する:
AI_EXTRACT( <file>, <responseFormat> )
AI_EXTRACT( file => <file>,
responseFormat => <responseFormat> )
引数¶
text抽出用の入力文字列。
file抽出用の FILE。
サポートされているファイル形式:
PDF
PNG
PPTX、 PPT
EML
DOC、 DOCX
JPEG, JPG
HTM, HTML
TEXT, TXT
TIF, TIFF
BMP、GIF、WEBP
MD
ファイルのサイズは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?']]抽出された情報の構造を定義する JSON スキーマ。エンティティとテーブルの抽出をサポートします。例:
{ 'schema': { 'type': 'object', 'properties': { 'income_table': { 'description': 'Income for FY2026Q2', 'type': 'object', 'column_ordering': ['month', 'income'], 'properties': { 'month': { 'description': 'Month', 'type': 'array' }, 'income': { 'description': 'Income', 'type': 'array' } } }, 'title': { 'description': 'What is the title of the document?', 'type': 'string' }, 'employees': { 'description': 'What are the names of employees?', 'type': 'array' } } } }
注釈
JSON スキーマ形式を他の応答形式と組み合わせることはできません。
responseFormatに``schema`` キーが含まれている場合、すべての質問をJSON スキーマ内で定義する必要があります。追加キーはサポートされていません。このモデルは、JSON スキーマの特定の形式のみを受け入れます。最上位タイプは常に、独立して抽出されたサブオブジェクトを含むオブジェクトである必要があります。サブオブジェクトは、テーブル(列を表す文字列のリストのオブジェクト)、文字列のリスト、または文字列の場合があります。
現在サポートされているスカラー型は文字列のみです。
descriptionフィールドはオプションです。descriptionフィールドを使用して、モデルにコンテキストを提供します。たとえば、モデルがドキュメント内の正しい適切なテーブルをローカライズするのに役立ちます。Use the
column_orderingfield to specify the order of all columns in the extracted table. Thecolumn_orderingfield is case-sensitive and must match the column names defined in thepropertiesfield.
戻り値¶
抽出された情報を含む JSON オブジェクト。
配列、テーブル、単一値の抽出を含む出力の例:
{
"error": null,
"response": {
"employees": [
"Smith",
"Johnson",
"Doe"
],
"income_table": {
"income": ["$120 678","$130 123","$150 998"],
"month": ["February", "March", "April"]
},
"title": "Financial report"
}
}
アクセス制御の要件¶
ユーザーは、 SNOWFLAKE.CORTEX_USER データベースロール が付与されているロールを使用する必要があります。この権限の付与については、Cortex LLM 権限 をご参照ください。
使用上の注意¶
同じ関数呼び出しの中で、
textと``file`` の両方のパラメーターを同時に使用することはできません。自然言語で質問するか、抽出する情報(都市、通り、 ZIP コードなど)を説明できます。例:
['address': 'City, street, ZIP', 'name': 'First and last name']次の言語がサポートされています。
アラビア語
ベンガル語
ビルマ語
セブアノ語
中国語
チェコ語
オランダ語
英語
フランス語
ドイツ語
ヘブライ語
ヒンディー語
インドネシア語
イタリア語
日本語
クメール語
韓国語
ラオス語
マレー語
ペルシャ語
ポーランド語
ポルトガル語
ロシア語
スペイン語
タガログ語
タイ
トルコ語
ウルドゥー語
ベトナム語
ドキュメントは125ページ以内でなければなりません。
1回の AI_EXTRACT 呼び出しで、エンティティ抽出については最大100件、テーブル抽出については最大10件の質問を行うことができます。
テーブル抽出質問は、エンティティ抽出質問10件に相当します。たとえば、1回の AI_EXTRACT 呼び出しで、4件のテーブル抽出質問と60件のエンティティ抽出質問を行うことができます。
エンティティ抽出の最大出力長は、1問あたり512トークンです。テーブル抽出の場合、モデルは最大4096トークンの回答を返します。
クライアント側の暗号化ステージはサポートされていません。
信頼性スコアはサポートされていません。
例¶
入力文字列からの抽出¶
次の例では、入力テキストから情報を抽出しています。
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?'} );
次の例では、入力テキストから情報を抽出して解析しています。
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?"}') );
ファイルからの抽出¶
次の例では、
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?']] );
次の例では、ステージ上のすべてのファイルから情報を抽出しています。
注釈
ディレクトリテーブルが有効になっていることを確認します。詳細については、 ディレクトリテーブルの管理 をご参照ください。
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);
次の例では、
report.pdfファイルからtitle値を抽出します。SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'title': { 'description': 'What is the title of document?', 'type': 'string' } } } } );
次の例では、
report.pdfファイルからemployees配列を抽出します。SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'employees': { 'description': 'What are the surnames of employees?', 'type': 'array' } } } } );
次の例では、
report.pdfファイルからincome_tableテーブルを抽出します。SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'income_table': { 'description': 'Income for FY2026Q2', 'type': 'object', 'column_ordering': ['month', 'income'], 'properties': { 'month': { 'type': 'array' }, 'income': { 'type': 'array' } } } } } } );
次の例では、
report.pdfファイルからテーブル(income_table)、単一値(title)、配列(employees)を抽出します。SELECT AI_EXTRACT( file => TO_FILE('@db.schema.files', 'report.pdf'), responseFormat => { 'schema': { 'type': 'object', 'properties': { 'income_table': { 'description': 'Income for FY2026Q2', 'type': 'object', 'column_ordering': ['month', 'income'], 'properties': { 'month': { 'type': 'array' }, 'income': { 'type': 'array' } } }, 'title': { 'description': 'What is the title of document?', 'type': 'string' }, 'employees': { 'description': 'What are the surnames of employees?', 'type': 'array' } } } } );
リージョンの可用性¶
リージョンの可用性 をご参照ください。
法的通知¶
法的通知については、 Snowflake AI と ML をご参照ください。