Data Transformation · Topic 9 of 14
Semantic Views, Semantic Analysis and Cortex Cost Control
Define business metrics in semantic views, run semantic analysis with embeddings and Cortex Analyst, and control Cortex LLM cost with usage views.
- 4 min
- Semantic view:
TABLES,RELATIONSHIPS,FACTS,DIMENSIONS,METRICS; read by Cortex Analyst and Agents. - Query with
SELECT ... FROM SEMANTIC_VIEW(... METRICS ... DIMENSIONS ...). - Semantic analysis: embeddings,
AI_SIMILARITY, Cortex Search, Cortex Analyst.
What it is
A semantic view is a schema level object that stores business concepts (entities, relationships, row level facts, dimensions and metrics) as metadata on top of your tables. Everyone who queries it gets the same definition of "revenue" or "active customer". Cortex Analyst and Cortex Agents read semantic views to turn business questions into correct SQL.
Semantic analysis is the second idea in this page: analyzing meaning rather than exact text, using embeddings, similarity and AI functions. Cost management keeps those LLM calls from surprising you.
How it works
Semantic views
CREATE SEMANTIC VIEW sales_sv
TABLES (
orders AS sales.public.orders PRIMARY KEY (order_id),
customers AS sales.public.customers PRIMARY KEY (customer_id)
)
RELATIONSHIPS (
orders_to_customers AS orders (customer_id) REFERENCES customers
)
FACTS (orders.line_amount AS amount)
DIMENSIONS (
customers.region AS customers.region,
orders.order_year AS YEAR(order_date)
)
METRICS (orders.total_revenue AS SUM(orders.line_amount))
COMMENT = 'Revenue by region and year';
SELECT * FROM SEMANTIC_VIEW(
sales_sv
METRICS (orders.total_revenue)
DIMENSIONS (customers.region, orders.order_year));
| Clause | Holds |
|---|---|
TABLES | Logical tables, with aliases, primary or unique keys, synonyms, comments |
RELATIONSHIPS | Joins between logical tables on shared keys |
FACTS | Row level expressions (not aggregated) |
DIMENSIONS | Categorical attributes used to group and filter |
METRICS | Aggregated measures such as SUM or AVG, including derived and window function metrics |
- Clause order matters:
TABLES, thenRELATIONSHIPS,FACTS,DIMENSIONS,METRICS. At least one dimension or metric is required. - Metrics can use
USINGto pick a join path when several exist, andNON ADDITIVE BYfor semi additive measures such as a balance. PRIVATEfacts and metrics are usable inside other expressions but cannot be queried directly.- Optional AI clauses (
AI_SQL_GENERATION,AI_QUESTION_CATEGORIZATION,AI_VERIFIED_QUERIES) guide Cortex Analyst. - Creating one needs the
CREATE SEMANTIC VIEWschema privilege plusSELECTon the underlying tables. - You can also build one in Snowsight with a guided wizard, or from a YAML specification.
When a question asks how to give analysts and Cortex Analyst one consistent definition of a metric, the answer is a semantic view, not a copy of the SQL in every dashboard.
Semantic data analysis with Cortex
Several tools analyze meaning:
| Tool | What it does |
|---|---|
AI_EMBED | Turns text into a vector that represents meaning |
AI_SIMILARITY | Compares the embeddings of two inputs |
AI_SENTIMENT, AI_CLASSIFY | Label tone or topic without keyword rules |
AI_AGG, AI_SUMMARIZE_AGG | Insights across many rows |
| Cortex Search | Hybrid (vector and keyword) search service over a table |
| Cortex Analyst | Natural language questions answered with SQL, driven by a semantic view |
A typical pipeline embeds new rows into a VECTOR column, then queries by similarity (VECTOR_COSINE_SIMILARITY) or serves them through a Cortex Search service.
Cost management for Cortex LLM
AI functions consume credits based on tokens, or on pages for document functions. Input and output tokens both count.
- Monitor:
SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_FUNCTIONS_USAGE_HISTORYshows credits by function, model, user, role and query. It hasQUERY_TAG, so tag workloads to charge them back to teams. The view has a latency of up to a few minutes. - Estimate:
AI_COUNT_TOKENSreturns the token count for an input before you run it. - Reduce: filter rows before calling the function, send only needed columns, keep prompts short, pick a smaller model when quality allows, and prefer a purpose built function over a long free form prompt.
- Control access: revoke the
USE AI FUNCTIONSprivilege andSNOWFLAKE.CORTEX_USERfromPUBLIC, then grant them (or theAI_FUNCTIONS_USERrole, which is not granted toPUBLIC) only to chosen roles. Without that revoke, users keep access throughPUBLICand any per user control is bypassed. - Restrict models: the
CORTEX_MODELS_ALLOWLISTaccount parameter limits which models can be called; Snowflake is deprecating it in favor of role based model access. - Alert: build an alert or task on the usage view to warn administrators or stop runaway queries. Cancelling stops further charges but does not refund credits already used.
Model processing is billed as AI credits, not warehouse time, so a larger warehouse does not make LLM calls cheaper. A small warehouse is usually enough for queries that call AI functions.
Common mistakes
Treating a semantic view as a physical view. It stores definitions and is queried with SEMANTIC_VIEW, not a table copy.
Putting clauses in the wrong order. FACTS must come before DIMENSIONS.
Putting an aggregate in a fact. Facts are row level; aggregates belong in metrics.
Limiting access by role but leaving PUBLIC granted. The grant on PUBLIC defeats the control.
What to remember for the exam
- Semantic view:
TABLES,RELATIONSHIPS,FACTS,DIMENSIONS,METRICS; read by Cortex Analyst and Agents. - Query with
SELECT ... FROM SEMANTIC_VIEW(... METRICS ... DIMENSIONS ...). - Semantic analysis: embeddings,
AI_SIMILARITY, Cortex Search, Cortex Analyst. - Cost: credits per token or page; watch
CORTEX_AI_FUNCTIONS_USAGE_HISTORY; revokeCORTEX_USERfromPUBLIC; filter rows and pick smaller models.
Check yourself
Where do you define a metric once so every tool and Cortex Analyst calculates it the same way?
In a semantic view, using the METRICS clause.
Which Account Usage view shows credits spent by AI functions per model and user?
SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_FUNCTIONS_USAGE_HISTORY.
Why must CORTEX_USER be revoked from PUBLIC to enforce per role limits?
Every user inherits PUBLIC, so the default grant lets them bypass any role based restriction.
Topic 9 of 14 in Data Transformation
Test yourself on Data Transformation
The full Snowflake DEA-C02 question bank has 709 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.