跳到主内容

指令

指令是帮助指导 Wren AI 如何生成 SQL 查询和响应的指南。它们允许您定义业务规则、数据模型理解和查询模式,以确保生成一致、准确且符合您组织特定需求的结果。

Instructions

指令有两种形式

  • 全局指令:适用于所有查询,无论提出的问题是什么
  • 问题匹配指令:仅当用户的问题匹配特定模式或主题时应用

通过配置指令,您可以

  • 强制执行一致的命名约定和格式
  • 实施业务规则和数据过滤标准
  • 指导如何计算特定的业务概念
  • 确保使用正确的表连接和关系
  • 标准化输出格式以提高可读性

全局指令

全局指令适用于 Wren AI 生成的每一个查询。它们非常适合设置一致标准、强制执行业务规则以及指导 Wren AI 如何解释您的数据模型。

添加全局指令

Add Global Instruction

添加全局指令的步骤

  1. 导航到“知识”选项卡
  2. 点击“添加指令”按钮
  3. 在“应用指令到”下选择“全局”
  4. 在文本字段中输入您的指令详情
  5. 点击“提交”保存并应用指令

示例 - 订单状态过滤

Global Instruction Example Form

一个常见的需求是确保计算中一致处理订单状态。这是一个全局指令示例,用于标准化订单过滤

Exclude orders with `order_status IN ('canceled', 'unavailable')` from any sales or revenue-related calculations.

有了此指令后,当用户提问“上个月的总收入是多少?”时,Wren AI 将生成包含正确过滤条件的 SQL

Global Instruction Example

如您所见,SQL 查询包含 WHERE 子句,该子句将取消和不可用的订单排除在计算之外。

更多示例

四舍五入到小数点后两位

Always round all floating point numbers (e.g., revenue, averages, percentages) to 2 decimal places using the `ROUND(..., 2)` function in SQL.

对可选表使用 LEFT JOIN

Always use LEFT JOIN when joining optional or non-required tables like reviews or payments, to prevent loss of rows.

使用特定语言输出列别名

Always output column alias with Traditional Chinese.

问题匹配指令

问题匹配指令仅当用户的问题匹配特定模式或主题时应用。它们非常适合指导 Wren AI 如何处理特定的业务概念、指标或分析类型。

添加问题匹配指令

Add Question-Matching Instruction Form

添加问题匹配指令的步骤

  1. 导航到“知识”选项卡
  2. 点击“添加指令”按钮
  3. 在“应用指令到”下选择“匹配特定问题”
  4. 在文本字段中输入您的指令详情
  5. 添加应触发该指令的问题
  6. 点击“提交”保存并应用指令

示例 - 延迟交货分析

对于关于交货表现的问题,您可能希望确保对何为“延迟交货”有一致的定义。这是一个用于此目的的问题匹配指令示例

Question-Matching Instruction Example Form

匹配的问题

  • 我们的延迟交货率是多少?
  • 有多少订单被延迟?
  • 多少百分比的交货是延迟的?

指令详情

Use the difference between `order_estimated_delivery_date` and `order_delivered_customer_date` from `olist_orders_dataset`. 
If the delivered date is later than the estimated date, consider it a late delivery.

当用户提问“我们的交货有多少百分比是延迟的?”时,Wren AI 将生成 SQL,根据您定义的标准准确计算延迟交货

Question-Matching Instruction Example Answer

答案显示了延迟交货的百分比。

Question-Matching Instruction Example SQL

如您所见,SQL 查询比较了 olist_orders_dataset 表中的 order_estimated_delivery_dateorder_delivered_customer_date,这与指令中的定义一致。

这确保了在分析整个组织的交货表现时采用一致的方法。

更多示例

对于关于“产品退货率”或“退货比例”的问题

匹配包含“产品退货率”或“退货比例”的问题。

Olist does not explicitly include returns, so treat orders with `order_status = 'canceled'` as proxy for returned/canceled orders.
Use the ratio of canceled orders to total orders.

对于关于“卖家表现”或“优秀卖家”的问题

匹配包含“卖家表现”或“优秀卖家”的问题。

Aggregate revenue and order counts by `seller_id` from `olist_order_items_dataset`. Join with `olist_orders_dataset` to apply filters like date or status.

管理指令

您可以从指令管理页面查看、编辑和删除您的指令

Instructions Management