以下是使用 API 搭配 AWS CLI 或支援的 SDK 建立受管知識庫和設定資料來源的範例,例如 Python。呼叫 CreateKnowledgeBase 之後,您可以呼叫 CreateDataSource,在 dataSourceConfiguration 中使用連線資訊建立資料來源。
若要了解您可以透過包含選用 vectorIngestionConfiguration 欄位套用至擷取的自訂項目,請參閱自訂資料來源的擷取。
AWS Command Line Interface
步驟 1:建立知識庫
使用受管內嵌模型 (預設):
aws bedrock-agent create-knowledge-base \
--name "my-managed-kb" \
--role-arn "arn:aws:iam::123456789012:role/BedrockKBRole" \
--description "My managed knowledge base" \
--knowledge-base-configuration file://kb-config.json
kb-config.json
{
"type": "MANAGED",
"managedKnowledgeBaseConfiguration": {
"embeddingModelType": "MANAGED"
}
}
使用自訂內嵌模型 (客戶提供的 Bedrock 模型):
aws bedrock-agent create-knowledge-base \
--name "my-custom-embed-kb" \
--role-arn "arn:aws:iam::123456789012:role/BedrockKBRole" \
--description "My managed knowledge base with custom embedding" \
--knowledge-base-configuration file://kb-config.json
kb-config.json
{
"type": "MANAGED",
"managedKnowledgeBaseConfiguration": {
"embeddingModelType": "CUSTOM",
"embeddingModelArn": "arn:aws:bedrock:us-west-2::foundation-model/amazon.titan-embed-text-v2:0",
"embeddingModelConfiguration": {
"bedrockEmbeddingModelConfiguration": {
"dimensions": 1024
}
}
}
}
省略 embeddingModelType 時,預設為 MANAGED。使用 時MANAGED,您不得指定 embeddingModelArn或 embeddingModelConfiguration。使用 時CUSTOM,兩個欄位都是必要欄位。
使用自訂多模式內嵌模型 (TwelveLabs Marengo Embed 3.0):
多模態內嵌模型使用CUSTOMembeddingModelType與文字內嵌模型相同的 。差別在於 bedrockEmbeddingModelConfiguration接受您傳遞模型特定設定的額外modelConfiguration欄位,而且您必須supplementalDataStorageConfiguration為多模型儲存目的地指定 。
aws bedrock-agent create-knowledge-base \
--name "my-multimodal-embed-kb" \
--role-arn "arn:aws:iam::123456789012:role/BedrockKBRole" \
--description "My managed knowledge base with multimodal embedding" \
--knowledge-base-configuration file://kb-config.json
kb-config.json
{
"type": "MANAGED",
"managedKnowledgeBaseConfiguration": {
"embeddingModelType": "CUSTOM",
"embeddingModelArn": "arn:aws:bedrock:us-east-1::foundation-model/twelvelabs.marengo-embed-3-0-v1:0",
"embeddingModelConfiguration": {
"bedrockEmbeddingModelConfiguration": {
"embeddingDataType": "FLOAT",
"modelConfiguration": {
"version": "1",
"audio": {
"segmentation": {
"method": "dynamic",
"dynamic": {
"minDurationSec": 4
}
}
},
"video": {
"segmentation": {
"method": "fixed",
"fixed": {
"durationSec": 6
}
}
}
}
}
},
"supplementalDataStorageConfiguration": {
"storageLocations": [
{
"s3Location": {
"uri": "s3://amzn-s3-demo-bucket"
},
"type": "S3"
}
]
}
}
}
modelConfiguration 欄位是 JSON 物件,其內容專屬於您選擇的內嵌模型。version 欄位為必要欄位,且必須設定為 1。對於每個 video audio和 模態,您可以設定 segmentationmethod的 dynamic,其接受minDurationSec值,或 fixed,其接受durationSec值。如需 TwelveLabs Marengo Embed 3.0 接受的設定,請參閱 TwelveLabs Marengo Embed 3.0。
您必須在使用TwelveLabs Marengo Embed 3.0模型supplementalDataStorageConfiguration時提供 。
步驟 2:建立資料來源
aws bedrock-agent create-data-source \
--name "S3-connector" \
--description "S3 data source connector for Amazon Bedrock to use content in S3" \
--knowledge-base-id "your-knowledge-base-id" \
--data-source-configuration file://bedrock-s3-managed-connector-configuration.json \
--data-deletion-policy "DELETE" \
--vector-ingestion-configuration '{"parsingConfiguration":{"parsingStrategy":"SMART_PARSING"}}'
bedrock-s3-managed-connector-configuration.json
{
"type": "MANAGED_KNOWLEDGE_BASE_CONNECTOR",
"managedKnowledgeBaseConnectorConfiguration": {
"mediaExtractionConfiguration": {
"imageExtractionConfiguration": {
"imageExtractionStatus": "ENABLED"
}
},
"connectorParameters": {
"type": "S3",
"version": "1",
"connectionConfiguration": {
"bucketName": "your-test-s3-bucket",
"bucketOwnerAccountId": "123456789012"
},
"deletionProtectionConfiguration": {
"enableDeletionProtection": false
}
}
}
}