Skip to content

create_knowledge_base async

create_knowledge_base(
    name: Name,
    role_arn: KnowledgeBaseRoleArn,
    knowledge_base_configuration: KnowledgeBaseConfiguration,
    *,
    config_overrides: Optional[AsyncBedrockAgentClientConfig] = None,
    client_token: Optional[ClientToken] = None,
    description: Optional[Description] = None,
    storage_configuration: Optional[StorageConfiguration] = None,
    tags: Optional[TagsMap] = None,
) -> CreateKnowledgeBaseResponse

Creates a knowledge base. A knowledge base contains your data sources so that Large Language Models (LLMs) can use your data. To create a knowledge base, you must first set up your data sources and configure a supported vector store. For more information, see Set up a knowledge base.

To create a managed knowledge base, provide a managedKnowledgeBaseConfiguration during creation. For more information, see Build a managed knowledge base.

  • Provide the name and an optional description.

  • Provide the Amazon Resource Name (ARN) with permissions to create a knowledge base in the roleArn field.

  • For managed knowledge bases, set embeddingModelType to MANAGED to use the service-managed embedding model, or CUSTOM with an embeddingModelArn to use your own. To use your own KMS key for encryption, provide the ARN in serverSideEncryptionConfiguration. No vector store configuration is required for managed knowledge bases.

  • For self-managed knowledge bases, provide the embedding model to use in the embeddingModelArn field in the knowledgeBaseConfiguration object.

  • For self-managed knowledge bases, provide the configuration for your vector store in the storageConfiguration object.

Parameters:

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see Ensuring idempotency.

  • name (Name) –

    A name for the knowledge base.

  • description (Optional[Description], default: None ) –

    A description of the knowledge base.

  • role_arn (KnowledgeBaseRoleArn) –

    The Amazon Resource Name (ARN) of the IAM role with permissions to invoke API operations on the knowledge base.

  • knowledge_base_configuration (KnowledgeBaseConfiguration) –

    Contains details about the embeddings model used for the knowledge base.

  • storage_configuration (Optional[StorageConfiguration], default: None ) –

    Contains details about the configuration of the vector database used for the knowledge base.

  • tags (Optional[TagsMap], default: None ) –

    Specify the key-value pairs for the tags that you want to attach to your knowledge base in this object.

Raises:

Source code in docs_src/capo_bedrock_agent/_services/async_bedrock_agent.py
async def create_knowledge_base(
    self,
    name: "capo_bedrock_agent.types.name.Name",
    role_arn: "capo_bedrock_agent.types.knowledge_base_role_arn.KnowledgeBaseRoleArn",
    knowledge_base_configuration: "capo_bedrock_agent.types.knowledge_base_configuration.KnowledgeBaseConfiguration",
    *,
    config_overrides: Optional[AsyncBedrockAgentClientConfig] = None,
    client_token: Optional[
        "capo_bedrock_agent.types.client_token.ClientToken"
    ] = None,
    description: Optional[
        "capo_bedrock_agent.types.description.Description"
    ] = None,
    storage_configuration: Optional[
        "capo_bedrock_agent.types.storage_configuration.StorageConfiguration"
    ] = None,
    tags: Optional["capo_bedrock_agent.types.tags_map.TagsMap"] = None,
) -> "capo_bedrock_agent.types.create_knowledge_base_response.CreateKnowledgeBaseResponse":
    """<p>Creates a knowledge base. A knowledge base contains your data sources so that Large Language Models (LLMs) can use your data. To create a knowledge base, you must first set up your data sources and configure a supported vector store. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/knowlege-base-prereq.html">Set up a knowledge base</a>.</p> <note> <p>To create a managed knowledge base, provide a <code>managedKnowledgeBaseConfiguration</code> during creation. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/kb-build-managed.html">Build a managed knowledge base</a>.</p> </note> <ul> <li> <p>Provide the <code>name</code> and an optional <code>description</code>.</p> </li> <li> <p>Provide the Amazon Resource Name (ARN) with permissions to create a knowledge base in the <code>roleArn</code> field.</p> </li> <li> <p>For managed knowledge bases, set <code>embeddingModelType</code> to <code>MANAGED</code> to use the service-managed embedding model, or <code>CUSTOM</code> with an <code>embeddingModelArn</code> to use your own. To use your own KMS key for encryption, provide the ARN in <code>serverSideEncryptionConfiguration</code>. No vector store configuration is required for managed knowledge bases.</p> </li> <li> <p>For self-managed knowledge bases, provide the embedding model to use in the <code>embeddingModelArn</code> field in the <code>knowledgeBaseConfiguration</code> object.</p> </li> <li> <p>For self-managed knowledge bases, provide the configuration for your vector store in the <code>storageConfiguration</code> object.</p> <ul> <li> <p>For an Amazon OpenSearch Service database, use the <code>opensearchServerlessConfiguration</code> object. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-setup-oss.html">Create a vector store in Amazon OpenSearch Service</a>.</p> </li> <li> <p>For an Amazon Aurora database, use the <code>RdsConfiguration</code> object. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-setup-rds.html">Create a vector store in Amazon Aurora</a>.</p> </li> <li> <p>For a Pinecone database, use the <code>pineconeConfiguration</code> object. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-setup-pinecone.html">Create a vector store in Pinecone</a>.</p> </li> <li> <p>For a Redis Enterprise Cloud database, use the <code>redisEnterpriseCloudConfiguration</code> object. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-setup-redis.html">Create a vector store in Redis Enterprise Cloud</a>.</p> </li> </ul> </li> </ul>

    Args:
        client_token: <p>A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a>.</p>
        name: <p>A name for the knowledge base.</p>
        description: <p>A description of the knowledge base.</p>
        role_arn: <p>The Amazon Resource Name (ARN) of the IAM role with permissions to invoke API operations on the knowledge base.</p>
        knowledge_base_configuration: <p>Contains details about the embeddings model used for the knowledge base.</p>
        storage_configuration: <p>Contains details about the configuration of the vector database used for the knowledge base.</p>
        tags: <p>Specify the key-value pairs for the tags that you want to attach to your knowledge base in this object.</p>

    Raises:
        capo_bedrock_agent.errors.access_denied_exception.AccessDeniedException: <p>The request is denied because of missing access permissions.</p>
        capo_bedrock_agent.errors.conflict_exception.ConflictException: <p>There was a conflict performing an operation.</p>
        capo_bedrock_agent.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_bedrock_agent.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of requests exceeds the service quota. Resubmit your request later.</p>
        capo_bedrock_agent.errors.throttling_exception.ThrottlingException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_bedrock_agent.errors.validation_exception.ValidationException: <p>Input validation failed. Check your request parameters and retry the request.</p>
        capo_bedrock_agent.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_bedrock_agent.types.create_knowledge_base_request.CreateKnowledgeBaseRequest]",
    ) -> AsyncOperationResponse[
        "capo_bedrock_agent.types.create_knowledge_base_response.CreateKnowledgeBaseResponse"
    ]:
        import capo_bedrock_agent._operations.amazon_bedrock_agent_build_time_lambda.create_knowledge_base

        (
            output,
            http_response,
        ) = await capo_bedrock_agent._operations.amazon_bedrock_agent_build_time_lambda.create_knowledge_base.async_create_knowledge_base(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_bedrock_agent.types.create_knowledge_base_request.CreateKnowledgeBaseRequest",
    ) -> dict[str, Any]:
        import capo_bedrock_agent.types.create_knowledge_base_request

        return (
            capo_bedrock_agent.types.create_knowledge_base_request.redact_sensitive(
                input_
            )
        )

    def _redact_output(
        output: "capo_bedrock_agent.types.create_knowledge_base_response.CreateKnowledgeBaseResponse",
    ) -> dict[str, Any]:
        import capo_bedrock_agent.types.create_knowledge_base_response

        return capo_bedrock_agent.types.create_knowledge_base_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateKnowledgeBase",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_bedrock_agent.types.create_knowledge_base_request.CreateKnowledgeBaseRequest = {
        "name": name,
        "role_arn": role_arn,
        "knowledge_base_configuration": knowledge_base_configuration,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if description is not None:
        input_["description"] = description
    if storage_configuration is not None:
        input_["storage_configuration"] = storage_configuration
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output