Snowsight 中的 Cortex Code¶
概述
Cortex Code provides an agentic experience across several functional areas within Snowsight. It is designed to assist data analysts, engineers, and administrators with tasks such as SQL development, data exploration, and account management by deeply integrating into the Snowsight interface and offering capabilities such as diff views.
Cortex Code 使用智能编排,根据您的请求规划并执行多步骤任务。此外,它会从您的 Snowflake 环境中选择内部工具和相关上下文来完成任务,确保每次响应的准确性。
该助手遵循代理式工作流程,理解您的意图,制定行动计划并执行各个步骤,同时在整个会话过程中保持上下文。
Cortex Code 能理解角色、权限、架构以及 SQL 语法,并在生成或修改代码时应用 Snowflake 的最佳实践。
To use Cortex Code in Snowsight, follow these steps:
- Select the Cortex Code icon
in the lower-right corner. The Cortex Code panel opens on the right side of Snowsight. - In the message box, type in your question and then select the send icon or press
Enterto submit it. Cortex Code provides a response in the panel.
如果 Cortex Code 的响应中包含 SQL 语句,您可以直接执行这些语句,或将其复制到剪贴板。
访问控制要求
A role used to access Cortex Code must have the following database roles granted:
| Database Role | Notes |
|---|---|
| SNOWFLAKE.COPILOT_USER | Required for all users to access Cortex Code. |
| SNOWFLAKE.CORTEX_USER or SNOWFLAKE.CORTEX_AGENT_USER | At least one of these database roles is required. SNOWFLAKE.CORTEX_AGENT_USER provides additional capabilities for agentic workflows. |
For instructions on granting database roles, see GRANT DATABASE ROLE.
For general information about roles and access control, see Overview of Access Control.
Note
如果您的账户此前选择退出(或已禁用)Snowflake Copilot(旧版),Cortex Code 也会被禁用。请联系您的客户团队,为您的账户启用此功能。
使用案例和优势
Cortex Code in Snowsight acts as an intelligent agent, helping you work more efficiently by translating natural language instructions into executable actions. By maintaining awareness of your workspace context and Snowflake account configuration, it assists with development, exploration, and administration tasks without requiring you to leave Snowsight.
Cortex Code supports the following key functional areas within Snowsight:
工作区中的代理式编码
Cortex Code 作为集成在 Workspaces 中的对话式编码助手运行。它支持交互式代码生成、修改、审查和解释。
- 代码生成和开发: 生成 SQL 查询、创建新文件,并为数据管道和分析工作流构建逻辑。
- 代码修改和优化: 直接在工作区中优化 SQL,识别逻辑或语法错误,并针对性能、可读性或成本提出优化建议。
- 变更审核: 在应用更改之前,通过差异视图预览 AI 建议的修改。差异视图会高亮显示新增和删除内容,使用户能够保持对代码的控制。
- 代码解释: 请求对现有 SQL 的解释,以帮助理解或协作。
- 提出后续问题: 通过提出澄清问题,或请求对生成的代码或结果进行进一步分析,继续对话。
- Inline catalog context: Type
@in the message box to trigger a real-time search for catalog objects (such as tables, schemas, and views) and add them as context for your prompt. - Quick actions from highlighted SQL: In a SQL file, highlight text to open quick actions such as Quick Edit, Format, Add to Chat, and Explain.
- Fix SQL errors: If a SQL statement fails, use the Fix button in the results grid to get suggested fixes for the error.
- AI 支持的代码建议(目前为预览版): 当您在文件中输入 SQL,Cortex Code 会显示上下文感知的内联建议,以提高开发速度和准确性。
AI 代码建议¶
Cortex Code 为 Snowflake 中的 SQL 提供智能、上下文感知的内联代码。当您在文件中输入 SQL,Cortex Code 会预测并建议 SQL 语句的下一部分,在光标位置显示为灰色文本。
Cortex Code 使用您的查询历史记录、当前工作区的内容、表架构以及当前工作区中最近执行的几次查询来匹配您的工作模式并生成建议。
在您输入时短暂停顿后,或者刚接受上一个建议后,建议会自动触发。
与建议交互时,您可以执行以下操作:
- To accept a suggestion, press
Shift+Enter. - To dismiss a suggestion, press
Esc,Delete, orBackspace, or continue typing.
When catalog suggestions appear alongside an inline suggestion, press Shift + Enter to accept the inline suggestion, or press the
down arrow and then Enter to select a catalog option instead.
Note
AI 代码建议有时可能不正确或不符合您的意图。如果建议不相关,请忽略它并继续输入以提供更多上下文。
要禁用 AI 代码建议,请执行以下步骤:
- Sign in to Snowsight.
- In the navigation menu, select Projects » Workspaces.
- From a SQL file, select the Settings icon in the upper-right corner.
- Select User preferences.
- Select the AI code suggestions toggle to disable the feature.
- Select Close.
智能产品与文档发现
Cortex Code 利用 Horizon Catalog 和 Snowflake 文档中的上下文,帮助您在不离开工作区的情况下定位数据资产和参考信息。
- 自然语言架构搜索: 使用自然语言查询定位表、列等数据库对象,无需了解确切的对象名称。
- 集成问答: 基于官方文档,检索有关 Snowflake 功能、SQL 语法或最佳实践的答案。
- Snowflake Marketplace 发现: 如果提示中涉及 Snowflake Marketplace,Cortex Code 将搜索并返回 Marketplace 中的相关列表。
在可用情况下,响应还可能包含标签、掩码策略和数据沿袭等上下文信息,以帮助您验证所发现的数据资产。
简化账户管理
Cortex Code 通过提供治理、安全和成本管理相关的上下文信息,支持账户管理任务。
- 治理和安全: 检索有关用户和角色访问权限、数据所有权,以及包含个人身份信息 (PII) 的表。
- 成本管理: 查询账户使用情况和 Credit 使用量,并识别高成本的仓库或查询。
支持的模型和区域
Cortex Code supports the following models. You can use these models as long as the account has access to them. For more information, see Control model access.
- Recommended: Claude Opus 4.6 (
claude-opus-4-6) - Claude Opus 4.5 (
claude-opus-4-5) - Claude Sonnet 4.5 (
claude-sonnet-4-5) - Claude Sonnet 4.0 (
claude-4-sonnet)
While the listed models may not be available in all regions, you can use Cortex Code in any cloud or region by using Cortex Cross-region inference. This includes clouds and regions where the models are not available. For more information, see Cross-region inference.
Important
当所选模型在您所在区域不可用时,需要跨区域推理。 如果推理失败并出现模型可用性错误,请配置跨区域推理:
- AWS US - Claude Opus 4.6 offers the highest quality. Set up Cortex Cross-region inference for
AWS_USto access Claude Opus 4.6 models. - AWS EU - Set up Cortex Cross-region inference for
AWS_EUto access Claude models. - AWS APJ - Set up Cortex Cross-region inference for
AWS_APJto access Claude models. - AWS AU - Set up Cortex Cross-region inference for
AWS_AUto access Claude Opus 4.6 models. - Any region - Set up Cortex Cross-region inference for
ANY_REGIONto access all models.
要启用跨区域推理,ACCOUNTADMIN 必须运行:
Replace AWS_US with the appropriate region identifier (AWS_US, AWS_EU, AWS_APJ, AWS_AU, ANY_REGION).
Note
Model access may also be restricted by your organization. If you cannot access a model even after enabling cross-region inference, verify that the model is enabled in your account’s AI model access settings. See Control model access for details.
Cortex Code 要求用户具备 SNOWFLAKE.COPILOT_USER 数据库角色,并且还需拥有 SNOWFLAKE.CORTEX_USER 或 SNOWFLAKE.CORTEX_AGENT_USER 数据库角色之一。
Note
如果您的账户此前选择退出(或已禁用)Snowflake Copilot(旧版),Cortex Code 也会被禁用。请联系您的客户团队,为您的账户启用此功能。
Web 搜索¶
ACCOUNTADMIN 角色可以配置 Cortex Code CLI 以进行 Web 搜索,并在生成响应和规划任务时使用搜索结果。要在账户中正确启用 Web 搜索,请按照以下步骤操作:
- Navigate to AI/ML > Agents.
- Select Settings.
- Select the toggle next to Web search to enable the feature, as shown below.

Snowflake will process your inputs according to the Snowflake Privacy Notice (§2). Web search may not be used for the purpose of redistributing or creating a competing web search service.
示例提示
您可以使用自然语言提示与 Cortex Code 进行交互。在提示中,请提供生成准确结果所需的上下文信息(例如数据库、架构以及要操作的对象)。为了在不同环境中获得最可靠的结果,建议使用完全限定的对象名称。
以下示例展示了请求代码生成、优化以及管理洞察的常见方式。
访问和权限
| 用例 | 示例提示 |
|---|---|
| 访问发现 | “我可以访问哪些数据库?” |
| 安全审计 | “查找所有包含 PII 的表。” |
数据发现
| 用例 | 示例提示 |
|---|---|
| 标签发现 | “列出 ANALYTICS_DB 中所有标记为 PII = TRUE 的表。” |
| 沿袭和标记 | “显示从 RAW_DB.ORDERS 到下游仪表板的数据沿袭。” |
| 元数据搜索 | “在哪里可以找到与客户流失和订阅状态相关的表?” |
SQL 开发和优化
| 用例 | 示例提示 |
|---|---|
| 逻辑解释 | “此 SQL 脚本的作用是什么?” |
| 生成 | “编写一个查询,按收入排序列出前 10 位客户,并计算 7 天移动平均值。” |
| 查询优化 | “将最佳表现者查询更新为显示前 100 名。” |
| 性能优化 | “解释此查询为何执行缓慢,并对其进行优化。” |
| 数据合成 | “在 SAMPLESDATA.SALES 表中生成 30 天的电子商务网站销售合成数据。” |
基础设施和成本管理
| 用例 | 示例提示 |
|---|---|
| 资源监视 | “哪 5 种服务类型消耗的 Credit 最多?请展示可视化结果,并说明如何降低成本。” |
机器学习和工程管道
| 用例 | 示例提示 |
|---|---|
| 笔记本(EDA 与机器学习) | “为客户流失预测用例构建一个笔记本,使用 pandas 进行数据处理,使用 matplotlib 和 seaborn 进行 EDA 和可视化,并使用 scikit-learn 进行预处理、模型训练(逻辑回归和基于树的模型)、评估和解释,同时通过清晰的 Markdown 说明业务影响和结果。” |
| 深度学习 | “创建一个新笔记本,并为 MNIST 数据集构建一个 CNN。” |
| 管道工程 | “创建一个 dbt 项目,用于转换原始销售数据。” |
语义模型集成 (Cortex Analyst)
| 用例 | 示例提示 |
|---|---|
| 语义查询 | “Use the @models/revenue.yaml semantic model to answer “What was revenue last month?”” |
| 模型调试 | “识别 @models/revenue.yaml 中语义模型的错误。” |
安全性和访问权限
Cortex Code operates within your Snowflake account’s existing authentication and role-based access controls (RBAC). It does not store or modify your credentials and only performs actions permitted by the active role.
Cortex Code always starts a session using your default role, regardless of the role you’ve selected in Snowsight worksheets, workspaces, or the role selector in the lower-left corner of the UI. If you need to perform actions that require a different role, you can ask Cortex Code to change roles during the session (for example, “switch to the SYSADMIN role”).
Note
If Cortex Code returns a permissions error, verify that your default role has the required privileges. You can either change your default role using ALTER USER, or ask Cortex Code to use a specific role for the current session.
工作区中的 Cortex Code¶
You can access Cortex Code through the assistant panel integrated into Snowsight. Cortex Code processes requests in the context of the active code or environment, or general Snowflake knowledge.
要在工作区中使用 Cortex Code 代理,请执行以下操作:
- Sign in to Snowsight.
- In the navigation menu, select Projects » Workspaces.
- 打开包含相关文件的工作区(例如,现有 SQL 文件)。
- Select the Cortex Code icon at the bottom-right of the workspace.
- Enter a prompt or ask a question using natural language. Type
@to search for and add catalog objects (such as tables, schemas, or views) as inline context. See 示例提示 for ideas. - 查看输出结果。Cortex Code 会返回答案、代码建议或修改后的查询。
- 对于编码任务,Cortex Code 可能会显示比较视图,用于高亮显示新增和删除的内容。查看建议的修改,并可直接将其应用到脚本中。
- 可通过后续提示进一步优化代码,将文件转换为其他对象类型(如笔记本或语义视图),或集成 AI SQL 等高级功能。
使用 AGENTS.md 和代理技能在工作区中自定义 Cortex Code¶
AGENTS.md (http://Agents.md) is a simple, open format for guiding coding agents.
创建一个 AGENTS.md 文件,用于提供持久化指令,Cortex Code 会在每次对话中自动加载这些指令。将该文件复制到工作区的根目录,以便在与 Cortex Code 就项目进行交互时应用个性化指令。
Support for Agent Skills (https://agentskills.io/) will be available soon.
Skill¶
Skills extend Cortex Code with specialized capabilities that can be invoked by typing / in the message box.
内置技能
Snowflake provides built-in skills that are available from any page in Snowsight. Type / to see and select from the available skills. The list of built-in skills evolves as feature teams add new skills to Snowsight.
个人技能
您可以在工作区中创建自己的技能,以便根据您的特定工作流程定制 Cortex Code。
要添加个人技能,请使用工作区中的以下任一选项:
- Upload Skill File(s)
- Upload Skill Folder(s)
- + Create Skill
Personal skills are stored in the .snowflake/cortex/skills directory of the workspace and can be invoked by typing / in the message box.
Note
个人技能只能从创建个人技能的工作区中访问。当使用不同的工作区或在工作区之外时,它们不可用。
笔记本中的 Cortex Code¶
Leveraging Cortex Code helps you explore data, write and edit queries and code, visualize insights, and explain results seamlessly in Notebooks in Workspaces, accelerating end-to-end data science and machine learning development.
笔记本中的 Cortex Code 支持以下功能:
- 在工作区目录中创建和管理笔记本
- 添加、移除并重新排序 SQL、Python 和 Markdown 单元格
- 使用最新的预安装的包和正确的笔记本语法(例如单元格引用)编辑代码
- 生成使用 matplotlib、seaborn、plotly 和 altair 的数据可视化代码
- 运行整个笔记本或指定单元格
Try out these example prompts.
Cortex Code agent for dbt Projects on Snowflake¶
Cortex Code 支持覆盖整个 dbt 生命周期的转换工作流,包括:
- 探索原始源数据并推断数据之间的关系
- 快速构建暂存模型和中间模型
- 构建多模型 DAGs 及相关指标
- 添加数据质量测试和增量加载逻辑
- 运行 dbt 命令
- 生成并维护项目文档
Cortex Code 代理可通过自然语言提示,帮助您完成数据探索、dbt 模型编写、测试添加、性能优化,并通过迭代反馈生成文档。
它通过自动化处理 SQL 样板代码、依赖管理、测试和文档,显著减少日常数据工程工作量,同时仍保留对项目结构和业务逻辑的控制。
dbt 项目的示例提示¶
Cortex Code 代理同时适用于 dbt 新手和有经验的用户。新用户可以探索新接入的 Bronze 层数据、推断架构,并快速搭建暂存模型,建立清晰、规范的基础。有经验的用户则可以通过增量事实模型、完善的测试以及自动生成的文档,构建复杂的数据集市,并在验证周期中快速迭代。
以下场景展示了在 dbt 项目中使用 Cortex Code 的常见方式。
| 用例 | 上下文 | 示例提示 |
|---|---|---|
| 探索来源 | 在建模之前,了解原始数据的结构和关系。 | “列出 Bronze 层中的所有源表,并汇总关键列、数据类型以及可能的主键。为每个数据源提出暂存模型建议。” |
| 原型设计 | 创建多模型逻辑和 DAGs。 | “创建模型,按卡车和地点计算每日盈利能力。生成 DAG 并提出依赖关系建议。” |
| 数据质量 | Adding tests to schema.yml. | “为关键维度添加 not_null 和 accepted_values 测试。基于推断出的键,为 IDs 建议唯一性测试。” |
| 增量逻辑 | 优化模型性能。 | “将主要事实模型转换为按 order_date 分区的增量模型,并为迟到数据设置合并行为。” |
| 文档 | 降低维护成本。 | “为项目生成文档,并根据源数据上下文,为新模型和关键字段撰写说明。” |
Cortex Code、Snowflake Intelligence 与旧版 Copilot¶
尽管 Cortex Code 支持广泛的编码和管理任务,但它不同于独立的编码代理,也区别于 Snowflake 中其他专用的 AI 系统。
The following table summarizes key differences between Cortex Code, Snowflake Intelligence, and the legacy Copilot experience.
| Feature | Cortex Code | Snowflake Intelligence | Snowflake Copilot (legacy) |
|---|---|---|---|
| Use case | Supports development and operational workflows in Snowflake, including authoring SQL, exploring data assets, and performing administrative tasks. | Provides a natural language interface for asking complex questions about data and receiving analysis-focused responses. | Previous iteration of Cortex Code for documentation help and basic SQL assistance. |
| Primary integration | Integrated directly into Snowsight and Workspaces. Provides context-aware assistance within the active workspace. | Accessed through the Snowflake Intelligence UI and Cortex Agents API, enabling natural language interaction for insights and recommendations. | Separate copilot for SQL and UI assistance. |
| Scope of tasks | Supports SQL authoring, data exploration, documentation search, and account administration. | Focuses on question answering, data insights, and analysis-driven responses. | Limited SQL and UI assistance. |
| Key capabilities | Generates and modifies SQL code, reviews changes using a diff view, and explains existing code. | Analyzes data, generates summaries, and assists with natural language interactions. | Contextual SQL suggestions and limited help features. |
| Design focus | Provides a unified AI interface across coding, documentation, and administrative workflows. | Delivers conversational insights and query assistance for data understanding. | Deprecated in favor of Cortex Code. |
Legal notices¶
Where your configuration of Cortex Code uses a model provided on the Model and Service Pass-Through Terms, your use of that model is further subject to the terms for that model on that page.
The data classification of inputs and outputs are as set forth in the following table.
| Input data classification | Output data classification | Designation |
|---|---|---|
| Usage Data | Customer Data | Covered AI Features [1] |
For additional information, refer to Snowflake AI and ML.