使用 Snowflake Cortex 生成描述

您可以使用 Snowsight 和 Snowflake Cortex COMPLETE 函数 的强大功能来自动生成列、表或视图的描述。Cortex 支持的对象描述功能利用 Snowflake 托管的大型语言模型 (LLMs) 来评估对象元数据,并在需要时利用示例数据来生成描述。

生成的描述在保存后,会存储在列、表或视图的 COMMENT 属性中。您可以在显示 COMMENT 属性的任何位置查看描述,其中包括以下内容:

  • Snowsight 中的 Table DetailsView Details 选项卡。

  • Snowsight 中表或视图的 Columns 选项卡。

  • DESCRIBE TABLE 命令的输出。

  • Account Usage TABLES 视图的输出。

对表、视图或列具有 任何权限 的用户可以在保存描述后查看描述。

备注

You can also call a stored procedure to programmatically generate object descriptions using Snowflake Cortex. For more information, see Using SQL to automatically generate object descriptions.

Cortex descriptions access control requirements

To use the Cortex Powered Object Descriptions feature, you must have:

You must also set the CORTEX_MODELS_ALLOWLIST parameter to allow access to the mistral-7b and llama3.1-8b models. By default, this parameter is set to 'All', which allows access to all models. If the parameter has been changed, ensure that these models are included. For more information about controlling model access with this parameter, see 账户级别的允许列表参数.

LLM regional requirements

Your region must support the LLM used by Snowflake Cortex to generate the descriptions. If you have the required privileges, but do not see this feature, check the availability of the COMPLETE function. If the COMPLETE function is not supported in your region, you need to enable cross-region inference to use the feature.

受支持对象

您可以为以下对象生成描述:

  • 所有表类型

  • 视图

  • 物化视图

  • 表和视图中的列。

使用 Snowflake Cortex 创建、编辑并保存描述

以下部分介绍了生成和编辑 Snowflake Cortex 支持的描述的步骤。

生成并保存描述

要为表或视图生成并保存描述,请执行以下操作:

  1. Sign in to Snowsight as a user with the OWNERSHIP privilege.

  2. 导航到要为其生成描述的表或视图。

  3. 如果出现提示,请选择一个仓库。

  4. Table Details 选项卡或 View Details 选项卡上,选择 Generate with Cortex

  5. 如果要编辑描述,请选择铅笔图标并编辑描述。

  6. 选择 Save

备注

Users with the OWNERSHIP privilege can execute the following to let users with the role my_role generate descriptions. In this example, the user has an ACCOUNTADMIN role:

USE ROLE ACCOUNTADMIN;
GRANT USAGE ON WAREHOUSE ai_wh TO ROLE my_role;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE my_role;
Copy

同时为所有列创建描述

Snowsight 允许您一次为多列生成描述,一次最多 50 列。要通过单个操作为表或视图中的所有列生成描述,请执行以下操作:

  1. Sign in to Snowsight as a user with the required privileges.

  2. 导航到包含这些列的表或视图。

  3. 如果出现提示,请选择一个仓库。

  4. 选择 Columns 选项卡。

  5. 在工具栏中选择 Generate Descriptions

  6. 如果出现提示,请决定是否使用 样本数据

  7. 如果您要编辑描述,请选择铅笔图标。

  8. 选择要保存的列。

  9. 选择 Save

  10. 如果您的表或视图超过 50 列,并且您想为其余列生成描述,请重复此过程。

为单列创建描述

要为单列生成描述,请执行以下操作:

  1. Sign in to Snowsight as a user with the required privileges.

  2. 导航到包含这些列的表或视图。

  3. 如果出现提示,请选择一个仓库。

  4. 选择 Columns 选项卡。

  5. 找到该列,将鼠标悬停在 Description 列中的行上,然后选择 Generate with Cortex

  6. 如果出现提示,请决定是否使用 样本数据

  7. 如果您要编辑描述,请选择铅笔图标。

  8. 选择 Save

覆盖现有描述

要将用户指定的描述替换为生成的描述,请执行以下操作:

  1. Sign in to Snowsight as a user with the required privileges.

  2. 导航到要编辑描述的表或视图。

  3. 如果尚未使用仓库,请选择一个仓库。

  4. 编辑表、视图和列的描述:

    • 表和视图:在 Table Details 选项卡中,选择铅笔图标以编辑现有描述,然后选择 Generate with Cortex

    • 列:在 Columns 选项卡中,选择现有描述的铅笔图标,然后选择 Generate with Cortex

  5. 选择 Save

生成描述但不保存

要为表或视图生成描述,请执行以下操作:

  1. Sign in to Snowsight as a user with the SELECT privilege.

  2. 导航到要为其生成描述的表或视图。

  3. 如果出现提示,请选择一个仓库。

  4. Table Details 选项卡或 View Details 选项卡上,选择 Describe Table

备注

表所有者无法保存通过选择 Describe Table 按钮生成的描述。如果您是表所有者并希望编辑及保存描述,请在页面的 Description 部分中选择 Generate with Cortex

示例数据输入

为列生成描述时,您只能依赖元数据,或者您可以选择使用示例数据来改进 Snowflake Cortex 支持的描述。示例数据是指在使用 Snowflake Cortex 生成描述时评估的特定列中的数据。如果您选择使用示例数据,Snowflake 会使用部分示例数据来生成描述,从而获得更准确的描述。Snowflake 不将示例数据存储为使用情况数据。

使用示例数据的决定由个人用户决定。首次在浏览器会话中生成列描述时,系统将提示您决定是否使用示例数据。弹出框默认为“是”,允许您在继续操作之前选择禁用示例数据。您的浏览器会在 Snowflake 会话 期间存储您对该问题的回复,直到下次会话才会再次询问您。您还可以使用您的 用户配置文件 来设置是否使用示例数据的偏好。

备注

如果该区域支持 Snowflake Cortex,则示例数据可以跨越区域边界。有关更多信息,请参阅 LLM regional requirements

成本注意事项

生成描述会产生以下费用:

  • 正在使用的仓库消耗的 credit。

  • 因使用 Snowflake Cortex 与较小的 LLMs(例如 Mistral-7b 和 Llama 3.1-8b)而收取的 credit。这些费用作为 AI 服务出现在账单上,其中包括 Snowflake Cortex 的所有使用情况。