

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 實作 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"]
             })
         }
     }
 };
```