

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

# 將變更直接擷取到知識庫
<a name="kb-direct-ingestion"></a>

Amazon Bedrock 知識庫可讓您修改資料來源，並在一個步驟中同步變更。如果您的知識庫連接到以下其中一種資料來源類型，則可以利用此功能：
+ Amazon S3
+ 自訂

透過直接擷取，您可以在單一動作中直接新增、更新或刪除知識庫中的檔案，而且您的知識庫可以存取文件，而無需同步。直接擷取會使用 `KnowledgeBaseDocuments` API 操作，為您直接提交到為知識庫設定的向量存放區的文件編製索引。您也可以直接使用這些操作檢視知識庫中的文件，而不需要導覽至連線的資料來源即可檢視。

## 與同步資料來源的差異
<a name="kb-direct-ingestion-sync-diff"></a>

Amazon Bedrock 知識庫也提供一組與[同步資料來源](kb-data-source-sync-ingest.md)相關的 `IngestionJob` API 操作。當您使用 [StartIngestionJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_StartIngestionJob.html) 請求同步資料來源時，Amazon Bedrock 知識庫會掃描連線資料來源中的每個文件，並驗證它是否已編製索引到為知識庫設定的向量存放區中。如果尚未建立索引，則它會成為向量存放區的索引。

使用 [IngestKnowledgeBaseDocuments](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_IngestKnowledgeBaseDocuments.html) 請求，您可以提交要直接編製索引到向量存放區的文件陣列。因此，您可以略過將文件新增至資料來源的步驟。請參閱以下段落，以了解這兩組 API 操作的使用案例：

**如果您使用自訂資料來源**  
您不需要同步或使用 `IngestionJob` 操作。您使用 `KnowledgeBaseDocuments` 操作或在 AWS 管理主控台 中新增、修改或刪除的文件，會成為自訂資料來源和知識庫的一部分。

**如果您使用 Amazon S3 資料來源**  
您可以在不同的使用案例中使用這兩組操作：
+ 第一次將知識庫連線至 S3 資料來源後，您必須在 AWS 管理主控台 中同步資料來源，或透過 Amazon Bedrock API 提交 [StartIngestionJob](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_StartIngestionJob.html) 請求。
+ 將文件索引至為您的知識庫設定的向量存放區，或以下列方式移除索引文件：

  1. 將文件新增至 S3 位置或從中刪除文件。然後，在 AWS 管理主控台 中同步您的資料來源，或在 API 中提交 `StartIngestionJob` 請求。如需同步和 `StartIngestionJob` 操作的詳細資訊，請參閱 [將您的資料與您的 Amazon Bedrock 知識庫同步](kb-data-source-sync-ingest.md)。

  1. 使用 `IngestKnowledgeBaseDocuments` 請求直接將 S3 文件擷取至知識庫。如需直接擷取文件的詳細資訊，請參閱 [將文件直接擷取至知識庫](kb-direct-ingestion-add.md)。
**警告**  
對於 S3 資料來源，您直接在 AWS 管理主控台 中或使用 `KnowledgeBaseDocuments` API 操作編製知識庫索引的任何變更都不會反映在 S3 位置中。您可以使用這些 API 操作，在單一步驟中立即變更知識庫。不過，您應該在 S3 位置進行相同的變更，以便下次在 AWS 管理主控台 中或使用 `StartIngestionJob` 同步資料來源時，不會覆寫這些變更。  
請勿同時提交 `IngestKnowledgeBaseDocuments` 和 `StartIngestionJob` 請求。

選取主題，以了解如何在資料來源中執行直接擷取文件：

**Topics**
+ [與同步資料來源的差異](#kb-direct-ingestion-sync-diff)
+ [直接擷取的先決條件](kb-direct-ingestion-prereq.md)
+ [將文件直接擷取至知識庫](kb-direct-ingestion-add.md)
+ [檢視資料來源中文件的相關資訊](kb-direct-ingestion-view.md)
+ [直接從知識庫刪除文件](kb-direct-ingestion-delete.md)

# 直接擷取的先決條件
<a name="kb-direct-ingestion-prereq"></a>

若要使用直接擷取，IAM 角色必須具有使用 `KnowledgeBaseDocs` API 操作的許可。如果您的 IAM 角色已連接 [AmazonBedrockFullAccess](security-iam-awsmanpol.md#security-iam-awsmanpol-AmazonBedrockFullAccess)AWS 受管政策，您可以略過本節。

下列政策可以連線至 IAM 角色，以允許它對您在 `Resource` 欄位中指定的知識庫執行直接擷取。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "DirectIngestion",
            "Effect": "Allow",
            "Action": [
                "bedrock:StartIngestionJob",
                "bedrock:IngestKnowledgeBaseDocuments",
                "bedrock:GetKnowledgeBaseDocuments",
                "bedrock:ListKnowledgeBaseDocuments",
                "bedrock:DeleteKnowledgeBaseDocuments"
            ],
            "Resource": [
                "arn:aws:bedrock:us-east-1:123456789012:knowledge-base/${KnowledgeBaseId}"
            ]
        }
    ]
}
```

------

若要進一步限制許可，您可以忽略動作，也可以指定要篩選許可的資源和條件索引鍵。如需動作、資源和條件索引鍵的詳細資訊，請參閱*服務授權參考*中的下列主題：
+ [Amazon Bedrock 定義的動作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html#amazonbedrock-actions-as-permissions) – 了解動作、您可以在 `Resource` 欄位中限制其範圍的資源類型，以及您可以在 `Condition` 欄位中篩選許可的條件索引鍵。
+ [Amazon Bedrock 定義的資源類型](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html#amazonbedrock-resources-for-iam-policies) – 了解 Amazon Bedrock 中的資源類型。
+ [Amazon Bedrock 的條件索引鍵](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html#amazonbedrock-policy-keys) – 了解 Amazon Bedrock 中的條件索引鍵。

# 將文件直接擷取至知識庫
<a name="kb-direct-ingestion-add"></a>

本主題說明如何將文件直接擷取至知識庫。限制適用於您可以直接擷取的文件類型，視資料來源而定。如需可用來指定要擷取之文件的方法限制，請參閱下表：


****  

| Data source type (資料來源類型) | 文件已定義內嵌 | Amazon S3 位置中的文件 | 
| --- | --- | --- | 
| Amazon S3 | ![\[Red circular icon with an X symbol, indicating cancellation or denial.\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/images/icons/icon-no.png)否 | ![\[Green circular icon with a white checkmark symbol inside.\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/images/icons/icon-yes.png)是 | 
| Custom | ![\[Green circular icon with a white checkmark symbol inside.\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/images/icons/icon-yes.png)是 | ![\[Green circular icon with a white checkmark symbol inside.\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/images/icons/icon-yes.png)是 | 

展開對應您的使用案例的區段：

**注意**  
使用主控台時，您最多可以將 10 個文件直接擷取至您的知識庫。如果您改為使用 `IngestKnowledgeBaseDocuments` API，您最多可以將 25 個文件擷取至您的知識庫。如需此配額的詳細資訊，請參閱《AWS 一般參考指南》**中的 [Amazon Bedrock 服務配額](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#limits_bedrock)。

## 使用主控台
<a name="kb-direct-ingestion-add-console"></a>

若要直接在 中新增或修改文件 AWS 管理主控台，請執行下列動作：

1.  AWS 管理主控台 使用具有使用 Amazon Bedrock 主控台之許可的 IAM 身分登入 。接著，開啟位於 [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock) 的 Amazon Bedrock 主控台。

1. 在左側導覽窗格中選擇**知識庫**。

1. 在**知識庫**區段中，選取要擷取文件的知識庫。

1. 在**資料來源**區段中，選取要新增、修改或刪除文件的資料來源。

1. 在**文件**區段中，選擇**新增文件**。然後執行下列其中一項：
   + 若要直接新增或修改文件，請選取**直接新增文件**。然後，執行下列動作：

     1. 在**文件識別碼**欄位中，指定文件的唯一名稱。如果您指定的名稱已存在於資料來源中，則會取代文件。

     1. 若要上傳文件，請選取**上傳**。若要定義文件內嵌，請選取**新增文件內嵌**、選擇格式，然後在方塊中輸入文件的文字。

     1. (選用) 若要將中繼資料與文件建立關聯，請選取**新增中繼資料**，然後輸入索引鍵、類型和值。
   + 若要透過指定文件的 S3 位置來新增或修改文件，請選取**新增 S3 文件**。然後，執行下列動作：

     1. 在**文件識別碼**欄位中，指定文件的唯一名稱。如果您指定的名稱已存在於資料來源中，則會取代文件。

     1. 指定文件的 **S3 位置**是位於您目前的帳戶還是不同的 AWS 帳戶中。然後指定文件的 S3 URI。

     1. (選用) 若要將中繼資料與文件建立關聯，請選擇**中繼資料來源**。指定中繼資料的 S3 URI，或選取**新增中繼資料**，然後輸入索引鍵、類型和值。

1. 若要擷取文件和任何相關聯的中繼資料，請選擇**新增**。

## 使用 API
<a name="kb-direct-ingestion-add-api"></a>

若要使用 Amazon Bedrock API 直接將文件擷取至知識庫，請使用 [Amazon Bedrock 代理人建置時間端點](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt)傳送 [IngestKnowledgeBaseDocuments](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_IngestKnowledgeBaseDocuments.html) 請求，並指定知識庫的 ID 及其連線的資料來源。

**注意**  
如果您指定已存在於知識庫中的文件識別碼或 S3 位置，則會以新內容覆寫該文件。

請求內文包含一個欄位 `documents`，對應至 [KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 物件的陣列，每個欄位代表要新增至資料來源和擷取至知識庫的文件內容和選用中繼資料。[KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 物件包含下列欄位：
+ 內容 – 對應至 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 物件，其中包含要新增之文件內容的相關資訊。
+ 中繼資料 – (選用) 對應至 [DocumentMetadata](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentMetadata.html) 物件，其中包含要新增之文件中繼資料的相關資訊。如需如何在擷取期間使用中繼資料的詳細資訊，請參閱 [設定和自訂查詢和回應產生](kb-test-config.md) 中的**中繼資料和篩選**一節。

選取主題以了解如何擷取不同資料來源類型的文件，或查看範例：

**Topics**
+ [將文件擷取至連線至自訂資料來源的知識庫](#kb-direct-ingestion-add-custom)
+ [將文件擷取至連線至 Amazon S3 資料來源的知識庫](#kb-direct-ingestion-add-s3)
+ [範例請求內文](#w2aac28c10c23c19c17c11b3c19)

### 將文件擷取至連線至自訂資料來源的知識庫
<a name="kb-direct-ingestion-add-custom"></a>

如果您指定的 `dataSourceId` 屬於自訂資料來源，您可以為 `documents` 陣列中的每個 [KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 物件新增內容和中繼資料。

新增至自訂資料來源的文件內容可以透過下列方式定義：

#### 定義文件內嵌
<a name="kb-direct-ingestion-add-custom-inline"></a>

您可以定義下列類型的文件內嵌：

------
#### [ Text ]

如果文件是文字，[DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 物件應該採用下列格式：

```
{ 
    "custom": { 
        "customDocumentIdentifier": { 
            "id": "string"
        },
        "inlineContent": { 
            "textContent": { 
                "data": "string"
            },
            "type": "TEXT"
        },
        "sourceType": "IN_LINE"
    },
    "dataSourceType": "CUSTOM"
}
```

在 `id` 欄位中包含文件的 ID，並在 `data` 欄位中包含文件的文字。

------
#### [ Bytes ]

如果文件包含更多文字，請將其轉換為 Base64 字串。[DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 物件應該採用下列格式：

```
{ 
    "custom": { 
        "customDocumentIdentifier": { 
            "id": "string"
        },
        "inlineContent": { 
            "byteContent": { 
                "data": blob,
                "mimeType": "string"
            },
            "type": "BYTE"
        },
        "sourceType": "IN_LINE"
    },
    "dataSourceType": "CUSTOM"
}
```

在 `id` 欄位中包含文件的 ID、在 `data` 欄位中包含 Base64 編碼的文件，以及在 `mimeType` 欄位中包含 MIME 類型。

------

#### 從 S3 擷取文件
<a name="w2aac28c10c23c19c17c11b3c15b7b3"></a>

如果您是從 S3 位置擷取文件，則 `content` 欄位中的 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 物件應為下列格式：

```
{ 
    "custom": { 
        "customDocumentIdentifier": { 
            "id": "string"
        },
        "s3Location": { 
            "bucketOwnerAccountId": "string",
            "uri": "string"
        },
        "sourceType": "S3"
    },
    "dataSourceType": "CUSTOM"
}
```

在 `id` 欄位中包含文件的 ID、在 `bucketOwnerAccountId` 欄位中包含文件的 S3 儲存貯體擁有者，以及在 `uri` 欄位中包含文件的 S3 URI。

文件的中繼資料可以透過下列方式定義：

#### 定義中繼資料內嵌
<a name="w2aac28c10c23c19c17c11b3c15c11b1"></a>

如果您定義中繼資料內嵌，則 `metadata` 欄位中的 [DocumentMetadata](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentMetadata.html) 物件應採用下列格式：

```
{ 
    "inlineAttributes": [ 
        { 
            "key": "string",
            "value": { 
                "stringValue": "string",
                "booleanValue": boolean,
                "numberValue": number,
                "stringListValue": [ "string" ],
                "type": "STRING" | "BOOLEAN" | "NUMBER" | "STRING_LIST"
            }
        }
    ],
    "type": "IN_LINE_ATTRIBUTE"
}
```

針對您新增的每個屬性，在 `key` 欄位中定義索引鍵。在 `type` 欄位中指定值的資料類型，並包含對應至資料類型的欄位。例如，如果您包含字串，屬性會採用下列格式：

```
{ 
    "key": "string",
    "value": { 
        "stringValue": "string",
        "type": "STRING"
    }
}
```

#### 從 S3 擷取中繼資料
<a name="w2aac28c10c23c19c17c11b3c15c11b3"></a>

您也可以從 S3 位置中具有 `.metadata.json` 副檔名的檔案擷取中繼資料。如需中繼資料檔案格式的詳細資訊，請參閱 [連接至知識庫的 Amazon S3](s3-data-source-connector.md) 中的**文件中繼資料欄位**區段。

如果中繼資料來自 S3 檔案，`metadata` 欄位中的 [DocumentMetadata](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentMetadata.html) 物件應採用下列格式：

```
{
    "s3Location": { 
        "bucketOwnerAccountId": "string",
        "uri": "string"
    },
        "type": "S3_LOCATION"
    }
 }
```

在 `bucketOwnerAccountId` 欄位中包含中繼資料檔案的 S3 儲存貯體擁有者，以及在 `uri` 欄位中包含中繼資料檔案的 S3 URI。

**警告**  
如果您定義內容內嵌，則必須定義中繼資料內嵌。

### 將文件擷取至連線至 Amazon S3 資料來源的知識庫
<a name="kb-direct-ingestion-add-s3"></a>

如果您指定的 `dataSourceId` 屬於 S3 資料來源，您可以為 `documents` 陣列中的每個 [KnowledgeBaseDocument](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_KnowledgeBaseDocument.html) 物件新增內容和中繼資料。

**注意**  
對於 S3 資料來源，您只能從 S3 位置新增內容和中繼資料。

要新增至 S3 的 S3 文件內容應以下列格式新增至 [DocumentContent](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentContent.html) 物件：

```
{ 
    "dataSourceType": "string",
    "s3": { 
        "s3Location": { 
            "uri": "string"
        }
    }
}
```

在 `bucketOwnerAccountId` 欄位中包含文件的 S3 儲存貯體擁有者，以及在 `uri` 欄位中包含文件的 S3 URI。

新增至自訂資料來源的文件中繼資料可以下列格式定義：

```
{
    "s3Location": { 
        "bucketOwnerAccountId": "string",
        "uri": "string"
    },
        "type": "S3_LOCATION"
    }
 }
```

**警告**  
您直接擷取至連線至 S3 資料來源之知識庫的文件不會新增至 S3 儲存貯體本身。我們也建議您將這些文件新增至 S3 資料來源，以便在您同步資料來源時不會將其移除或覆寫。

### 範例請求內文
<a name="w2aac28c10c23c19c17c11b3c19"></a>

展開下列各節，查看使用 `IngestKnowledgeBaseDocuments` 時不同使用案例的請求內文：

#### 將自訂文字文件新增至自訂資料來源並將其擷取
<a name="w2aac28c10c23c19c17c11b3c19b5b1"></a>

下列範例顯示將一個文字文件新增至自訂資料來源：

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "inlineContent": { 
                  "textContent": { 
                     "data": "Hello world!"
                  },
                  "type": "TEXT"
               },
               "sourceType": "IN_LINE"
            }
         }
     }
   ]
}
```

#### 將 Base64 編碼的文件新增至自訂資料來源並將其擷取
<a name="w2aac28c10c23c19c17c11b3c19b5b3"></a>

下列範例顯示將 PDF 文件新增至自訂資料來源：

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "inlineContent": { 
                  "byteContent": { 
                     "data": "<Base64-encoded string>",
                     "mimeType": "application/pdf"
                  },
                  "type": "BYTE"
               },
               "sourceType": "IN_LINE"
            }
         }
     }
   ]
}
```

#### 從 S3 位置將文件新增至連線至自訂資料來源的知識庫並將其擷取
<a name="w2aac28c10c23c19c17c11b3c19b5b5"></a>

下列範例顯示從 S3 位置將一個文字文件新增至自訂資料來源：

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "s3": {
                "s3Location": {
                    "uri": "amzn-s3-demo-bucket"
                }
               },
               "sourceType": "S3"
            }
         }
     }
   ]
}
```

#### 將內嵌文件新增至連線至自訂資料來源的知識庫，並包含中繼資料內嵌
<a name="w2aac28c10c23c19c17c11b3c19b5b7"></a>

下列範例顯示文件中自訂資料來源的內嵌新增，以及包含兩個屬性的中繼資料：

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
   "documents": [ 
      { 
         "content": { 
            "dataSourceType": "CUSTOM",
            "custom": { 
               "customDocumentIdentifier": { 
                  "id": "MyDocument"
               },
               "inlineContent": { 
                  "textContent": { 
                     "data": "Hello world!"
                  },
                  "type": "TEXT"
               },
               "sourceType": "IN_LINE"
            }
         },
         "metadata": {
            "inlineAttributes": [ 
               { 
                  "key": "genre",
                  "value": {
                     "stringValue": "pop",
                     "type": "STRING"
                  }
               },
               { 
                  "key": "year",
                  "value": { 
                     "numberValue": 1988,
                     "type": "NUMBER"
                  }
               }
            ],
            "type": "IN_LINE_ATTRIBUTE"
         }
     }
   ]
}
```

#### 將文件新增至連線至 S3 資料來源的知識庫，並包含其中繼資料
<a name="w2aac28c10c23c19c17c11b3c19b5b9"></a>

下列範例顯示將文件與中繼資料一起新增至 S3 資料來源。您只能透過 S3 包含中繼資料：

```
PUT /knowledgebases/KB12345678/datasources/DS12345678/documents HTTP/1.1
Content-type: application/json

{
    "documents": [ 
        { 
            "content": { 
                "dataSourceType": "S3",
                "s3": { 
                "s3Location": {
                    "uri": "amzn-s3-demo-bucket"
                }
            }
        },
        "metadata": {
            "s3Location": {
                "bucketOwnerId": "111122223333",
                "uri": "amzn-s3-demo-bucket"
            },
                "type": "S3_LOCATION"
            }
        }
    ]
}
```

# 檢視資料來源中文件的相關資訊
<a name="kb-direct-ingestion-view"></a>

下列主題說明如何在資料來源中檢視文件。如果您的知識庫已連線至 Amazon S3 資料來源，您可以檢視已連線 S3 儲存貯體中的文件。

**注意**  
如果您透過連線至 S3 資料來源建立新的知識庫，您必須先同步資料來源，才能在資料來源上使用這些 API 操作。

展開與您的使用案例對應的方法：

## 使用主控台
<a name="kb-direct-ingestion-view-console"></a>

若要在資料來源中檢視已在 AWS 管理主控台 中擷取的文件，請執行下列動作：

1. 使用具有 Amazon Bedrock 主控台使用許可的 IAM 身分登入AWS 管理主控台。接著，開啟位於 [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock) 的 Amazon Bedrock 主控台。

1. 在左側導覽窗格中選擇**知識庫**。

1. 在**知識庫**區段中，選取您要檢視其文件的知識庫。

1. 在**資料來源**區段中，選取您要檢視其文件的資料來源。

1. **文件**區段會列出資料來源中的文件。這些文件也已擷取至知識庫。

## 使用 API
<a name="kb-direct-ingestion-view-api"></a>

使用 Amazon Bedrock API，您可以檢視資料來源中已擷取至知識庫的一部分或全部文件。選取與您的使用案例相關的主題。

**Topics**
+ [檢視知識庫中一部分文件的相關資訊](#kb-direct-ingestion-get)
+ [檢視知識庫中所有文件的相關資訊](#kb-direct-ingestion-list)

### 檢視知識庫中一部分文件的相關資訊
<a name="kb-direct-ingestion-get"></a>

若要檢視資料來源中特定文件的相關資訊，請使用 [Amazon Bedrock 代理人建置時間端點](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt)傳送 [GetKnowledgeBaseDocuments](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_GetKnowledgeBaseDocuments.html) 請求，並指定資料來源 ID 及其連線的知識庫。

對於您要取得資訊的每個文件，請在 `documentIdentifiers` 陣列中以下列其中一種格式新增 [DocumentIdentifier](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentIdentifier.html) 項目：
+ 如果資料來源是自訂來源，請在 `id` 欄位中指定文件的 ID：

  ```
  { 
      "custom": { 
          "id": "string"
      },
      "dataSourceType": "CUSTOM"
  }
  ```
+ 如果資料來源是 Amazon S3，請在 `uri` 欄位中指定文件的 S3 URI：

  ```
  {
      "dataSourceType": "S3",
      "s3": { 
          "uri": "string"
      }
  }
  ```

回應會傳回項目陣列，每個項目都包含您請求之文件的相關資訊。

### 檢視知識庫中所有文件的相關資訊
<a name="kb-direct-ingestion-list"></a>

若要檢視資料來源中所有文件的相關資訊，請使用 [Amazon Bedrock 代理人建置時間端點](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt)傳送 [ListKnowledgeBaseDocuments](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_ListKnowledgeBaseDocuments.html) 請求，並指定資料來源的 ID 及其連線的知識庫。也您有下列選項：
+ 指定 `maxResults` 以限制要傳回的結果數量。
+ 如果結果不符合回應，則會在回應的 `nextToken` 欄位中傳回值。您可以在後續請求的 `nextToken` 欄位中使用此值，以取得下一批結果。

# 直接從知識庫刪除文件
<a name="kb-direct-ingestion-delete"></a>

如果您不再需要知識庫中的文件，可以直接將其刪除。若要了解如何從資料來源和知識庫中刪除文件，請展開與使用案例對應的區段：

## 使用主控台
<a name="kb-direct-ingestion-delete-console"></a>

若要使用 AWS 管理主控台 直接從資料來源和知識庫刪除文件，請執行下列動作：

1. 使用具有 Amazon Bedrock 主控台使用許可的 IAM 身分登入AWS 管理主控台。接著，開啟位於 [https://console.aws.amazon.com/bedrock](https://console.aws.amazon.com/bedrock) 的 Amazon Bedrock 主控台。

1. 在左側導覽窗格中選擇**知識庫**。

1. 在**知識庫**區段中，選取要從中刪除文件的知識庫。

1. 在**資料來源**區段中，選取要從中刪除文件的資料來源。

1. 在**文件**區段中，選取要刪除的文件。然後選擇**刪除文件**。檢閱訊息然後確認。

## 使用 API
<a name="kb-direct-ingestion-delete-api"></a>

若要透過 Amazon Bedrock API 從您的資料來源刪除特定文件，請使用 [Amazon Bedrock 代理程式建置時期端點](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt)傳送 [DeleteKnowledgeBaseDocuments](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DeleteKnowledgeBaseDocuments.html) 請求，並指定資料來源的 ID 及其連線的知識庫。

對於您要刪除的每個文件，請在 `documentIdentifiers` 陣列中以下列其中一種格式新增 [DocumentIdentifier](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DocumentIdentifier.html) 項目：
+ 如果資料來源是自訂來源，請在 `id` 欄位中指定文件的 ID：

  ```
  { 
      "custom": { 
          "id": "string"
      },
      "dataSourceType": "CUSTOM"
  }
  ```
+ 如果資料來源是 Amazon S3，請在 `uri` 欄位中指定文件的 S3 URI：

  ```
  {
      "dataSourceType": "S3",
      "s3": { 
          "uri": "string"
      }
  }
  ```

**警告**  
您直接從連線至 S3 資料來源之知識庫刪除的文件不會從 S3 儲存貯體本身刪除。建議您從 S3 儲存貯體刪除這些文件，以便在您同步資料來源時，不會重新導入這些文件。