

# 实现 RAG
<a name="speech-rag"></a>

**注意**  
本文档适用于 Amazon Nova 版本 1。如需 Amazon Nova 2 Sonic 指南，请访问[工具配置](https://docs.aws.amazon.com/nova/latest/nova2-userguide/sonic-tool-configuration.html)。

检索增强生成（RAG）可检索知识库并纳入其中的信息，从而改进回复。在 Amazon Nova Sonic 中，RAG 需通过“工具使用”来实现。

## 知识库实现概述
<a name="speech-rag-implement"></a>

实现 RAG 需要以下元素：
+ **配置工具**：在 `promptStart` 事件中定义知识库搜索工具。
+ **接收工具使用请求**：当用户提出问题时，模型将调用知识库工具。
+ **查询向量数据库**：根据向量数据库执行搜索查询。
+ **返回结果**：将搜索结果发送回模型。
+ **生成回复**：模型将检索到的信息纳入其语音回复中。

## 知识库配置
<a name="speech-rag-tool"></a>

以下是基础知识库工具的配置示例：

```
{
     toolSpec: {
         name: "knowledgeBase",
         description: "Search the company knowledge base for information",
         inputSchema: {
             json: JSON.stringify({
                 type: "object",
                 properties: {
                     query: {
                         type: "string",
                         description: "The search query to find relevant information"
                     }
                 },
                 required: ["query"]
             })
         }
     }
 };
```