Skip to content
v2.274.0

Experimental

@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

KnowledgeBase L2 construct Added in v2.274.0-alpha.0 ​

An Amazon Bedrock knowledge base.

Example ​

ts
declare const collection: opensearchserverless.ICollectionRef;

const knowledgeBase = new bedrock.KnowledgeBase(this, 'KnowledgeBase', {
  type: bedrock.KnowledgeBaseType.vector({
    embeddingsModel: bedrock.BedrockFoundationModel.TITAN_EMBED_TEXT_V2_1024,
    vectorStore: bedrock.VectorStore.openSearchServerless({
      collection,
      vectorIndexName: 'bedrock-knowledge-base-default-index',
      vectorField: 'bedrock-knowledge-base-default-vector',
      textField: 'AMAZON_BEDROCK_TEXT_CHUNK',
      metadataField: 'AMAZON_BEDROCK_METADATA',
    }),
  }),
});
python
# collection: opensearchserverless.ICollectionRef


knowledge_base = bedrock.KnowledgeBase(self, "KnowledgeBase",
    type=bedrock.KnowledgeBaseType.vector(
        embeddings_model=bedrock.BedrockFoundationModel.TITAN_EMBED_TEXT_V2_1024,
        vector_store=bedrock.VectorStore.open_search_serverless(
            collection=collection,
            vector_index_name="bedrock-knowledge-base-default-index",
            vector_field="bedrock-knowledge-base-default-vector",
            text_field="AMAZON_BEDROCK_TEXT_CHUNK",
            metadata_field="AMAZON_BEDROCK_METADATA"
        )
    )
)
java
ICollectionRef collection;


KnowledgeBase knowledgeBase = KnowledgeBase.Builder.create(this, "KnowledgeBase")
        .type(KnowledgeBaseType.vector(VectorKnowledgeBaseTypeProps.builder()
                .embeddingsModel(BedrockFoundationModel.TITAN_EMBED_TEXT_V2_1024)
                .vectorStore(VectorStore.openSearchServerless(OpenSearchServerlessVectorStoreProps.builder()
                        .collection(collection)
                        .vectorIndexName("bedrock-knowledge-base-default-index")
                        .vectorField("bedrock-knowledge-base-default-vector")
                        .textField("AMAZON_BEDROCK_TEXT_CHUNK")
                        .metadataField("AMAZON_BEDROCK_METADATA")
                        .build()))
                .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
ICollectionRef collection;


var knowledgeBase = new KnowledgeBase(this, "KnowledgeBase", new KnowledgeBaseProps {
    Type = KnowledgeBaseType.Vector(new VectorKnowledgeBaseTypeProps {
        EmbeddingsModel = BedrockFoundationModel.TITAN_EMBED_TEXT_V2_1024,
        VectorStore = VectorStore.OpenSearchServerless(new OpenSearchServerlessVectorStoreProps {
            Collection = collection,
            VectorIndexName = "bedrock-knowledge-base-default-index",
            VectorField = "bedrock-knowledge-base-default-vector",
            TextField = "AMAZON_BEDROCK_TEXT_CHUNK",
            MetadataField = "AMAZON_BEDROCK_METADATA"
        })
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
var collection ICollectionRef


knowledgeBase := bedrock.NewKnowledgeBase(this, jsii.String("KnowledgeBase"), &KnowledgeBaseProps{
	Type: bedrock.KnowledgeBaseType_Vector(&VectorKnowledgeBaseTypeProps{
		EmbeddingsModel: bedrock.BedrockFoundationModel_TITAN_EMBED_TEXT_V2_1024(),
		VectorStore: bedrock.VectorStore_OpenSearchServerless(&OpenSearchServerlessVectorStoreProps{
			Collection: *Collection,
			VectorIndexName: jsii.String("bedrock-knowledge-base-default-index"),
			VectorField: jsii.String("bedrock-knowledge-base-default-vector"),
			TextField: jsii.String("AMAZON_BEDROCK_TEXT_CHUNK"),
			MetadataField: jsii.String("AMAZON_BEDROCK_METADATA"),
		}),
	}),
})

Initializer ​

ts
new KnowledgeBase(scope: Construct, id: string, props: KnowledgeBaseProps)
python
KnowledgeBase(scope: Construct, id: str, props: KnowledgeBaseProps)
java
new KnowledgeBase(Construct scope, String id, KnowledgeBaseProps props)
csharp
new KnowledgeBase(Construct scope, string id, KnowledgeBaseProps props)
go
NewKnowledgeBase(Scope Construct, Id *string, Props KnowledgeBaseProps)

Construct Props ​

descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= no description#
A description of the knowledge base.

Must be 1-200 characters.

knowledgeBaseNamestringknowledge_base_namestrknowledgeBaseNameStringKnowledgeBaseNamestringKnowledgeBaseName*string= a unique name is generated#
The name of the knowledge base.

Must be 1-100 characters of letters, digits, hyphens and underscores, and must not contain consecutive hyphens or underscores.

roleanyroleanyroleanyRoleanyRoleany= a new role is created, trusted b…#
The service role that Amazon Bedrock assumes to operate the knowledge base.

The permissions the knowledge base needs to reach its data store and models are granted to this role.

default

Default: a new role is created, trusted by bedrock.amazonaws.com and scoped to knowledge bases in this account

tags{ [key: string]: string }tagstyping.Mapping[str, str]tagsMap<String, String>TagsIDictionary<string, string>Tags*map[string]*string= no tags#
Tags to apply to the knowledge base.
The type of the knowledge base and its type-specific configuration.

Properties ​

The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#
The principal to grant permissions to.
Grant permissions on this knowledge base to IAM principals.
knowledgeBaseArnstringknowledge_base_arnstrknowledgeBaseArnStringKnowledgeBaseArnstringKnowledgeBaseArn*stringrequired#
The ARN of the knowledge base.
knowledgeBaseIdstringknowledge_base_idstrknowledgeBaseIdStringKnowledgeBaseIdstringKnowledgeBaseId*stringrequired#
The unique identifier of the knowledge base.
knowledgeBaseRefKnowledgeBaseReferenceknowledge_base_refKnowledgeBaseReferenceknowledgeBaseRefKnowledgeBaseReferenceKnowledgeBaseRefKnowledgeBaseReferenceKnowledgeBaseRefKnowledgeBaseReferencerequired#
A reference to a KnowledgeBase resource.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
Resolves the underlying `CfnKnowledgeBase` from the construct tree.
The service role that Amazon Bedrock assumes to operate the knowledge base.

Always defined for knowledge bases created with this construct.

stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#
Adds a statement to the IAM policy of the knowledge base service role.

For a referenced knowledge base whose role was not provided, the statement cannot be applied; a warning is emitted with the statement to add to the role manually.

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromKnowledgeBaseArn(scope: Construct, id: string, knowledgeBaseArn: string): IKnowledgeBase@staticmethod def from_knowledge_base_arn(scope: Construct, id: str, knowledge_base_arn: str) -> IKnowledgeBasepublic static IKnowledgeBase fromKnowledgeBaseArn(Construct scope, String id, String knowledgeBaseArn)public static IKnowledgeBase FromKnowledgeBaseArn(Construct scope, string id, string knowledgeBaseArn)func FromKnowledgeBaseArn(Scope Construct, Id *string, KnowledgeBaseArn *string) IKnowledgeBasestatic#
Reference an existing knowledge base by ARN.
fromKnowledgeBaseAttributes(scope: Construct, id: string, attrs: KnowledgeBaseAttributes): IKnowledgeBase@staticmethod def from_knowledge_base_attributes(scope: Construct, id: str, attrs: KnowledgeBaseAttributes) -> IKnowledgeBasepublic static IKnowledgeBase fromKnowledgeBaseAttributes(Construct scope, String id, KnowledgeBaseAttributes attrs)public static IKnowledgeBase FromKnowledgeBaseAttributes(Construct scope, string id, KnowledgeBaseAttributes attrs)func FromKnowledgeBaseAttributes(Scope Construct, Id *string, Attrs KnowledgeBaseAttributes) IKnowledgeBasestatic#
Reference an existing knowledge base by its attributes.
fromKnowledgeBaseId(scope: Construct, id: string, knowledgeBaseId: string): IKnowledgeBase@staticmethod def from_knowledge_base_id(scope: Construct, id: str, knowledge_base_id: str) -> IKnowledgeBasepublic static IKnowledgeBase fromKnowledgeBaseId(Construct scope, String id, String knowledgeBaseId)public static IKnowledgeBase FromKnowledgeBaseId(Construct scope, string id, string knowledgeBaseId)func FromKnowledgeBaseId(Scope Construct, Id *string, KnowledgeBaseId *string) IKnowledgeBasestatic#
Reference an existing knowledge base by ID.

The knowledge base is assumed to be in the same account and region as the scope.

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.