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
In a nutshell
  • 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.

Base tablesTABLES and RELATIONSHIPSSemantic viewfacts, dimensions, metricsSEMANTIC_VIEW queryBI and SQL usersSemantic viewdefinition read byCortex Analyst or Agentquestion to SQLgenerated SQLAnswer

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));
ClauseHolds
TABLESLogical tables, with aliases, primary or unique keys, synonyms, comments
RELATIONSHIPSJoins between logical tables on shared keys
FACTSRow level expressions (not aggregated)
DIMENSIONSCategorical attributes used to group and filter
METRICSAggregated measures such as SUM or AVG, including derived and window function metrics
  • Clause order matters: TABLES, then RELATIONSHIPS, FACTS, DIMENSIONS, METRICS. At least one dimension or metric is required.
  • Metrics can use USING to pick a join path when several exist, and NON ADDITIVE BY for semi additive measures such as a balance.
  • PRIVATE facts 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 VIEW schema privilege plus SELECT on the underlying tables.
  • You can also build one in Snowsight with a guided wizard, or from a YAML specification.
Exam tip

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:

ToolWhat it does
AI_EMBEDTurns text into a vector that represents meaning
AI_SIMILARITYCompares the embeddings of two inputs
AI_SENTIMENT, AI_CLASSIFYLabel tone or topic without keyword rules
AI_AGG, AI_SUMMARIZE_AGGInsights across many rows
Cortex SearchHybrid (vector and keyword) search service over a table
Cortex AnalystNatural 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_HISTORY shows credits by function, model, user, role and query. It has QUERY_TAG, so tag workloads to charge them back to teams. The view has a latency of up to a few minutes.
  • Estimate: AI_COUNT_TOKENS returns 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 FUNCTIONS privilege and SNOWFLAKE.CORTEX_USER from PUBLIC, then grant them (or the AI_FUNCTIONS_USER role, which is not granted to PUBLIC) only to chosen roles. Without that revoke, users keep access through PUBLIC and any per user control is bypassed.
  • Restrict models: the CORTEX_MODELS_ALLOWLIST account 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.
Watch out

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; revoke CORTEX_USER from PUBLIC; 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.