AWS SDK와 CreateKnowledgeBase 함께 사용 - Amazon Bedrock

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

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 세부 정보는 SDK for Python (Boto3) API 참조의 CreateKnowledgeBase를 참조하세요. AWS

AWS SDK 개발자 안내서 및 코드 예제의 전체 목록은 섹션을 참조하세요AWS SDK에서 Amazon Bedrock 사용. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.