Semantic Views & Cortex Analyst
Snowflake · Advanced Features
Theory
A semantic view is a schema-level object that describes your data in business terms: logical TABLES, the RELATIONSHIPS between them, FACTS, DIMENSIONS such as city or order_date, and METRICS such as total_sales = SUM(amount). Because the meaning lives in one governed object, every tool asks for total_sales the same way. You can query it with SELECT * FROM SEMANTIC_VIEW(sales_sv METRICS orders.total_sales DIMENSIONS customers.city).
Cortex Analyst uses that semantic model to answer natural-language questions. Asked "What were sales by city last month?", it generates SQL from the definitions, runs it on your warehouse and returns the result. It is offered as a REST API and as a tool inside Cortex Agents, which Snowflake now recommends for new conversational apps. Older semantic models written as YAML files on a stage still work.
Why we use it
Letting business users ask questions in plain English only works if the AI knows what each table, join and metric means. Semantic views give it that context once, so answers are consistent and governed instead of guessed from column names.
When to use it
Use semantic views to define shared metrics for BI and AI, and Cortex Analyst (usually through Cortex Agents) for self-service questions over structured data. Use Cortex Search for unstructured text. Keep critical reports on reviewed SQL and verify generated answers.
How it works
- Business user asks a question in plain English
- Cortex Analyst reads the semantic view: tables, relationships, metrics
- It generates SQL for the question
- Is the question answerable with the defined data? Yes: Run the SQL on the user's warehouse. No: Ask the user to clarify or decline.
- Results respect the user's role and policies
- Answer and the generated SQL are returned
Example
CREATE OR REPLACE SEMANTIC VIEW sales_sv
TABLES (
orders AS sales_db.public.orders PRIMARY KEY (order_id),
customers AS sales_db.public.customers PRIMARY KEY (customer_id)
)
RELATIONSHIPS (
orders_to_customers AS orders (customer_id) REFERENCES customers
)
FACTS (
orders.order_amount AS amount
)
DIMENSIONS (
customers.city AS city,
orders.order_date AS order_date
)
METRICS (
orders.total_sales AS SUM(orders.order_amount)
)
COMMENT = 'Sales metrics for BI and Cortex Analyst';
SELECT * FROM SEMANTIC_VIEW(
sales_sv
DIMENSIONS customers.city
METRICS orders.total_sales
);Key points
- A semantic view defines tables, relationships, facts, dimensions and metrics
- FACTS must come before DIMENSIONS in CREATE SEMANTIC VIEW
- Query it directly with SEMANTIC_VIEW(... METRICS ... DIMENSIONS ...)
- Cortex Analyst turns questions into SQL and runs it on your warehouse
- Snowflake recommends Cortex Agents for new apps; Analyst is one of its tools
- Needs SNOWFLAKE.CORTEX_USER or CORTEX_ANALYST_USER plus SELECT on the tables