Using Snowsight to create and manage semantic views¶
In Snowsight, you can create and manage semantic views:
创建语义视图¶
In Snowsight, you can create a semantic view by using a wizard or by uploading a semantic model specification.
备注
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.
Using the AI-assisted generator 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 model 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 AI-assisted 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.
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.
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.
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. There's no limit on the tables or views that you can specify, but Snowflake recommends not using more than 10.
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. 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.
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 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.
要编辑语义视图,请执行以下操作:
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.
在向导的 Select columns 步骤中:
Select the columns to include in the 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.
这些示例查询可帮助 Cortex Analyst 了解如何使用语义视图。
添加代表数据常见用例的查询。
为您的表、事实、维度或指标添加同义词。
这些同义词是用户可能在查询中使用的替代术语。
同义词有助于 Cortex Analyst 正确解释用户的问题。
添加自定义指令。
它们为如何解释数据提供了更多上下文信息。
包括应考虑的业务规则或限制。
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.
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 查询语义视图.
Best practices for creating a semantic view¶
提供清晰的描述:
在所有名称和描述中使用业务术语。
使描述足够详细,以方便非技术用户理解。
包括代表性的用户问题:
包括可以帮助模型生成器更好地理解您的意图的问题。
包括提问方式的变体。
仔细查看生成的建议:
确保问题与用例相关。
确保建议的关系符合您的业务理解。
使用真实问题进行测试:
创建语义视图后,使用实际业务问题对其进行测试。
根据模型对这些问题的支持程度,完善语义视图。
迭代开发语义视图:
从一个简单的星型架构开始。
从核心表和指标开始,然后扩展。为了简单起见,建议使用三个表。
获取业务用户的反馈,并完善您的语义视图。
故障排除¶
If your semantic view is not listed in the list of views, refresh the list of models (not the page itself).
如果语义视图中的关系出现错误,请确保这些关系与实际数据结构相匹配。
如果查询速度很慢,请减少表或列的数量。
如果在使用语义视图时 Cortex Analyst 产生意外的结果,请查看语义视图中的事实、维度和指标。