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 YAML specification.

  • label-semantic_model_generator

备注

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.

  1. Sign in to Snowsight.

  2. In the navigation menu, select AI & ML » Cortex Analyst.

  3. At the top of the navigation menu, select Create new » Create new Semantic View.

  4. Select a location to store the semantic view after creation.

  5. Enter a name for the semantic view.

  6. For Description, specify information about the semantic view.

  7. 选择 Next: Select tables

  8. 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.

  9. 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.

  10. 选择 Next: Select tables

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. 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

  1. If you are planning to create the semantic view from Cortex Analyst, create a stage for the YAML file.

  2. Upload the YAML file in one of the following ways:

    • Database object explorer:

      1. Sign in to Snowsight.

      2. In the navigation menu, select Catalog » Database Explorer.

      3. 从显示 No Database selected 的菜单中,选择要在其中创建语义视图的数据库和架构。

      4. Select Create » Semantic View » Upload YAML file.

      5. Select the YAML file to upload.

      6. Under Select database, schema and stage, select the database, schema, and stage where you want to upload the YAML file.

      7. If you want the YAML file uploaded to a specific path in the stage, specify that path.

      8. 选择 Create and Save

    • Cortex Analyst:

      1. Sign in to Snowsight.

      2. In the navigation menu, select AI & ML » Cortex Analyst.

      3. Select Create new » Upload YAML file.

      4. Select the YAML file to upload.

      5. 选择 Create 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.

要编辑语义视图,请执行以下操作:

  1. Access the semantic view in one of the following ways:

    • Database object explorer:

      1. Sign in to Snowsight.

      2. In the navigation menu, select Catalog » Database Explorer.

      3. 从数据库菜单中,选择包含要编辑的语义视图的数据库和架构。

      4. Select from 下,选择 Semantic Views

      5. 选择拥有语义视图的角色。

      6. Select the Semantic information tab.

    • Cortex Analyst:

      1. Sign in to Snowsight.

      2. In the navigation menu, select AI & ML » Cortex Analyst.

      3. Select from 下,选择 Semantic Views

      4. 从数据库菜单中,选择包含要编辑的语义视图的数据库和架构。

      5. 选择要编辑的语义视图,然后选择 Open

  2. 对语义视图进行更改。您可以:

    • 迭代开发语义视图:

      1. 选择拥有语义视图的角色。

      2. Make changes to the name or description.

      3. 选择 Create and Save

    • 迭代开发语义视图:

      1. Cortex Analyst 窗口的右上角选择 Save

      2. 在向导的 Select tables 步骤中:

        1. Find tables and views 选项卡中,选择包含要在语义视图中使用的数据的表或视图。

        2. 选择 Next: Select tables

      3. 在向导的 Select columns 步骤中:

        1. 选择要包含在模型中的列。

          要选择表或视图中的所有列,请选择表或视图。

        2. 选择 Next: Select tables

    • To make changes to the name, description, synonyms, or primary key of a logical table in the semantic view:

      1. 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.

      2. 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.

      3. 选择 Create and Save

    • 为您的表、事实、维度或指标添加同义词。

      1. Open the form for adding the new item:

        • In the database object explorer, select 更多选项, and select Fact, Dimension, or Metric.

        • In Cortex Analyst, select + next to Facts, Dimensions, or Metrics.

      2. Enter information about the new fact, dimension, or metric, and select Add.

    • 添加、修改或移除事实、维度和指标。

      1. Select Facts, Dimensions, or Metrics to display the list of facts, dimensions or metrics.

      2. For the fact, dimension, or metric that you want to change:

        • Select Edit to modify the item.

        • Select 更多选项 » Remove fact, Remove dimension, or Remove metric to remove the item.

    • 更新关系。

      1. Open the form for adding the new item:

        • In the database object explorer, select + Relationship.

        • In Cortex Analyst, select + next to Relationships.

      2. Enter a name for the relationship, select the tables in the relationship, and select the columns to use to join the tables.

      3. 选择 Create and Save

  3. 如果您计划在此视图中使用 Cortex Analyst,请考虑以下几点:

    • Verified Queries 部分添加示例查询。

      • 这些示例查询可帮助 Cortex Analyst 了解如何使用语义视图。

      • 添加代表数据常见用例的查询。

    • 为您的表、事实、维度或指标添加同义词。

      • 这些同义词是用户可能在查询中使用的替代术语。

      • 同义词有助于 Cortex Analyst 正确解释用户的问题。

    • 添加自定义指令。

      • 它们为如何解释数据提供了更多上下文信息。

      • 包括应考虑的业务规则或限制。

  4. 选择 Create and 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:

  1. Access the semantic view in one of the following ways:

    • Database object explorer:

      1. Sign in to Snowsight.

      2. In the navigation menu, select Catalog » Database Explorer.

      3. 从数据库菜单中,选择包含要编辑的语义视图的数据库和架构。

      4. Select from 下,选择 Semantic Views

      5. 选择拥有语义视图的角色。

      6. Select 更多选项 » Share.

    • Cortex Analyst:

      1. Sign in to Snowsight.

      2. In the navigation menu, select AI & ML » Cortex Analyst.

      3. Select from 下,选择 Semantic Views

      4. 选择拥有语义视图的角色。

      5. 选择 Create and Save

  2. 选择应拥有语义视图的角色。

  3. 选择 Create and Save

This grants the SELECT and REFERENCES privileges on the semantic view to the selected role.

编辑语义视图

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 查询语义视图.

创建语义视图

  • 提供清晰的描述:

    • 在所有名称和描述中使用业务术语。

    • 使描述足够详细,以方便非技术用户理解。

  • 包括代表性的用户问题:

    • 包括可以帮助模型生成器更好地理解您的意图的问题。

    • 包括提问方式的变体。

  • 仔细查看生成的建议:

    • 确保问题与用例相关。

    • 确保建议的关系符合您的业务理解。

  • 使用真实问题进行测试:

    • 创建语义视图后,使用实际业务问题对其进行测试。

    • 根据模型对这些问题的支持程度,完善语义视图。

  • 迭代开发语义视图:

    • 从一个简单的星型架构开始。

    • 从核心表和指标开始,然后扩展。为了简单起见,建议使用三个表。

    • 获取业务用户的反馈,并完善您的语义视图。

故障排除

  • 如果您的语义视图未在 Cortex Analyst 语义视图生成器的视图列表中列出,请刷新模型列表(而不是页面本身)。

  • 如果语义视图中的关系出现错误,请确保这些关系与实际数据结构相匹配。

  • 如果查询速度很慢,请减少表或列的数量。

  • 如果在使用语义视图时 Cortex Analyst 产生意外的结果,请查看语义视图中的事实、维度和指标。