What you will be able to do
- Pick the Cortex AI function that categorizes, extracts from, or analyzes a given kind of staged file
- Build a SQL pipeline that turns staged media into FILE references and runs multimodal AI functions over them
- Use embeddings for similarity, and semantic views for consistent business metrics and dimensions
- Estimate and monitor Cortex token spend, and cut it through model choice, input size and warehouse size
1.Cortex AI functions as SQL
Cortex AI Functions run large language models from inside a SQL statement. They let a pipeline classify, extract from, summarize and analyze text, images, documents, audio and video without the data leaving the Snowflake service perimeter. They are also available in Python. To call them, a role needs the account-level USE AI FUNCTIONS privilege plus either the CORTEX_USER or AI_FUNCTIONS_USER database role. They are built for throughput, so batch processing over large tables suits them best. Interactive, latency-sensitive work belongs on the separate Cortex REST APIs (Complete, Embed and Agents).
| Job | Functions | What they return |
|---|---|---|
| Categorize | AI_CLASSIFY, AI_FILTER | User-defined categories for text or images; True or False for use in WHERE or JOIN … ON |
| Extract from files | AI_EXTRACT, AI_PARSE_DOCUMENT, AI_TRANSCRIBE | Fields from text, images and documents; OCR or LAYOUT text from documents; transcripts with timestamps and speakers from audio and video |
| Generate | AI_COMPLETE | A completion for text or an image from a model you choose |
| Text analytics | AI_SENTIMENT, AI_SUMMARIZE, AI_AGG, AI_SUMMARIZE_AGG, AI_TRANSLATE, AI_REDACT | Sentiment, summaries, insights across many rows, translations, PII-redacted text |
| Semantic | AI_EMBED, AI_MULTI_EMBED, AI_SIMILARITY | Embedding vectors and similarity scores |
| Helpers | TO_FILE, AI_COUNT_TOKENS, PROMPT | FILE references, token counts, prompt objects |
AI_AGG and AI_SUMMARIZE_AGG are the ones to use for an aggregate question such as 'what are customers complaining about across these 40,000 tickets?'. Neither is subject to context window limits, so the whole column goes in rather than a sample. For categorization, AI_CLASSIFY assigns your labels. AI_FILTER turns a natural-language condition into a boolean you can use in a WHERE clause.
Checkpoint 1 of 5· Match them up
A pipeline team is choosing a Cortex AI function for each task. Match each function to the job it does.
Tap a term, then the definition that fits it.
AI_FILTER returns a boolean, so it belongs in WHERE or JOIN … ON. AI_CLASSIFY assigns labels instead. AI_SUMMARIZE_AGG reads a whole column without context window limits, so you don't have to sample. AI_TRANSCRIBE handles audio and video. AI_PARSE_DOCUMENT extracts OCR or LAYOUT text from documents.
“AI_FILTER: Returns True or False for a given text or image input, allowing you to filter results in SELECT, WHERE, or JOIN … ON clauses.”Source: docs.snowflake.com
Sources1
2.Multimodal extraction pipelines in SQL
Multimodal functions read files straight from internal or external stages. The usual first step is to turn a stage's directory table into a table of FILE values with TO_FILE. A FILE value holds a reference to the file and its metadata, not the file's bytes. It isn't updated when the underlying file changes or is deleted, so rebuild the table after the stage changes.
CREATE OR REPLACE TABLE video_table AS
(SELECT TO_FILE('@MY_VIDEOS', RELATIVE_PATH) AS video_file
FROM DIRECTORY(@MY_VIDEOS));| Media type | Primary functions | Common tasks |
|---|---|---|
| Documents | AI_COMPLETE, AI_PARSE_DOCUMENT, AI_EXTRACT | Q&A, summarization, extraction, comparison, chart understanding |
| Images | AI_COMPLETE, AI_CLASSIFY, AI_EMBED, AI_EXTRACT, AI_SIMILARITY, AI_FILTER | Caption, compare, classify, extract entities, image search |
| Audio | AI_COMPLETE, AI_TRANSCRIBE | Caption, compare, classify, extract entities, transcribe, identify speakers |
| Video | AI_COMPLETE, AI_TRANSCRIBE, AI_MULTI_EMBED | Summarize, classify, extract metadata, search scenes, transcribe |
For structured extraction, pass the FILE value to AI_COMPLETE with a multimodal model and a response format of {'type': 'json', 'schema': ...}. The schema lists the fields you want, for example sentiment, summary, an array of brands and a boolean harmful_content_detected, and marks which are required. Each video then returns one JSON object that downstream SQL can query like any other semi-structured value. Audio and video processing through AI_COMPLETE is in public preview; the other multimodal capabilities are generally available.
Text analytics often runs as a chain. The first step converts media to text, and the second analyzes that text. AI_TRANSCRIBE takes a staged audio or video file and returns JSON with the duration and transcript. A later AI_COMPLETE call, with its prompt built by PROMPT, then reads the transcript.
SELECT AI_TRANSCRIBE(TO_FILE('@podcast_videos_S3', 'podcast-interview.mp4'));SELECT
AI_COMPLETE('claude-sonnet-4-5',
PROMPT('Return a list of any Retail Brands mentioned in this podcast {0}',
TO_VARCHAR(transcription_results))) AS brands_identified
FROM podcast_video_transcription;Checkpoint 2 of 5· Check yourself
A marketing team stores thousands of ad videos on an external stage that has a directory table. They want one queryable JSON record per video, with sentiment, a summary, the brands shown and a harmful-content flag. Which approach produces this inside SQL?
Multimodal functions read files where they sit on the stage through FILE references built with TO_FILE from the directory table. AI_COMPLETE with a {'type': 'json', 'schema': ...} response format returns one structured object per video. AI_CLASSIFY only assigns labels, Snowflake doesn't load unstructured files into rows, and RELATIVE_PATH is just a path, not the video's content.
“a table is first created from staged video files using the FILE data type. The query then calls AI_COMPLETE with a multimodal model”Source: docs.snowflake.com
3.Semantic analysis: embeddings and semantic views
Embeddings support semantic analysis: finding content that means the same thing even when the words differ. AI_EMBED turns text or an image into a vector. Vector comparison functions then measure how close two vectors are, which is how a pipeline finds similar documents, clusters them, or classifies them. AI_SIMILARITY does both steps at once, returning the embedding similarity of two inputs directly. For video, AI_MULTI_EMBED with the Twelve Labs Marengo 3 model turns each video into one or more 512-dimensional vectors with segment metadata. You store those vectors in a table and search them with SQL to find a scene, for example a man riding a skateboard.
Semantic views take a different approach. They capture the meaning of business data rather than the meaning of content. A semantic view is a schema-level object, treated as metadata, that maps physical columns to business concepts. A column named amt_ttl_pre_dsc becomes gross revenue. Net revenue is defined once as SUM(gross_revenue * (1 - discount)) instead of being recalculated, sometimes wrongly, in dozens of reports. Inside a semantic view, logical tables stand for business entities such as customers or orders and are related through joins on shared keys. Each logical table defines three kinds of element:
- Facts: row-level values, such as one sale's amount, that mostly help build the other two.
- Metrics: aggregated KPIs such as Total Revenue, built with SUM, AVG or COUNT across rows.
- Dimensions: categorical attributes such as date, product category or region, used to group and filter metrics.
You query a semantic view in a SELECT statement. Cortex Agents read its definition to generate SQL against the physical tables, combining LLM reasoning with rule-based definitions. You can also share it through private, public Marketplace, or organizational listings. You create one with CREATE SEMANTIC VIEW, with Semantic Studio in Workspaces, or with a Snowsight wizard.
Net Revenue is the metric: an aggregation over facts, defined once with the correct formula. Region is the dimension, the categorical attribute that the metric is grouped by.
Checkpoint 3 of 5· Check yourself
An audit finds that 'net revenue' is calculated differently across dozens of reports, and a Cortex Agent now has to answer revenue questions the same way every time. What should the data engineer build?
Semantic views record what business data means. A metric defines the aggregation once and correctly, and Cortex Agents read that definition to generate SQL. Embeddings measure how similar content is, not whether a calculation is correct. Facts are row-level helpers, so leaving the aggregation to each report brings back the inconsistency. Labelling columns doesn't fix any formula.
“the semantic view can define it consistently as a metric with the correct aggregation: SUM(gross_revenue * (1 - discount))”Source: docs.snowflake.com
4.Managing Cortex AI cost
Cortex AI functions are billed by tokens processed, priced in credits per million tokens per function. That pricing is on top of the cost of keeping the warehouse running. For text, a token is roughly four characters, though this varies by model. The functions differ in which tokens count, and those differences determine what a pipeline really costs.
| Function | Billed on |
|---|---|
| AI_COMPLETE, AI_CLASSIFY, AI_FILTER, AI_AGG, AI_SUMMARIZE, AI_TRANSLATE | Input and output tokens |
| AI_EMBED, AI_SIMILARITY | Input tokens only |
| AI_CLASSIFY | Labels, descriptions and examples counted as input tokens for every record |
| AI_PARSE_DOCUMENT | Document pages processed |
| AI_EXTRACT | Input and output tokens; responseFormat counts as input; each document page counts as 970 tokens |
| Audio input | 50 tokens per second of audio |
| AI_COUNT_TOKENS | Compute only; no token-based cost |
Functions such as AI_CLASSIFY, AI_SENTIMENT and AI_SUMMARIZE_AGG add their own prompt to your input, so the billed count is higher than the text you supply. The biggest savings come from the inputs: keep classification labels short, since they are billed again on every row, trim documents before sending them, and run AI_COUNT_TOKENS first to check that a call fits the model's limit.
Monitoring works at three levels of detail. METERING_DAILY_HISTORY filtered to SERVICE_TYPE='AI_SERVICES' shows daily AI credits for the account. CORTEX_FUNCTIONS_USAGE_HISTORY shows credits and tokens per function call. CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY shows them per query, and you can filter it by query_id to find the most expensive statements. The per-query view has one row for each model used in a query. Running the same prompt through mistral-7b and mistral-large therefore shows the cost of each model side by side, which is the evidence you need to move a workload to a cheaper model. Requests made through the Cortex REST APIs don't get this per-query detail.
SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY
WHERE SERVICE_TYPE='AI_SERVICES';Checkpoint 4 of 5· Fill the gap
A FinOps analyst wants daily credits for all AI services in the account, including Cortex AI functions. Which view completes this query?
SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE. ?
WHERE SERVICE_TYPE='AI_SERVICES';METERING_DAILY_HISTORY, filtered to SERVICE_TYPE='AI_SERVICES', gives daily AI credits for the whole account. CORTEX_FUNCTIONS_USAGE_HISTORY gives the finer per-call detail, and CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY gives per-query detail. PIPE_USAGE_HISTORY shows Snowpipe charges, such as automatic directory table refreshes.
Source: docs.snowflake.comCheckpoint 5 of 5· Check yourself
Each category label in an AI_CLASSIFY job over two million tickets has a long description and several examples. Which change cuts the job's token bill the most?
AI_CLASSIFY counts its labels, descriptions and examples as input tokens on every record, so their length gets multiplied by two million. AI_CLASSIFY bills both input and output tokens, and warehouse size doesn't change how many tokens are billed.
“AI_CLASSIFY labels, descriptions, and examples are counted as input tokens for each record processed, not just once for each AI_CLASSIFY call.”Source: docs.snowflake.com
Sources6
Practise it for real
Build a small pipeline that catalogs staged audio files and transcribes one of them in SQL
1.Create an internal stage with ENCRYPTION = (TYPE = 'SNOWFLAKE_SSE') and DIRECTORY = ( ENABLE = true ), then PUT a few audio files onto it.
Why: Server-side encryption keeps the files readable through URLs, and the directory table gives you a catalog of the files.
You should see: The stage exists. Its directory table may still be empty, because nothing has refreshed it yet.
2.Run ALTER STAGE on the stage with REFRESH, then SELECT * FROM DIRECTORY(@your_stage).
Why: Directory tables on internal stages register new files only when refreshed manually.
You should see: One row per file, with RELATIVE_PATH, SIZE, LAST_MODIFIED, MD5, ETAG and FILE_URL.
3.Create a table of FILE values with TO_FILE('@your_stage', RELATIVE_PATH) selected FROM DIRECTORY(@your_stage).
Why: Multimodal functions accept FILE references to staged files.
You should see: One FILE value per staged audio file.
4.Call AI_TRANSCRIBE on one FILE value, then query SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY for that query_id once usage data appears.
Why: The cost view connects the call to the tokens it consumed: audio is billed at 50 tokens per second.
You should see: A JSON transcript with audio_duration and text, and a usage row showing the credits and tokens for the query.
Stuck? Get a nudge
If DIRECTORY returns no rows after the PUT, check whether you ran the refresh.
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“your role needs the USE AI FUNCTIONS account-level privilege and one of the CORTEX_USER or AI_FUNCTIONS_USER database roles”
↩︎ Cortex AI functions as SQL“AI_CLASSIFY: Classifies text or images into user-defined categories.”
↩︎ Cortex AI functions as SQL“For more interactive use cases where latency is important, use the REST API.”
↩︎ Cortex AI functions as SQL“AI_FILTER: Returns True or False for a given text or image input, allowing you to filter results in SELECT, WHERE, or JOIN … ON clauses.”
↩︎ Checkpoint - 2.
“These functions process files stored on internal or external stages, extracting insights from textual, visual, and audio signals.”
↩︎ Multimodal extraction pipelines in SQL“You can define the exact schema you want the model to return”
↩︎ Multimodal extraction pipelines in SQL“The Twelve Labs Marengo 3 embedding model converts each video into one or more 512-dimensional vectors”
↩︎ Semantic analysis: embeddings and semantic views“a table is first created from staged video files using the FILE data type. The query then calls AI_COMPLETE with a multimodal model”
↩︎ Checkpoint - 3.
“FILE values are not updated when you modify or delete the underlying file.”
↩︎ Multimodal extraction pipelines in SQL - 4.
“This vector can be used with the vector comparison functions to determine the semantic similarity of two documents.”
↩︎ Semantic analysis: embeddings and semantic views - 5.
“You can store semantic business concepts directly in the database in a Semantic View, which is a schema-level object.”
↩︎ Semantic analysis: embeddings and semantic views“Metrics are quantifiable measures of business performance calculated by aggregating facts or other columns from the same table”
↩︎ Semantic analysis: embeddings and semantic views“You can use Semantic Views in Cortex Agents and query these views in a SELECT statement.”
↩︎ Semantic analysis: embeddings and semantic views“the semantic view can define it consistently as a metric with the correct aggregation: SUM(gross_revenue * (1 - discount))”
↩︎ Checkpoint - 6.
“Snowflake Cortex AI functions incur compute cost based on the number of tokens processed.”
↩︎ Managing Cortex AI cost“Each page in a document is counted as 970 tokens.”
↩︎ Managing Cortex AI cost“The query usage history is grouped by the models used in the query.”
↩︎ Managing Cortex AI cost“AI_CLASSIFY labels, descriptions, and examples are counted as input tokens for each record processed, not just once for each AI_CLASSIFY call.”
↩︎ Exam trap 1“Snowflake recommends using a warehouse size no larger than MEDIUM when calling Snowflake Cortex AI Functions.”
↩︎ Exam trap 2“Using a larger warehouse than necessary does not increase performance, but can result in unnecessary costs.”
↩︎ Prediction“AI_CLASSIFY labels, descriptions, and examples are counted as input tokens for each record processed, not just once for each AI_CLASSIFY call.”
↩︎ Checkpoint