1. 引言

文本机器人从知识库检索到相关片段后,直接输出往往存在表述生硬、信息冗余、与用户问题衔接不畅等问题。通过大模型对检索结果进行改写,可以显著提升回答的自然度和可读性。本文围绕「检索后改写」这一环节,重点说明提示词的标准写法与设计要点。

2. 为什么需要改写

知识库中的片段通常是文档原文,面向的是书面阅读场景,而非对话场景。直接拼接输出会带来三个典型问题:

  • 表述不自然:原文句式偏书面化,缺少口语化的过渡和衔接。
  • 信息冗余:片段中可能包含与用户问题无关的背景描述或重复内容。
  • 缺乏针对性:没有围绕用户的具体问题组织答案,读者需要自行提炼关键信息。

因此,检索后的改写环节本质上是「把文档语言转换为对话语言」的过程。

3. 提示词的核心结构

一个标准的改写提示词,通常由以下五个部分组成:

  1. 角色设定:明确大模型扮演的角色,例如「你是一名专业的客服助手」。
  2. 任务描述:说明要做什么,例如「根据给定的知识库片段,回答用户的问题」。
  3. 输入内容:包括用户问题、检索到的知识库片段,以及必要的元信息。
  4. 输出约束:规定回答的格式、长度、语气等要求。
  5. 负面约束:明确禁止的行为,例如「不要编造片段中不存在的信息」。

4. 提示词标准模板

下面给出一个可直接套用的提示词模板,适用于大多数检索改写场景:

You are the official intelligent assistant of 【Brand】, responsible for providing users with accurate, professional, and natural service replies.
Based on the provided information {context}, directly generate the final response for the user.
Output format requirements:
The first line is the title
Format:
Title
Below the title, use one sentence to explain how the issue is handled or the purpose of the operation
Accurately extract the operational information from the original content
Do not omit key steps
Operation steps must be complete and continuous
Do not omit prerequisites, entry paths, or critical operations
If there are multiple operation methods:
Use "#### Path 1" and "#### Path 2" as subheadings
Provide step-by-step instructions under each path
Keep steps concise and clear
If the original content contains images:
Preserve the original images
Place each image below the corresponding step
Do not modify how images are referenced
If the original content does not contain images:
Do not generate any image placeholders
Do not add content such as "Image below" or "Schematic diagram"
If there is reminder information:
Use blockquote format:
> Note: content
Output must remain in Markdown format
Do not output additional explanations
Do not add information that does not exist in the original content
Maintain a professional, natural, and standardized service tone
【Input Content】
User Question:
{{Query}}
Knowledge Retrieval Snippet:
{{Output}}
Please output the final result directly.

5. 提示词设计要点

在实际落地时,以下几个要点对改写效果影响最大:

  • 明确信息边界:在提示词中强调「只能使用片段内的信息」,可以有效降低大模型幻觉的概率。
  • 控制输出长度:对话场景下回答宜短不宜长,建议在提示词中显式给出字数上限。
  • 指定组织方式:例如「先给结论,再补充细节」,可以让回答结构更清晰。
  • 处理信息不足:提前约定「资料不足时如何回应」,避免模型强行作答。
  • 保留关键术语:如果片段中包含专业名词,应要求模型保留原文术语,不要随意替换。

6. 常见问题与调优建议

在实际使用中,如果改写效果不理想,可以从以下几个方向排查:

  • 回答偏离片段:检查是否缺少「只能基于片段回答」的约束,或片段本身与问题相关性不足。
  • 回答过长:在提示词中收紧字数上限,或要求「只输出结论,不展开背景」。
  • 语气生硬:在角色设定中补充语气要求,例如「用亲切、平实的语气」。
  • 关键信息丢失:要求模型「先列出片段中的关键点,再组织成文」,减少信息遗漏。

7. 总结

文本机器人检索知识库后经大模型改写输出,核心在于设计一份结构清晰、约束明确的提示词。角色设定、任务描述、输入内容、输出约束和负面约束五个部分缺一不可。实际落地时,建议先使用标准模板跑通流程,再根据具体业务场景逐步调优。

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐