Document AI is a managed Snowflake capability that extracts structured data — text, numbers, dates, and more — from unstructured documents like PDFs and images. It combines pre-trained OCR (Optical Character Recognition) and NER (Named Entity Recognition) models so you can pull required fields from invoices, receipts, contracts, and medical records directly with SQL.
ドキュメント(PDF/画像)
→ Stage(Internal or External)に格納
→ BUILD_SCOPED_FILE_URL() でファイル参照
→ Document AI モデル(PREDICT関数で推論)
→ VARIANT型の抽出結果
→ FLATTEN + SELECTで構造化テーブルに格納Document AI runs on Snowflake's Serverless Compute, so you don't have to provision a warehouse yourself. Extraction results come back as a VARIANT value, and you can access individual fields using JSON path notation.
-- Document AIモデルの作成(Snowsight UIで作成するのが推奨)
-- SQLでの作成例
CREATE OR REPLACE SNOWFLAKE.ML.DOCUMENT_INTELLIGENCE
invoice_extractor
FROM @doc_stage
USING (
SELECT
BUILD_SCOPED_FILE_URL(@doc_stage, relative_path) AS file_url
FROM DIRECTORY(@doc_stage)
WHERE relative_path LIKE '%.pdf'
LIMIT 10
);In the Snowsight UI you can visually annotate the fields (Values) you want to extract on the uploaded sample documents, then fine-tune the model from there.
| Field name | What it captures | Data type |
|---|---|---|
| invoice_number | Invoice number | VARCHAR |
| invoice_date | Invoice date | DATE |
| total_amount | Total amount | NUMBER |
| vendor_name | Vendor name | VARCHAR |
| line_items | Line items (multiple) | ARRAY |
-- BUILD_SCOPED_FILE_URL: セッションスコープの一時URL
-- Document AIのPREDICT関数への入力として最も一般的
SELECT BUILD_SCOPED_FILE_URL(
@invoice_stage,
'invoices/2026/INV-001.pdf'
) AS scoped_url;
-- BUILD_STAGE_FILE_URL: ステージ参照URL
SELECT BUILD_STAGE_FILE_URL(
@invoice_stage,
'invoices/2026/INV-001.pdf'
) AS stage_url;
-- GET_PRESIGNED_URL: 署名付きURL(外部共有用)
SELECT GET_PRESIGNED_URL(
@invoice_stage,
'invoices/2026/INV-001.pdf',
3600 -- 有効期限: 秒
) AS presigned_url;| Function | Use case | Validity scope |
|---|---|---|
| BUILD_SCOPED_FILE_URL | Snowflake-internal processing (Document AI, UDFs, etc.) | Within the session |
| BUILD_STAGE_FILE_URL | Snowflake-internal references | Valid as long as you hold stage privileges |
| GET_PRESIGNED_URL | Temporary sharing with external applications | Until the expiration you specify |
-- 単一ドキュメントの推論
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, 'invoices/INV-001.pdf')
) AS result;
-- 結果から個別フィールドを抽出
SELECT
result:invoice_number::VARCHAR AS invoice_number,
result:invoice_date::DATE AS invoice_date,
result:total_amount::NUMBER(12,2) AS total_amount,
result:vendor_name::VARCHAR AS vendor_name,
result:__confidence::FLOAT AS overall_confidence
FROM (
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, 'invoices/INV-001.pdf')
) AS result
);-- Directory Tablesと組み合わせてバッチ推論
INSERT INTO extracted_invoices (file_path, invoice_number, invoice_date, total_amount, vendor_name, confidence, extracted_at)
SELECT
d.relative_path,
r.result:invoice_number::VARCHAR,
r.result:invoice_date::DATE,
r.result:total_amount::NUMBER(12,2),
r.result:vendor_name::VARCHAR,
r.result:__confidence::FLOAT,
CURRENT_TIMESTAMP()
FROM DIRECTORY(@invoice_stage) d,
LATERAL (
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, d.relative_path)
) AS result
) r
WHERE d.relative_path LIKE '%.pdf'
AND d.relative_path NOT IN (
SELECT file_path FROM extracted_invoices
);-- FLATTEN で明細行を展開
SELECT
result:invoice_number::VARCHAR AS invoice_number,
item.value:description::VARCHAR AS item_description,
item.value:quantity::INT AS quantity,
item.value:unit_price::NUMBER(10,2) AS unit_price,
item.value:amount::NUMBER(12,2) AS line_amount
FROM (
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, 'invoices/INV-001.pdf')
) AS result
),
LATERAL FLATTEN(input => result:line_items) AS item;Each extracted field comes with a confidence score from 0.0 to 1.0. Low-confidence fields need human review, so the production best practice is to set a threshold and route anything below it to a review queue.
-- 信頼度の低い抽出結果をレビューキューに投入
INSERT INTO review_queue (file_path, field_name, extracted_value, confidence)
SELECT
relative_path,
'total_amount',
result:total_amount::VARCHAR,
result:total_amount_confidence::FLOAT
FROM extracted_results
WHERE result:total_amount_confidence::FLOAT < 0.85;| Operation | Required privileges |
|---|---|
| Creating a model | CREATE SNOWFLAKE.ML.DOCUMENT_INTELLIGENCE on the database |
| Running PREDICT | USAGE on the model plus READ on the stage |
| BUILD_SCOPED_FILE_URL | READ on the stage |
Cortex AI
問題 1
You want to extract data from PDF files in an Internal Stage using Snowflake Document AI. Which function is the most appropriate to use when passing a file to PREDICT?
正解: B
When passing a file to Document AI's PREDICT function, BUILD_SCOPED_FILE_URL() is the recommended choice. It produces a session-scoped temporary URL optimized for Snowflake-internal processing. GET_PRESIGNED_URL is meant for external sharing and is not appropriate as Document AI input. STAGE_FILE_URL and READ_FILE don't exist as functions (BUILD_STAGE_FILE_URL does exist, but BUILD_SCOPED_FILE_URL is what's recommended for PREDICT input).
Which file formats can Document AI process?
Document AI handles PDF, PNG, JPEG, and TIFF documents. Both scanned paper documents and digital PDFs are supported. Files live in a Snowflake internal or external stage and are referenced via BUILD_SCOPED_FILE_URL() or BUILD_STAGE_FILE_URL(). Check the release notes for the latest per-file size and page-count limits.
Do I need to custom-train the Document AI model?
Common fields (dates, amounts, addresses, names, etc.) can be extracted out of the box with the pre-trained model. For industry-specific formats or proprietary layouts, you can fine-tune the model in Snowsight by providing annotated samples. Annotating just 5-10 sample documents typically delivers a sizable accuracy gain.
How is Document AI billed?
Document AI is billed via Serverless Credits. Cost depends on the page count and complexity of each document, scaling roughly with the total pages processed. For high-volume workloads, the recommended approach is to validate accuracy and cost on a small sample first, then scale up to batch processing once the numbers look right.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Snowflake Certifications: All 11 Exams Explained (2026)
Every SnowPro certification — Associate, Core, Specialty, Ad...
Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)
All 11 SnowPro exams ranked by difficulty with study-time es...
Snowflake Study Guide: Fastest Pass Route by Exam (2026)
How to pass SnowPro certifications efficiently — official ma...
SnowPro Core (COF-C03): Complete Exam Guide (2026)
Pass the SnowPro Core exam — six domains, scope, sample ques...
SnowPro Associate Platform (SOL-C01): Complete Guide (2026)
The entry-level SnowPro Associate exam — scope, weighting, s...