ドキュメントを使用したAI_COMPLETE

Cortex AI_COMPLETE関数は、PDF、Microsoft Word、およびその他のドキュメントファイル形式に保存されたデータを理解できる汎用的なAI関数です。AI_COMPLETEを使用して、次のようなさまざまなドキュメントデータ抽出タスクを実行できます。

  • グラフやチャートの中のデータを使用して質問に答える。

  • チャートとドキュメントテキストの関係を見つける。

  • 特定の質問に対してドキュメントの内容を要約する。

  • ドキュメントからエンティティを抽出する。

AI_COMPLETEが他の:doc:`ドキュメント処理AI関数<ai-documents>`に比べて優れている点は、モデルを選択できる能力です。これにより、特定のドキュメント処理タスクに最適なモデルを使用できます。

AI_COMPLETEを使用したドキュメントの処理

COMPLETE関数は、内部Snowflakeステージまたは外部ステージに保存されたドキュメントファイルを処理します。完了プロンプトでは、単一のドキュメントまたは複数のドキュメントを参照できます。たとえば、マーケティング資料の翻訳の正確性を比較するには、モデルに翻訳品質を評価するよう求めるプロンプトとともに、オリジナルのドキュメントと翻訳されたドキュメントを関数に入力します。

関数を呼び出す際には、使用するモデルとプロンプトを指定する必要があります。プロンプトには、指示とともに、処理する各ドキュメントのFILEオブジェクト参照が含まれている必要があります。サンプルプロンプトとその実行については`例`_を、関数呼び出し構文については:doc:`/sql-reference/functions/ai_complete-prompt-object`をご参照ください。

入力要件

AI_COMPLETE はデジタル作成およびスキャン済みドキュメントの両方に最適化されています。次のテーブルは、入力ドキュメントの制限と要件のリストです。

サポートされているファイルタイプ

すべてのモデル(.txt、.md、.pdf)
Claudeモデル(.txt、.md、.pdf、.doc、.docx、.xls、.xlsx、.csv、.xhtml)

ステージ暗号化

サーバー側の暗号化

データ型

:doc:`FILE </sql-reference/functions/to_file>`オブジェクト

注釈

現在、AI_COMPLETEを使用したステージからのファイルの処理はカスタムネットワークポリシーと互換性がありません。

次の例は、AI_COMPLETEを使用して3つの一般的なユースケース(チャートQ&A、コンテキスト化されたドキュメントの要約、技術レポートの探索)のドキュメント処理を実行する方法を示しています。

チャートQ&Aの例

「Breaking the Gridlock」EUレポートのタイトルページ

次の例では、AnthropicのClaude Opus 4モデルを使用して、``@docs``ステージに保存されているドキュメント``hdr2023-24snapshoten.pdf``のコンテキスト内で、チャートに表現されたデータを分析します。

SELECT AI_COMPLETE(
  MODEL => 'claude-4-opus',
  PROMPT => PROMPT('Compare the distributions of HDI in each group: low HDI group, medium HDI group, high HDI group and very high HDI group visualized in {0}', TO_FILE('@docs', 'hdr2023-24snapshoten.pdf'))
);

応答:

Looking at the document, I can see Figure S.2 on page 6 which shows the recovery of HDI values since the 2020-2021
decline across different HDI groups. The visualization shows:

**Low HDI group**:
- 49% recovered
- 51% did not recover

**Medium HDI group**:
- The document doesn't provide specific recovery percentages for this group in the figure

**High HDI group**:
- The document doesn't provide specific recovery percentages for this group in the figure

**Very high HDI group**:
- 100% recovered (all OECD countries)

The document also provides additional insights about HDI distributions:

1. **Inequality trends** (Figure S.3, page 7): The inequality between very high HDI and low HDI countries has been
   increasing since 2020, reversing a long-term declining trend. The difference in HDI values between these groups
   increased from 0.38 in 2017 to 0.39 in 2020 and is projected to continue rising.

2. **Overall recovery patterns**: The text notes that "every Organisation for Economic Co-operation and Development
   country is projected to have recovered, but only about half of the Least Developed Countries are projected to have
   done so."

3. **Global HDI trajectory**: While the global HDI value is projected to reach a record high in 2023, it remains below
   its pre-2019 trend, suggesting a permanent shift in the development trajectory.

The document emphasizes the highly unequal nature of recovery across HDI groups, with countries in higher HDI
categories showing much stronger recovery rates than those in lower HDI categories.

コンテキスト化されたドキュメントの要約の例

EU決議1008/2008の最初のページ

次の例では、AnthropicのClaude Sonnet 4モデルを使用して、複雑なレイアウトの法的テキストの要約を抽出します。ドキュメント``CELEX_32008R1008_EN_TXT.pdf``は@docsステージに保存されます。プロンプトは要約のコンテキストを絞り込みます。

SELECT AI_COMPLETE(
  MODEL => 'claude-4-sonnet',
  PROMPT => PROMPT('summarize the changes from the perspective of private aviation {0}', TO_FILE('@docs', 'CELEX_32008R1008_EN_TXT.pdf'))
);

応答:

From a private aviation perspective, this EU Regulation 1008/2008 introduces several significant changes that affect
private operators and business aviation:

## Key Changes Affecting Private Aviation:

### **Operating License Requirements**
- **Stricter financial oversight**: Private operators must demonstrate they can meet financial obligations for 24
  months from start of operations, with enhanced monitoring during the first two years
- **Simplified requirements for smaller operators**: Aircraft under 10 tonnes MTOM and/or less than 20 seats need
  only demonstrate €100,000 net capital (unless operating scheduled services or exceeding €3 million turnover)

### **Aircraft Registration and Leasing**
- **Flexible registration**: Private operators can register aircraft either in their home Member State or anywhere within the Community

- **Wet lease restrictions**: Stricter limitations on wet leasing aircraft from third countries, requiring prior
  approval and justification based on:
  - Exceptional needs (up to 7 months, renewable once)
  - Seasonal capacity requirements
  - Operational difficulties when EU-registered aircraft unavailable
- **Safety equivalence**: All third-country leased aircraft must meet equivalent safety standards to EU requirements.

### **Enhanced Supervision**

- **Unified oversight**: The same Member State authority now oversees both the Air Operator Certificate (AOC) and
  operating license, improving efficiency for operators with bases in multiple countries
- **Regular assessments**: Mandatory financial reviews, particularly after two years of operation and when potential
  problems are suspected

### **Insurance Requirements**
- **Extended coverage**: Insurance requirements now explicitly include mail liability coverage in addition to
  passengers, cargo, and third parties

### **Operational Flexibility**
- **Code-sharing freedom**: Private operators can more freely enter into code-share arrangements on intra-Community
  routes and routes to third countries
- **Pricing freedom**: Complete freedom to set fares and rates for intra-Community services

### **Administrative Streamlining**
- **Consolidated regulation**: The three separate regulations are now combined into one comprehensive framework,
  simplifying compliance
- **Reduced bureaucracy**: Member States cannot require documents already provided to licensing authorities

These changes generally **liberalize** private aviation operations within the EU while **strengthening** financial
and safety oversight, creating a more integrated and competitive market for private operators.

技術レポートの探索

75mm砲仕様書の最初のページ

次の例では、Gemini 3 Proモデルを使用して、技術レポートの図に表される死傷者データを分析します。ドキュメント``75mm-M3-spec-booklet-MK-VI.pdf``は``@docs``ステージに保存されます。

SELECT AI_COMPLETE(
  MODEL => 'gemini-3-pro',
  PROMPT => PROMPT('explain findings from figures 69-73 of {0}', TO_FILE('@docs', '75mm-M3-spec-booklet-MK-VI.pdf'))
);

応答:

Based on the provided document, specifically **page 4**, here is an explanation of the findings from Figures 69
through 73. These figures illustrate the fragmentation patterns and effectiveness of the **75-mm Shell, H.E., M48**
when fired from an M3 Gun. They visualize how dangerous the shell is to personnel (casualties) and equipment
(perforation of mild steel) at different burst heights and orientations.

サポートされているモデルと制限事項

Snowflake Cortexで利用可能なすべてのモデルには、モデルの*コンテキストウィンドウ*として知られる入力および出力トークンの総数に制限があります。コンテキストウィンドウのサイズはトークンで測定されます。コンテキストウィンドウの制限を超える入力はエラーになります。

テキストモデルの場合、トークンは一般的に約4文字のテキストを表します。制限に対応する単語数は、トークンで指定されたコンテキストウィンドウよりもやや少なくなります。画像モデルの場合、1ドキュメントあたりのトークン数はビジョンモデルのアーキテクチャに依存します。プロンプト内のトークン(例:「このドキュメントを要約してください」)も、モデルのコンテキストウィンドウに影響します。

モデル

コンテキストウィンドウ(トークン)

ファイルタイプ

ファイルサイズ

1プロンプトあたりのドキュメント

gemini-3-pro

1,000,000

.pdf, .txt, .md

10MB、最大900ページ

20

claude-3-7-sonnet

200,000

.txt, .md, .pdf, .doc, .docx, .xls, .xlsx, .csv, .xhtml

4.5MB

5

claude-4-sonnet

200,000

.txt, .md, .pdf, .doc, .docx, .xls, .xlsx, .csv, .xhtml

4.5MB

5

claude-4-opus

200,000

.txt, .md, .pdf, .doc, .docx, .xls, .xlsx, .csv, .xhtml

4.5MB

5

claude-haiku-4-5

200,000

.txt, .md, .pdf, .doc, .docx, .xls, .xlsx, .csv, .xhtml

4.5MB

5

claude-sonnet-4-5

200,000

.txt, .md, .pdf, .doc, .docx, .xls, .xlsx, .csv, .xhtml

4.5MB

5

claude-opus-4-5

200,000

.txt, .md, .pdf, .doc, .docx, .xls, .xlsx, .csv, .xhtml

4.5MB

5

アクセス制御の要件

さらに、 AI_COMPLETE 関数を使用するには、 ACCOUNTADMIN ロールは、 SNOWFLAKE.CORTEX_USER データベースロールを関数を呼び出せるユーザーに付与する必要があります。詳細については Cortex LLM 権限 をご参照ください。

ユーザーは、処理対象のステージとファイルへのREADアクセス権限も持っている必要があります。

コストの考慮事項

コストはファイルサイズではなく、処理された:ref:`トークン<label-cortex_llm_cost_considerations>`の総数によって決まります。ドキュメントがアップロードされると、テキストコンテンツが抽出され、トークンに変換されます。ビジュアルページセグメント(画像)もトークンに変換されます。請求は、入力トークン数(モデルが読み取るテキストと画像)と出力トークン数(モデルが生成するテキスト)の合計に基づいて行われます。

実際のトークン数は、モデルの基になるアーキテクチャや、ドキュメントの構成と構造によって異なります。高密度のテーブル、スプレッドシート、構造化データ、コード、ヘッダーとフッターの繰り返し、またはOCRで読み取ったテキストのようなコンテンツではトークン量が増大する可能性があります。逆に、抽出可能なテキストの量が限られている、画像量の多いドキュメントやスライドベースのドキュメントでは、トークン数が少なくなる場合があります。

注釈

現時点で、AI_COUNT_TOKENS関数はマルチモーダルモデルのドキュメント入力をサポートしていません。

モデルの選択

`MMLongBench-Doc <https://proceedings.neurips.cc/paper_files/paper/2024/hash/ae0e43289bffea0c1fa34633fc608e92-Abstract-Datasets_and_Benchmarks_Track.html>`_ベンチマークは、クロスページ情報検索を含む、マルチモーダルおよび長いコンテキストの理解において、モデルの機能を評価するために使用されます。

モデル

MMLongBench-Docスコア

claude-3-5-sonnet

46.8%

claude-3-7-sonnet

52.8%

claude-4-sonnet

50.2%

claude-4-opus

53.0%

claude-haiku-4-5

48.9%

claude-sonnet-4-5

61.4%

claude-opus-4-5

63.8%

claude-sonnet-4-6

62.3%

gemini-3-pro

60.5%

リージョンの可用性

リージョンの可用性 をご参照ください。

エラー条件

Snowflake Cortex AI_COMPLETE は以下のエラーメッセージを生成する可能性があります。

メッセージ

説明

_COMPLETE_WITH_PROMPT_HISTORY_LLM$V1 with remote service error:400 '"invalid request parameters: unsupported document content type: application/vnd.ms-excel"

選択されたファイルタイプはサポートされていません(この例ではMicrosoft Excelファイル)。ExcelファイルはClaudeモデルでのみサポートされています。

Request failed for external function _COMPLETE_WITH_PROMPT_HISTORY_LLM$V1 with remote service error:400 '"invalid request parameters:File data exceeds the limit of 10.00 MB for file prefix/file.pdf"

ファイルサイズの制限(この例では10MB)を超えています。

Remote file '@docs/file.pdf' was not found.可能性のある原因がいくつかあります。ファイルが存在しない。必要な認証情報が欠如しているか無効。コピーコマンドを実行している場合、ファイルがロードされているときにファイルが削除されていないこと、またはファイルが自動パージオプションと同時に2つの異なるテーブルにロードされていないことを確認してください。

ファイル名にエラーがある可能性があります。ファイル名では大文字と小文字が区別されます。または、ファイルが削除されている可能性があります。

セキュアオブジェクトのエラー

ステージが存在しないことを示す場合があります。ステージ名を確認し、ステージが存在していてアクセス可能であることを確認します。ステージ名の先頭には、必ずアットマーク(@)を使用します。ステージがサーバー側の暗号化を使用していることを確認します。

Request failed for external function COMPLETE$V6 with remote service error:400 '"model "model_name" does not support given modality"

リクエストで指定されたモデルは、ドキュメントまたはテキストのモダリティをサポートしていません。

Request failed for external function _COMPLETE_WITH_PROMPT with remote service error:500 '"internal error"

サーバー側でのリクエスト処理に関する問題。ファイルが破損しているか、切り捨てられている場合があります。