btay.io/wiki

Snowflake Cortex AI: A Working Engineer's Guide

Implementation-level Cortex reference — product map, setup, AISQL functions, Cortex Search, the token cost model, monitoring queries, governance, and gotchas.

Updated 44 min ago

Current as of July 30, 2026. Pricing and preview status change monthly — always confirm rates against Snowflake's Service Consumption Table, not this doc.

For the non-technical orientation — strategy, skepticism, and the questions to ask before approving anything — see Snowflake Cortex AI: The Big Picture.


The one-paragraph version

Cortex AI is Snowflake's managed AI layer. Models run inside the Snowflake perimeter against data already in your account, so there are no GPUs to provision, no pipelines to move data to a model provider, and no separate serving infrastructure. You call it from SQL. Snowflake hosts frontier models from OpenAI, Anthropic, Meta, and Mistral rather than pushing a house model, so the choice you make is "which model for this task," not "which vendor for my company." The strategic pitch in 2026 is that Snowflake owns the data, governance, and orchestration layer, and you pick the model.

The thing that will actually bite you

Cost is token-based and model choice swings the bill by 40x or more. Everything else in this doc is secondary to that.


Part 1 — The product map

Cortex AI is marketed as one thing but is really five, with different billing, maturity, and audiences. Keep them separate.

LayerWhat it isWho uses itBilling
AISQL functionsSQL-callable AI primitives (AI_COMPLETE, AI_CLASSIFY, AI_EMBED, etc.)Data engineers, analystsStandard Snowflake credits, per token
Cortex SearchManaged hybrid retrieval (semantic + keyword) for RAG and fuzzy matchingEngineers building appsPer-GB-indexed serving + warehouse for indexing
Cortex AnalystText-to-SQL over a governed semantic modelAnalysts, embedded apps67 credits per 1,000 messages (standalone API) or per-token via Agents
Cortex AgentsMulti-step orchestration across Search + Analyst + toolsApp buildersAI Credits, per token
CoWork / CoCoEnd-user surfaces: business agent and engineering IDEBusiness users / engineersAI Credits, per token

The 2026 renames (important, because docs and blogs disagree)

At Summit 26 (June 1–4, San Francisco), Snowflake renamed two of its flagship surfaces:

  • Snowflake Intelligence → Snowflake CoWork. The business-user agent interface. Natural-language querying of governed data, multi-step research, publishable conversational dashboards ("Artifacts"), and actions across Slack, Google Drive, and Salesforce via MCP connectors (Gmail and Jira announced as coming).
  • Cortex Code → CoCo. The engineer-facing environment, closer to an IDE than a chatbot. Builds Streamlit apps, pipelines, SQL, and dbt models.

Also announced at Summit 26, and worth tracking rather than adopting:

  • Cortex Sense — a runtime context layer that auto-assembles business meaning from query history, object metadata, BI dashboard definitions (Power BI, Tableau), and semantic views, then injects it into agent responses. Snowflake's internal testing claims it lifts CoWork/CoCo accuracy on complex enterprise queries from 47% to 83%. It was private preview as of June 2026, and the accuracy figure is vendor-internal and unreplicated. Treat as directional.
  • Horizon Context, Semantic Studio, Semantic View Autopilot — the governed semantics stack. Semantic View Autopilot automatically refines semantic views.
  • Cortex Training — custom training of open-weight models on managed GPUs.
  • AI Agent Identity (GA) and AI Security Posture Management — governance for what agents may read, write, and act on.
  • Natoma acquisition — MCP governance for agentic access to SaaS systems, with audit trails and verified agent identity.

The model catalog

The February 2, 2026 OpenAI partnership ($200M, multi-year) put OpenAI frontier models including GPT-5.2 natively inside Cortex across AWS, Azure, and GCP. Anthropic's Claude and Meta's Llama models are available too, alongside Snowflake-optimized variants of open-weight models. Model availability is region-specific — see cross-region inference below.


Part 2 — Setup and prerequisites

Three things gate access. Do these before you debug anything else.

1. Grant the role

GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE analytics_engineer;

Related roles you may need:

  • SNOWFLAKE.CORTEX_AGENT_USER — for Cortex Agents
  • SNOWFLAKE.COPILOT_USER — required (alongside CORTEX_USER or CORTEX_AGENT_USER) for CoCo

Note: if your account previously opted out of legacy Snowflake Copilot, CoCo is disabled and needs an account-team unlock.

2. Enable cross-region inference

Many models, especially the newest Claude and GPT releases, are not available in every region. The default is DISABLED, meaning calls to an unavailable model simply fail.

USE ROLE ACCOUNTADMIN;

-- Options: DISABLED (default) | AWS_US | AWS_EU | AWS_APJ | AZURE_US | AZURE_EU | ANY_REGION
-- Comma-separate to allow multiple
ALTER ACCOUNT SET CORTEX_ENABLED_CROSS_REGION = 'AWS_US';

Facts worth knowing:

  • Account level only. Cannot be set per-user or per-session. ACCOUNTADMIN only; ORGADMIN cannot set it.
  • No data egress charges. Credits are billed in the requesting region, not the processing region.
  • Latency increases with distance. Test before committing a latency-sensitive workload.
  • AWS_US is Snowflake's recommendation for the widest model coverage.
  • Cortex Search does not support cross-region inference in all regions.

3. Check model-level access control

Accounts can disable specific models. If a model call fails even with cross-region enabled, check the account's AI model access settings. Relevant for Cortex Analyst, which picks from a preference-ordered list of models — disabling models reduces its fallback options and raises failure risk.


Part 3 — AISQL function reference

These are the workhorses. Serverless, no orchestration, callable from SQL or Python.

FunctionDoesNotes
AI_COMPLETEGeneral text/image generationYou pick the model. The main cost lever lives here.
AI_CLASSIFYClassify text or images into your categoriesCheaper and more consistent than prompting AI_COMPLETE for the same job
AI_FILTERReturns booleanUsable in WHERE and JOIN … ON — semantic joins in plain SQL
AI_AGGAggregate a text column and reason across rowsNot bound by the model's context window
AI_EMBEDEmbedding vectors for text or imagesInput tokens only, so much cheaper than generation
AI_SIMILARITYSimilarity between two inputsGood candidate-ranking step ahead of deterministic matching
AI_EXTRACTStructured extraction from unstructured contentAsk for a response schema rather than free text
AI_PARSE_DOCUMENTLayout-aware document parsingPair with TO_FILE for staged files
AI_TRANSCRIBEAudio to text
AI_SENTIMENTSentiment scoringTask-specific, no prompt needed
AI_TRANSLATETranslation
AI_COUNT_TOKENSToken count for an inputUse this before every batch job.
TO_FILEReference a staged file for use in other functions

Legacy equivalents still exist under SNOWFLAKE.CORTEX.* (COMPLETE, SUMMARIZE, EXTRACT_ANSWER, COUNT_TOKENS). New work should use the AI_* forms.

Minimal examples

-- Classification with your own taxonomy
SELECT
    case_id,
    AI_CLASSIFY(case_notes, ['billing', 'performance', 'onboarding', 'service', 'other']) AS topic
FROM silver.crm_cases;

-- Semantic filter in a WHERE clause
SELECT activity_id, subject
FROM silver.crm_activities
WHERE AI_FILTER(CONCAT('Does this describe a fee or billing complaint? ', subject));

-- Structured extraction with a response schema
SELECT
    doc_id,
    AI_EXTRACT(
        file => TO_FILE('@stage_docs', file_name),
        responseFormat => {
            'account_number': 'string',
            'statement_period_end': 'date',
            'ending_market_value': 'number'
        }
    ) AS extracted
FROM bronze.custodian_statements;

-- Cross-row synthesis without context-window juggling
SELECT
    household_id,
    AI_AGG(meeting_note, 'Summarize the client''s stated concerns and any action items.') AS summary
FROM silver.meeting_notes
GROUP BY household_id;

Part 4 — Use case patterns that hold up

Ordered roughly by payoff-to-effort. The ones near the top are things SQL and dbt genuinely cannot do; the ones near the bottom need real product work.

Tier 1: unstructured-to-structured (highest payoff)

The classic win. You have text or PDFs sitting in a Bronze layer that no downstream model can use.

  • Semi-structured JSON narrative fields — planning-tool notes, CRM descriptions, freeform comment blobs. AI_EXTRACT into typed columns.
  • Document extraction — custodian statements, agreements, onboarding forms, K-1s. AI_PARSE_DOCUMENT then AI_EXTRACT with a response schema.
  • Classification and tagging — routing CRM activities and cases into a controlled vocabulary that the business defined.
  • Sentiment and theme extraction on client communications or survey responses.

Tier 2: entity resolution assistance

Where deterministic matching leaves a residual. Use AI_SIMILARITY or Cortex Search to generate ranked candidates, then apply your existing deterministic rules to accept or reject. Do not let the model make the final match decision on financial identity data — use it to shrink the candidate set a human or a rule adjudicates.

Tier 3: narrative generation over your own metrics

Variance commentary, flow explanations, month-end summaries. Cheap because the input is small (already-aggregated numbers, not raw text) and the output can be capped tightly. High perceived value with leadership audiences.

Internal documentation search, policy lookup, an ops assistant grounded on your own runbooks. Real value, real ongoing cost — see the Search section.

Tier 5: self-serve analytics (Cortex Analyst / CoWork)

The demo everyone wants. Requires a well-maintained semantic model to work at all, and the semantic model is the entire project. Budget accordingly. Verified queries help: you register common business questions with an approved SQL answer, and the service runs the verified query instead of generating a new one — faster, cheaper, and more consistent.

The architectural rule for all of the above

Run inference once

Run inference once, materialize the result, never call an AI function from a view that gets queried repeatedly. An AI_COMPLETE in a Gold view that ten dashboards hit is a bill, not an architecture.

In a medallion architecture: put the AI call in an incremental Silver model, write the output to a physical column, and treat the result as ordinary data from that point forward.

-- Incremental pattern: only pay for new rows
{{ config(materialized='incremental', unique_key='case_id') }}

SELECT
    case_id,
    case_notes,
    AI_CLASSIFY(case_notes, ['billing', 'performance', 'onboarding', 'service', 'other']) AS topic,
    CURRENT_TIMESTAMP() AS classified_at
FROM {{ ref('stg_crm_cases') }}
{% if is_incremental() %}
WHERE _loaded_at > (SELECT MAX(_loaded_at) FROM {{ this }})
{% endif %}

Managed hybrid retrieval. Handles chunking, embedding, indexing, refresh, and serving. You define it declaratively, like a dynamic table.

Creating a service

CREATE OR REPLACE CORTEX SEARCH SERVICE policy_docs_svc
    ON doc_text                              -- the column to index for search
    ATTRIBUTES doc_type, effective_date      -- filterable/faceted columns
    PRIMARY KEY (doc_id)                     -- enables incremental refresh
    WAREHOUSE = cortex_search_wh
    TARGET_LAG = '1 hour'
    REQUEST_LOGGING = TRUE                   -- preview; logs to SNOWFLAKE.LOCAL.AI_OBSERVABILITY_EVENTS
AS (
    SELECT
        doc_id,
        doc_type,
        effective_date,
        CONCAT('Title: ', title, '\n\n', body) AS doc_text
    FROM silver.internal_docs
);

Things the docs bury

  • PRIMARY KEY is a cost feature, not just a modeling one. Services with primary keys use an optimized refresh path that re-embeds only changed rows instead of the whole corpus. Without it, every refresh cycle re-embeds everything. Primary key columns must be TEXT. Duplicate keys are silently dropped from the index.
  • TARGET_LAG must be shorter than the source table's DATA_RETENTION_TIME_IN_DAYS. If it exceeds retention, the service can lose the ability to detect changes and may need to be recreated.
  • The source query follows dynamic-table rules. Non-deterministic functions are not allowed.
  • Hard limit: the materialized source query must be under 100 million rows, or CREATE fails. Increases require Snowflake support.
  • Concatenate fields in the source query to build a single richer search column, as in the example above. That is the intended pattern.
  • PRIMARY KEY can be added later via ALTER CORTEX SEARCH SERVICE … SET PRIMARY KEY (…).

Querying

Three surfaces: REST API, Python API, and SQL for testing.

-- Quick SQL test
SELECT PARSE_JSON(
    SNOWFLAKE.CORTEX.SEARCH_PREVIEW(
        'policy_docs_svc',
        '{"query": "fee billing exception approval", "columns": ["doc_id","doc_text"], "limit": 5}'
    )
);

-- High-throughput batch: fuzzy-match a column against a canonical list
SELECT q.raw_name, s.*
FROM staging_names AS q,
     LATERAL CORTEX_SEARCH_BATCH(
         service_name => 'canonical_names_svc',
         query => q.raw_name,
         limit => 3
     ) AS s;

CORTEX_SEARCH_BATCH gets significantly higher throughput than the interactive surfaces. It is the right tool for the fuzzy-matching-at-scale use case, and a genuinely underused feature.

Force a rebuild after a large load:

ALTER CORTEX SEARCH SERVICE policy_docs_svc REFRESH;

The cost warning

Cortex Search serving is billed per GB of indexed data per month, continuously, whether or not anyone queries it. This is the single most common source of surprise Cortex bills, because it is the only component that costs money while idle. Index only what is actually searched. Set TARGET_LAG to your real freshness requirement, not the tightest value that works. Monitor ACCOUNT_USAGE.CORTEX_SEARCH_SERVING_USAGE_HISTORY.


Part 6 — Cost model

How billing works

ComponentUnit
AISQL generative functions (AI_COMPLETE, AI_CLASSIFY, AI_FILTER, AI_AGG, AI_TRANSLATE, SUMMARIZE)Input and output tokens
Embeddings (AI_EMBED)Input tokens only
Cortex GuardInput tokens, counted from the output of the AI_COMPLETE it guards — billed in addition to the function
Cortex Search servingGB of indexed data per month, continuous
Cortex Search indexingYour warehouse
Cortex Analyst (standalone API)67 credits per 1,000 messages, flat
Cortex Analyst (via Agents)Per token
Warehouse computeNormal credits, for any SQL running alongside the call

A token is roughly 4 characters of English text, though this varies by model. Image token equivalence is model-determined.

The two currencies problem

Since April 1, 2026 there are two billing currencies, and the same model costs different amounts depending on which surface you call it through:

  • AISQL functions bill in standard, edition-priced Snowflake credits.
  • Cortex Agents, CoCo, and CoWork bill in AI Credits at a flat $2.00/credit globally, decoupled from Snowflake Edition and region.

Higher-level surfaces also carry an orchestration premium of roughly 18% on the same model versus calling it directly through AISQL.

The flat AI Credit rate mainly benefits Business Critical and non-US-region accounts. Standard edition in US regions was already near $2.00 and sees roughly no change; Business Critical in expensive regions has seen reported reductions up to 70%. Check your account's edition and region before building any cost estimate from a blog post's dollar figures.

Model choice is 90% of your bill

Per-model rates span roughly $0.12 to $5.10 per million tokens. A documented example: one team ran AI_COMPLETE over roughly one million rows with a 1,000-token prompt and about 3,000 tokens of output per row.

Model classResult
Most capable frontier model~26,000+ AI Credits, roughly $52,000
Small open-source model~440 credits, under $900

Same rows, same prompt, 59x difference from the model swap alone.

Two further pricing subtleties:

  1. Output tokens cost more than input tokens, often dramatically. Snowflake-optimized open-weight variants sometimes price input and output symmetrically, which makes them a sweet spot for output-heavy batch work.
  2. Long-context model variants are separate SKUs priced at roughly double. Selecting a -long-context model when you do not need the window is a silent 2x. Check the exact model string you are passing.

The REST API additionally distinguishes Regional from Global inference; Regional runs about 10% higher but pins inference to a specific region, which matters for data residency.

Cost checklist

  1. Sample first. Run AI_COUNT_TOKENS on 1,000 representative rows, take the average, multiply by row count, then look up the per-million rate before you run anything at scale.
  2. Start on the cheapest model that could work, evaluate quality on a labeled sample, and only escalate model tiers if quality actually fails. Do not start with the frontier model and optimize down.
  3. Cap max_tokens. If you need a category label, you need 5 tokens, not 500.
  4. Prefer task-specific functions to prompted generation. AI_CLASSIFY and AI_SENTIMENT are cheaper and more consistent than an AI_COMPLETE prompt doing the same job.
  5. Keep the calling warehouse at MEDIUM or smaller. Snowflake explicitly states that a larger warehouse does not improve Cortex function performance — it just costs more.
  6. Materialize and cache. Never re-embed or re-infer stable data. Store embeddings; store classifications; use unique_key incremental models.
  7. Trim conversation history in multi-turn agent flows. Every turn re-sends prior context and pays for it again.
  8. Index selectively in Cortex Search and set an honest TARGET_LAG.
  9. Route simple Analyst questions through Agents for per-token billing rather than the flat 67-credits-per-1,000-messages standalone API, which overcharges for trivial queries.
  10. Gate production Cortex workloads behind review. Experimentation is where the runaway bills happen.

Estimation formula

total_tokens = row_count × avg_tokens_per_row(input + expected output)
cost_in_credits = (total_tokens / 1,000,000) × credits_per_million_for_model
cost_in_dollars = cost_in_credits × your_effective_credit_price
-- Step 1 of every batch job
SELECT
    AVG(AI_COUNT_TOKENS('claude-haiku-4-5', case_notes)) AS avg_input_tokens,
    MAX(AI_COUNT_TOKENS('claude-haiku-4-5', case_notes)) AS max_input_tokens,
    COUNT(*) AS sample_size
FROM (SELECT case_notes FROM silver.crm_cases SAMPLE (1000 ROWS));

Part 7 — Monitoring

-- Cortex function spend by model and function
SELECT
    DATE_TRUNC('day', start_time) AS day,
    function_name,
    model_name,
    SUM(token_credits) AS credits,
    SUM(tokens) AS tokens
FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_USAGE_HISTORY
WHERE start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP())
GROUP BY ALL
ORDER BY credits DESC;

Other views worth wiring into a monitoring dashboard:

ViewUse
CORTEX_FUNCTIONS_USAGE_HISTORYHourly token and credit consumption by function, model, hour
CORTEX_FUNCTIONS_QUERY_USAGE_HISTORYAttribution down to the query — join to QUERY_HISTORY to find which model or dbt run caused a spike
CORTEX_SEARCH_SERVING_USAGE_HISTORYSearch serving cost by service
METERING_HISTORYAccount-level AI services credits
SNOWFLAKE.LOCAL.AI_OBSERVABILITY_EVENTSSearch request logs when REQUEST_LOGGING = TRUE

Set a resource monitor and a budget alert before the first production workload, not after the first invoice.


Part 8 — Governance and safety

  • Data stays in the Snowflake perimeter. This is the actual reason regulated firms can use Cortex where they cannot use a direct model-provider API. Inference runs where the data lives; no egress to a third-party endpoint.
  • Cortex Guard is a built-in safety filter for AI_COMPLETE output. Billed separately, on input tokens derived from the guarded call's output. Worth enabling on anything client-facing.
  • RBAC applies normally. Model access can be restricted at the role level. Cortex Search services are grantable objects (GRANT USAGE ON CORTEX SEARCH SERVICE …), and search results respect the grants on the underlying service, not the base table — so scope service definitions carefully.
  • AI Agent Identity (GA at Summit 26) gives agents verified identity and audit trails. If you are heading toward agentic workflows that write anywhere, this is the control plane to understand before building.
  • Determinism is not guaranteed. Different models produce different results, and Cortex Analyst may select different models depending on region, cross-region config, and role access. For reproducible output, pin region, cross-region setting, and model-level RBAC consistently — and never treat an LLM output as a system of record without a materialized, versioned copy.

Part 9 — Gotchas

GotchaConsequence
Model unavailable in your region, cross-region DISABLEDCall fails outright, not a fallback
Accidentally selecting a -long-context model string~2x cost, silently
AI function inside a frequently-queried viewRecomputed and rebilled on every query
Cortex Search service with no PRIMARY KEYFull re-embed on every refresh cycle
Cortex Search indexed but unusedStill billed monthly, continuously
TARGET_LAG longer than source retentionService can stop detecting changes; may need recreation
Source query over 100M rowsCREATE CORTEX SEARCH SERVICE fails
Warehouse larger than MEDIUM for Cortex callsNo speedup, extra cost
Same model, different surfaceDifferent currency and roughly 18% orchestration premium
Cortex Analyst standalone API for simple questions67 credits per 1,000 messages regardless of complexity
Preview features in production pathsCortex Sense was private preview as of June 2026; several Summit 26 items are previews
Blog-post dollar figuresAlmost always assume a different edition/region than yours

Part 10 — A pragmatic adoption sequence

Week 1 — Prove the plumbing

Grant CORTEX_USER, set cross-region inference, run AI_COUNT_TOKENS and one AI_CLASSIFY over a 1,000-row sample. Confirm the spend appears in CORTEX_FUNCTIONS_USAGE_HISTORY. Set a resource monitor.

Week 2 — Pick one unstructured-data problem you already can't solve

Not a chatbot. Something like extracting three typed fields from a document type you currently handle manually. Build it as an incremental Silver model. Measure accuracy against a hand-labeled sample of 100 rows, and measure cost per 1,000 rows.

Week 3 — Productionize that one thing

Materialize the output, add the model name and timestamp as columns for auditability, wire it into your existing tests. Now you have a real cost figure and a real accuracy figure to take to stakeholders.

Week 4 — Decide whether search or analytics is next

Cortex Search if the need is retrieval over your own documents. Cortex Analyst only if you are prepared to own a semantic model as a maintained artifact. Both are bigger commitments than Tier 1 work.

Deliberately later: agents, CoWork rollout, Cortex Sense. The interesting parts of the 2026 stack are also the least settled parts, and the semantic and governance groundwork they depend on is the same groundwork Tier 1 work forces you to build anyway.


Quick reference card

-- Access
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE <role>;
ALTER ACCOUNT SET CORTEX_ENABLED_CROSS_REGION = 'AWS_US';   -- ACCOUNTADMIN only

-- Before any batch job
SELECT AVG(AI_COUNT_TOKENS('<model>', <col>)) FROM <tbl> SAMPLE (1000 ROWS);

-- Core functions
AI_COMPLETE / AI_CLASSIFY / AI_FILTER / AI_AGG / AI_EMBED / AI_SIMILARITY
AI_EXTRACT / AI_PARSE_DOCUMENT / AI_TRANSCRIBE / AI_SENTIMENT / AI_TRANSLATE
AI_COUNT_TOKENS / TO_FILE

-- Search
CREATE CORTEX SEARCH SERVICE <name> ON <col> ATTRIBUTES <cols>
  PRIMARY KEY (<col>) WAREHOUSE = <wh> TARGET_LAG = '<n> hours' AS (<query>);
ALTER CORTEX SEARCH SERVICE <name> REFRESH;
SNOWFLAKE.CORTEX.SEARCH_PREVIEW(...)    -- testing
CORTEX_SEARCH_BATCH(...)                -- high throughput

-- Monitoring
SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_USAGE_HISTORY
SNOWFLAKE.ACCOUNT_USAGE.CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY
SNOWFLAKE.ACCOUNT_USAGE.CORTEX_SEARCH_SERVING_USAGE_HISTORY

The three rules, if you remember nothing else

Sample tokens before you run at scale, pick the cheapest model that passes your accuracy bar, and materialize every inference result exactly once.


Sources

Authoritative pricing lives only in Snowflake's Service Consumption Table. Every dollar figure here is illustrative.

Related pages

On this page