翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
AWS SDK CreateKnowledgeBase
で を使用する
次の例は、CreateKnowledgeBase
を使用する方法を説明しています。
- Python
-
- SDK for Python (Boto3)
-
注記
GitHub には、その他のリソースもあります。AWS コード例リポジトリ
で全く同じ例を見つけて、設定と実行の方法を確認してください。 Amazon Bedrock ナレッジベースを作成します。
def create_knowledge_base(bedrock_agent_client, name, role_arn, description=None): """ Creates a new knowledge base. Args: bedrock_agent_client: The Boto3 Bedrock Agent client. name (str): The name of the knowledge base. role_arn (str): The ARN of the IAM role that the knowledge base assumes to access resources. description (str, optional): A description of the knowledge base. Returns: dict: The details of the created knowledge base. """ try: kwargs = { "name": name, "roleArn": role_arn, "knowledgeBaseConfiguration": { "type": "VECTOR", "vectorKnowledgeBaseConfiguration": { "embeddingModelArn": "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1" } }, "storageConfiguration": { "type": "OPENSEARCH_SERVERLESS", # Note: You will need to create an OpenSearch Serverless collection first and replace this ARN # with your actual collection ARN from the OpenSearch console. If you use the console instead, # you can use the quick-create flow to have Knowledge Bases create the collection for you. "opensearchServerlessConfiguration": { "collectionArn": "arn:aws:aoss:us-east-1::123456789012:collection/abcdefgh12345678defgh", "fieldMapping": { "metadataField": "metadata", "textField": "text", "vectorField": "vector" }, "vectorIndexName": "test-uuid" }, }, "clientToken": "test-client-token-" + str(uuid.uuid4()) } if description: kwargs["description"] = description response = bedrock_agent_client.create_knowledge_base(**kwargs) logger.info("Created knowledge base with ID: %s", response["knowledgeBase"]["knowledgeBaseId"]) return response["knowledgeBase"] except ClientError as err: logger.error( "Couldn't create knowledge base. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
-
API の詳細については、 AWS SDK for Python (Boto3) API リファレンスの「CreateKnowledgeBase」を参照してください。
-
AWS SDK 開発者ガイドとコード例の完全なリストについては、「」を参照してくださいAWS SDK での Amazon Bedrock の使用。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。
CreateFlowVersion
CreatePrompt