配置数据代理的最佳做法

本文概述了配置数据代理以提供准确、相关且有用的响应以回答用户问题的最佳做法。 通过设置明确的代理级别和特定于数据源的说明,可以指导代理如何解释查询、选择数据源和生成响应。 你将了解如何定义代理的目标、确定数据源的优先级、合并关键术语并为常见方案提供查询逻辑。 这些配置提示有助于确保代理跨各种数据环境和用户需求可靠地执行。

若要浏览不同类型的数据代理配置,请参阅 数据代理配置

1. 让数据为 AI 使用做好准备

为了确保数据代理可以生成准确的查询,数据源、表和列使用清晰的描述性名称非常重要。 避免模糊或泛型标签,例如 Table1col1或者 flag,这可能会使代理难以解释用户意图。

效率较低:

  • 表名称: Table1Table2
  • 列名:col1statusflag

更好:

  • 表名称:CustomerOrders、、ProductCatalogSalesTransactionsOrderItems
  • 列名:customer_email_addressorder_submission_dateproduct_unit_price

描述性命名有助于代理了解数据结构并改进生成的查询的质量。

2.为特定域创建专用代理

为了提高准确性和相关性,请设计专注于特定域或用例的数据代理,而不是尝试处理各种问题。 可以使用目标指令、相关数据源和特定于域的术语来优化专用代理,使它们更加可靠且有效。

效率较低: 一种通用数据代理,可跨不同用户角色回答各种客户相关问题

更好: 一个为支持领导团队而定制的数据代理,结合来自多个数据源的见解进行会议准备

通过缩小代理的焦点,可以改进其生成精确响应和减少查询解释中的歧义的能力。

3. 最小化数据源范围

仅包含回答预期用户问题所需的数据源。 在每个数据源中,仅选择与用例相关的特定表和列。 更集中的配置可以提高代理生成准确高效的查询的能力。

效率较低: 将整个 Lakehouse 或模型连接到所有表和列

更好: 仅选择常见查询所需的基本表和列

小窍门

为获得最佳结果,请将给定数据源的表数限制为 25 或更少

4. 明确说明该做什么,而不仅仅是不该做什么。

而不是仅说明代理应避免的内容,而是提供有关正确方法的明确指导。 这有助于代理更有效地响应,并避免在处理边缘事例时出现歧义。

效率较低: 不要提供过时的薪酬信息或对缺失数据的假设。
更好: 始终提供官方工资系统提供的最新薪酬信息。 如果工资缺失或不完整,请通知员工你找不到当前记录,并建议他们联系 HR 以获取进一步帮助。

5. 定义业务术语、缩写和同义词

若要确保数据代理正确解释问题,请定义任何可能不明确、组织特定或特定于域的术语。 这些定义可帮助代理应用一致的逻辑并生成准确的响应,尤其是在用户问题引用内部术语或类似概念时。

要定义的内容的示例

  • 类似的概念: "calendar year""fiscal year"
  • 常见业务术语: "quarter"、、 "sales""SKU""shoes"
  • 缩写或首字母缩略词: "NPS" (净推荐值), "MAU" (每月活跃用户)

定义应放在何处

  • 代理级说明:将此用于适用于所有数据源和查询的定义(例如,“季度”表示的内容)。
  • 数据源说明:用于定义术语在特定数据集内的使用方式(例如,“销售”在不同系统中有不同定义)。

6. 使用引导词来推动查询生成

在数据源指令中,可以包含 SQL/DAX/KQL 语法的提示或片段,以指导模型以特定格式生成查询。 这些“前导词”可帮助代理在将自然语言转换为代码时推断出正确的逻辑。

效率较低:
查找所有名称中包含“bike”的产品。

更好:
查找包含“bike”的名称的所有产品
LIKE '%bike%'

在查询中包括如 LIKE '%...%' 这样的语法片段,有助于模型识别出预期的模式匹配子句。 此方法可提高生成的 SQL 的准确性,尤其是在处理部分匹配、筛选器或联接时。

7. 编写清晰、集中的说明:避免不必要的详细信息

说明应简洁且有目的。 仅包含帮助代理生成准确响应所需的信息。 避免模糊、过时或过于广泛的内容,这些内容会导致混淆或稀释代理的焦点。

效率较低:

You are an HR data agent who should try to help employees with all kinds of questions about work. You have access to many systems, like the HRIS platform, old payroll databases from previous vendors, archived employee files, scanned PDF policy documents, and maybe even some spreadsheets that HR used in the past. If someone asks about their pay, you might want to look in one of the old systems if needed. Also, sometimes data isn't updated immediately, so just do your best. Remember that the company reorganized in 2017, so department names might be different before then. Try to be friendly, but also make sure you don’t seem robotic. Sometimes HR policies change, so answers might not always be the same depending on the date. Just explain if something seems complicated.

为什么这不太有效?

  • 范围太宽(“关于工作的各种问题”)
  • 引用过时或不可靠的源(例如“旧的工资数据库”)
  • 缺少数据源的优先级
  • 引入不必要的历史背景
  • 使用短语(如“只尽最大努力”)创建歧义
  • 缺少处理缺失或复杂数据的明确指南

更好:

You are an HR Assistant Agent responsible for answering employee questions about employment status, job details, pay history, and leave balances.  
Use the official HR data warehouse to retrieve current and accurate records.  
If data is missing or unclear, inform the user and recommend they contact HR for further support.  
Keep responses concise, professional, and easy for employees to understand.

为什么这样更好?

  • 明确代理范围和职责
  • 在不重载技术详细信息的情况下引用正确的数据源
  • 提供明确的回退机制
  • 确立语气和沟通风格
  • 将表级细节留给数据源指南

8. 编写详细的数据代理说明

代理说明定义代理 如何解释用户问题、选择数据源和设置响应格式。 使用此部分可以清楚地描述代理的角色、预期行为、语气以及它应如何处理不同类型的查询。 在缺少信息时,包括有关预期用例、首选数据源和回退行为的特定详细信息。

小窍门

编写代理说明时,请问自己:不熟悉这些数据源的人是否能够了解要使用哪些源,以及如何根据说明使用它们? 否则,请修改说明以包含缺少的上下文。

效率较低:

You are an agent that helps with HR topics.  
Find answers if possible.  
Try not to give wrong information.  
If you cannot find something, you can tell the user to check elsewhere.  
Answer employee questions about work, pay, and other topics using available systems.  
Keep responses professional.

更好:

## Tone and style
Use clear, simple, and professional language.  
Sound friendly and helpful, like an internal HR support agent.  
Avoid technical jargon unless it's part of the business terminology used in the data.

## General knowledge
You are an HR Assistant Agent designed to help employees access accurate information about their employment, benefits, and pay.  
Only answer questions using the official HR data sources provided.  
If multiple records exist, prioritize the most recent and most official source.  
Do not guess or assume answers—if information is missing or unclear, advise the employee to contact HR directly.  

## Data source descriptions
- **Employee Data Warehouse**: Contains employment records including status, role, start date, and department.
- **Payroll System**: Contains pay history, compensation details, and tax withholding information.
- **Benefits Enrollment Database**: Includes information about health insurance, retirement plans, and other employee benefits.
- **HR Policy Lakehouse**: Stores official company policies, including holidays, leave policies, and onboarding documents.

## When asked about
- **Employment status (e.g., active, on leave, terminated)**: Use the *Employee Data Warehouse*  
- **Pay history or compensation**: Use the *Payroll System*  
- **Benefits and enrollment details**: Use the *Benefits Enrollment Database*  
- **Company holidays and leave of absence policies**: Use the *HR Policy Lakehouse*

9. 提供详细的数据源说明

数据源说明 应具有特定性、结构化性和描述性。 它们通过定义如何组织数据、哪些表和列相关以及如何处理表之间的关系来指导代理形成准确的查询。

使用此部分来描述:

  • 数据源的用途
  • 它打算回答哪种类型的问题
  • 响应中需要包含的列
  • 表之间的联接逻辑
  • 典型值格式(例如缩写与全名)

小窍门

假设第一次使用此数据集的新团队成员能否按照这些说明编写正确的查询?
如果没有,请添加缺失的上下文、阐明假设或包括示例查询来指导它们。

小窍门

在执行查询之前,数据代理看不到单个行值。
为了指导筛选逻辑,请包括典型值和格式的示例,例如,指定某列是使用缩写 State,还是使用全名 "CA",如 "California"

效率较低:

## General instructions
Use the EmployeeData warehouse to find answers about employees.  
Try to get useful employee details when needed.

### Employment status
You can use the EmployeeStatusFact table.  
Join to EmployeeDim if necessary.

更好:

## General instructions
Use the EmployeeData data warehouse to answer questions related to employee details, employment status, pay history, and organizational structure.

When generating queries:
• Use EmployeeDim as the primary table for employee details.  
• Always include the following columns in the response (if available):  
  - EmployeeID  
  - EmployeeName  
  - EmploymentStatus  
  - JobTitle  
  - DepartmentName  
• Join other tables to EmployeeDim using EmployeeID unless otherwise specified.  
• Filter for the most recent records when applicable.  

Example values:
- EmploymentStatus: "Active", "On Leave", "Terminated"  
- DepartmentName: "Finance", "HR", "Engineering"  
- State: Use U.S. state abbreviations like "CA", "NY", "TX"

## When asked about

When asked about **employee status**, use the `EmployeeStatusFact` table.  
Join it to `EmployeeDim` on `EmployeeID`.  
Filter by the most recent `StatusEffectiveDate` and return the following columns: `EmploymentStatus`, `StatusEffectiveDate`, `EmployeeName`, and `DepartmentName`.

When asked about **current job title or department**, use the `EmployeeDim` table.  
Return `JobTitle` and `DepartmentName`.  
If multiple records exist, filter for the record where `IsCurrent = True`.

10. 使用示例查询来表达复杂的查询逻辑

使用 示例查询 来帮助数据代理了解如何构造准确的查询,尤其是在逻辑复杂或细微差别时。 这些示例充当代理可以从中通用化的模板,即使用户的问题不完全匹配。

  • 包括常见或具有代表性的问题类型的示例查询。
  • 重点介绍查询逻辑涉及筛选、联接、聚合或日期处理的示例。
  • 使用数据源的正确语法(SQL、DAX 或 KQL)保持结构清晰且格式正确。
  • 无需逐字匹配用户问题;示例应演示意向和结构。

小窍门

与尝试单独通过文本解释复杂逻辑相比,提供格式正确的查询通常更清晰、更高效。

如何使用示例查询

对于每个用户的问题,数据代理执行 矢量相似性搜索 以检索前 3 个最相关的示例查询。 然后,这些内容将传递到代理的扩充提示中,以指导查询生成。

后续步骤