

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

# 使用 Amazon Bedrock 知識庫從資料來源擷取資訊
<a name="kb-how-retrieval"></a>

設定知識庫之後，您可以設定應用程式來查詢其中的資料來源。若要查詢知識庫，您可以利用下列 API 操作：
+ [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_Retrieve.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_Retrieve.html) – 從與查詢最相關的資料擷取來源區塊或影像，並在回應中以陣列傳回它們。
+ [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html) – 將 `Retrieve` 與 Amazon Bedrock 中的 [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) 操作聯結，從與查詢最相關的資料擷取來源區塊，並產生自然語言回應。包含資料中特定來源區塊的引文。如果您的資料來源包含視覺化元素，模型會在產生文字回應時利用這些影像的洞見，並為影像提供來源屬性。
+ [GenerateQuery](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_GenerateQuery.html) – 將自然語言使用者查詢轉換為格式適合結構化資料存放區的查詢。

`RetrieveAndGenerate` 操作是合併的動作，基本會使用 `GenerateQuery` (如果您的知識庫連線至結構化資料存放區)、`Retrieve` 和 `InvokeModel` 來執行整個 RAG 程序。由於 Amazon Bedrock 知識庫也可讓您存取 `Retrieve` 操作，因此您可以靈活地分離 RAG 中的步驟，並根據您的特定使用案例進行自訂。

您也可以在使用 `Retrieve` 或 `RetrieveAndGenerate` 時，使用[重新排名模型](rerank.md)來重新排名查詢期間所擷取文件的相關性。

若要了解如何在查詢知識庫時使用這些 API 操作，請參閱 [使用查詢和回應測試您的知識庫](knowledge-base-test.md)。