Creating with Snowsight¶
In Snowsight, you can create and manage semantic views to define logical tables over your data in Cortex Analyst. Semantic views abstract the physical tables and provide a business-friendly layer over your data. You can use semantic views with Cortex Analyst to answer business questions and perform data analysis.
You can create a semantic view in Snowsight in either of these ways:
- Use the Semantic View Autopilot, an AI-assisted generator, to build a semantic view for you.
- Upload a YAML specification.
After you create a semantic view, you can edit it, grant access to it, and query it, all in Snowsight.
Note
You can use the instructions in this section to also create a semantic model, but we recommend using semantic views instead. Semantic views provide the following features:
- Semantic views support advanced features such as Derived Metrics.
- Semantic views support access modification. They’re public by default, but you can make them private.
- Semantic views are schema objects that integrate with Snowflake’s privilege system, sharing mechanisms, and metadata catalog. Semantic models are YAML files stored in a stage and lack these native database integrations.
Prerequisites¶
To create a semantic view, you must use a role with the following privileges:
- CREATE SEMANTIC VIEW on the schema where you are creating the semantic view.
- USAGE on the database and schema where you are creating the semantic view.
- SELECT on the tables and views used in the semantic view.
You can export a model from Tableau and use it to automatically generate a semantic view. In addition to the preceding prerequisites, the Tableau ingestion feature requires:
- A stage where you have write permissions.
- If your Tableau file contains Custom SQL, you must also have the CREATE VIEW privilege on the schema because the SQL is parsed into a regular Snowflake view.
You can also upload a Power BI file (.pbit or .pbix) to automatically generate a semantic view. In addition to the preceding prerequisites, the Power BI ingestion feature requires:
- A stage where you have write permissions.
- Read access to the underlying tables and columns that your Power BI file references.
Creating a semantic view¶
In Snowsight, you can create a semantic view by using the AI-assisted generator (Semantic View Autopilot) or by uploading a YAML specification.
Using Semantic View Autopilot to create a semantic view¶
Use the AI-assisted generator to create a semantic view that combines semantic information from multiple sources. Instead of creating a semantic view manually with your own YAML specification, you can use the generator within Snowsight to save time. The process of creating a semantic view requires the following information:
- A description with basic information about the view
- Context, such as example SQL queries
- The data source (at least one table or view) that you’re using
- The columns that you’re using
The AI-assisted generator handles inputs in the following ways:
-
Example SQL queries
- Validate the list of queries and throw out invalid queries.
- Extract all tables and columns from the queries and present them for review before adding to the semantic view.
- Extract relationships from the queries.
- Add valid queries to the semantic view as verified queries.
-
Table metadata
- Extract all table and column descriptions.
- Add primary and unique keys to the semantic view by analyzing metadata or counting distinct values to determine cardinality and relationship types.
-
Query history
- Surface historical SQL queries as suggestions to the semantic view. The generator identifies the most common types of queries that fit within the bounds of the selected tables and columns.
- Find valid relationships and column types for the semantic view.
- Cortex Analyst uses the query history accessible by the role used to create the semantic model to generate both relationships and verified query suggestions.
To create a semantic view with the generator:
-
Sign in to Snowsight.
-
In the navigation menu, select AI & ML » Cortex Analyst.
-
At the top of the navigation menu, select Create new » Create new Semantic View.
-
Select a location to store the semantic view after creation.
-
Enter a name for the semantic view.
-
For Description, specify information about the semantic view. Use clear business terminology to help the AI understand the view’s purpose.
-
Select Next.
-
To provide context, add the following information:
- For SQL Queries, provide example questions and their respective SQL queries that you want to use as part of the view.
You can also provide context by uploading a Tableau or Power BI file. For details on each option, see Options for providing context.
-
For Select tables, provide the data source that you’re using to create the semantic view. You must provide at least one table or view. For your first semantic view, Snowflake recommends using fewer than 10 tables or views to keep it easy to understand and use. This is not a hard limit.
-
Select Next.
-
For Select columns, select the columns that you’re using to create the semantic view.
You can select all the columns or specific columns. For performance reasons, Snowflake recommends not using more than 50 columns.
- Select whether you want to add sample values from each column to the semantic view. Sample values help improve the accuracy of Cortex Analyst’s results.
- Select whether you want to add AI-generated descriptions for tables and columns to the semantic view. The AI-generated descriptions are based on the column names and sample values.
- Select Create and save, and then select Save and run. You can view the progress of the view generation, including details about the steps that the view generator is taking, on the semantic view page. The process can take a few minutes.
- Optional: To make additional modifications, edit the view either by using Snowsight or by editing the YAML file directly.
Cortex Analyst automatically generates suggestions to improve the semantic view after creation. After the suggestions appear, which might take several minutes, you can review them and apply them to the view as needed.
Options for providing context¶
While providing context is optional, it’s extremely useful in creating a high-quality semantic view. Without it, the generator only uses the database schema information, which might lack business nuance. Snowflake supports the following options for providing context:
Option 1: Upload Tableau file¶
Semantic View Autopilot supports using a file from Tableau to automatically generate a semantic model. This lets you migrate your existing business logic and metadata directly into Snowflake.
You can either use Tableau Desktop or Tableau Online to provide the file to Semantic View Autopilot. Semantic View Autopilot supports the following file formats:
TWBTWBXTDS
The file must meet the following constraints:
- File Size: Must be under 250 MB.
- No Large Extracts: If using a .twbx file, ensure it does not contain a large extract. If using a .twb file, ensure it does not contain large filters or parameters.
- LOD Calculations: Level of Detail (LOD) calculations are not supported.
You can get the TWB or TWBX file from Tableau Desktop. If you can’t find it, you can go to File | Save As and choose to save as a TWB.
For information about getting a view or workbook from Tableau Online, see Download Views and Workbooks.
After you provide the Tableau file to Semantic View Autopilot, autopilot parses it to extract the following metadata:
- Tables and Columns
- Relationships between tables
- Tableau calculated fields
- Parameters and Filters
- Custom SQL (parsed and turned into a regular Snowflake view)
Option 2: Upload Power BI file¶
Semantic View Autopilot supports using a Power BI file to automatically generate a semantic view. This lets you migrate your existing DAX measures, table relationships, and column definitions directly into Snowflake.
Semantic View Autopilot supports the following Power BI file formats:
.pbit(template files without embedded data).pbix(report files with embedded data)
The file must be under 250 MB.
After you provide the Power BI file to Semantic View Autopilot, autopilot parses it to extract the following metadata:
- Tables and Columns (including renamed tables and columns from M query)
- Relationships between tables
- DAX measures (single-table, cross-table, and derived metrics)
- Calculated columns (single-table)
- Primary keys
Caution
If your Power BI semantic model uses parameters for database or schema names, make sure those parameter values are filled in before exporting. Snowflake uses these values to match tables in your account. If the parameters are left blank, table matching fails and semantic view generation does not complete.
For detailed information about which Power BI features are supported, see Power BI ingestion feature support.
Option 3: Provide SQL queries¶
You can add example natural language questions and their corresponding SQL queries. This helps the model learn your specific business logic and create relationships.
Snowflake uses these queries to pre-select tables and columns in subsequent steps, and will also auto-add these queries as “verified queries” in the semantic model. Additionally, if valid relationships can be inferred, these will get added to the semantic view.
To provide queries as a file, use .csv format with two columns: a natural language question and its corresponding SQL query.
Uploading a YAML specification to create a semantic view¶
- If you are planning to create the semantic view from Cortex Analyst, create a stage for the YAML file.
- Upload the YAML file in one of the following ways:
-
- Sign in to Snowsight.
- In the navigation menu, select Catalog » Database Explorer.
- Select the database and schema where you want to create the semantic view.
- Select Create » Semantic View » Upload YAML file.
- Select the YAML file to upload.
- Under Select database, schema and stage, select the database, schema, and stage where you want to upload the YAML file.
- If you want the YAML file uploaded to a specific path in the stage, specify that path.
- Select Upload.
-
Cortex Analyst:
- Sign in to Snowsight.
- In the navigation menu, select AI & ML » Cortex Analyst.
- Select Create new » Upload YAML file.
- Select the YAML file to upload.
- Select Convert and save.
-
Editing a semantic view¶
Note
Editing a semantic view in Snowsight effectively replaces the existing view. To replace an existing semantic view, you must use a role that has been granted the following privileges:
- CREATE SEMANTIC VIEW on the schema where you are creating the semantic view.
- USAGE on the database and schema where you are creating the semantic view.
- SELECT on the tables and views used in the semantic view.
To edit a semantic view:
-
Access the semantic view in one of the following ways:
-
- Sign in to Snowsight.
- In the navigation menu, select Catalog » Database Explorer.
- Select the database and schema containing the semantic view.
- Select Semantic views.
- Select the semantic view.
- Select the Semantic information tab.
-
Cortex Analyst:
- Sign in to Snowsight.
- In the navigation menu, select AI & ML » Cortex Analyst.
- Select the Semantic views tab.
- Under Select database to see semantic views, select the database and schema containing the semantic view that you want to edit.
- Select the semantic view that you want to edit.
-
-
Make changes to the semantic view. You can make the following types of changes:
-
To modify the name or description of the semantic view:
- Select Edit next to the name of the semantic view.
- Make changes to the name or description.
- Select Apply.
-
To add a new logical table to the semantic view:
-
Select + Logical Table in the database object explorer or + in Cortex Analyst.
-
In the Select a table step in the wizard:
- Select the table or view that contains the data that you want to use in your semantic view.
- Select Next.
-
In the Select columns step in the wizard:
-
Select the columns to include in the view.
To select all columns in a table or view, select the table or view.
-
Select Generate logical table.
-
-
-
To make changes to the name, description, synonyms, or primary key of a logical table in the semantic view:
-
Select
» Edit Logical Table next to the logical table name in the database object explorer
or Edit next to the logical table name in Cortex Analyst. -
Make your changes to the name, description, synonyms, and primary key.
If you have not specified the description or synonyms, you can select Generate fields to fill in these fields automatically.
-
Select Save.
-
-
To add a fact, dimension, or metric:
-
To modify or remove a fact, dimension, or metric:
-
To add a relationship:
-
Open the form for adding the new item:
- In the database object explorer, select + Relationship.
- In Cortex Analyst, select + next to Relationships.
-
Enter a name for the relationship, select the tables in the relationship, and select the columns to use to join the tables.
-
Select Add.
-
-
-
If you plan to use Cortex Analyst with this view, consider the following:
-
Add sample queries to the Verified Queries section. Note that this section is available only in Cortex Analyst.
- These are example queries that help Cortex Analyst understand how to use the semantic view.
- Add queries that represent common use cases for your data.
-
Add synonyms for your tables, facts, dimensions, or metrics.
- These are alternative terms that users might use in queries.
- Synonyms help Cortex Analyst correctly interpret user questions.
-
Add custom instructions.
- These provide additional context about how the data should be interpreted.
- Include business rules or constraints that should be considered.
-
-
Select Save.
Granting the privilege to use a semantic view to another role¶
To grant another role the privileges to view and query a semantic view:
-
Access the semantic view in one of the following ways:
-
- Sign in to Snowsight.
- In the navigation menu, select Catalog » Database Explorer.
- Select the database and schema containing the semantic view.
- Select Semantic views.
- Select the semantic view.
- Select
» Share.
-
Cortex Analyst:
- Sign in to Snowsight.
- In the navigation menu, select AI & ML » Cortex Analyst.
- Select the Semantic views tab.
- Select the semantic view.
- Select Share.
-
-
Select the role that should be granted the privileges to view and query the semantic view.
-
Select Done.
This grants the SELECT and REFERENCES privileges on the semantic view to the selected role.
Querying a semantic view¶
If you are viewing a semantic view in the database object explorer, you can open a worksheet to construct a query for that view
by selecting
» Query with SQL.
For information on how to construct the query, see Querying semantic views.
Troubleshooting¶
- If your semantic view is not listed in the list of views, refresh the list of models (not the page itself).
- If errors occur with the relationships in the semantic view, ensure that these relationships match the actual data structure.
- If queries are slow, reduce the number of tables or columns.
- If Cortex Analyst produces unexpected results when using your semantic view, review the facts, dimensions, and metrics in the semantic view.
Best practices¶
For comprehensive guidance on designing high-quality semantic views, including scoping, writing effective descriptions, defining relationships and metrics, and improving accuracy with verified queries, custom instructions, and Cortex Search, see Best practices for modeling semantic views.