diff --git a/apidocs/namespaces/bedrock/README.md b/apidocs/namespaces/bedrock/README.md index 93245558..da91bf39 100644 --- a/apidocs/namespaces/bedrock/README.md +++ b/apidocs/namespaces/bedrock/README.md @@ -30,10 +30,13 @@ - [ParsingModality](enumerations/ParsingModality.md) - [ParsingStategyType](enumerations/ParsingStategyType.md) - [PromptTemplateType](enumerations/PromptTemplateType.md) +- [RedshiftQueryEngineStorageType](enumerations/RedshiftQueryEngineStorageType.md) +- [RedshiftQueryEngineType](enumerations/RedshiftQueryEngineType.md) - [SalesforceDataSourceAuthType](enumerations/SalesforceDataSourceAuthType.md) - [SalesforceObjectType](enumerations/SalesforceObjectType.md) - [SharePointDataSourceAuthType](enumerations/SharePointDataSourceAuthType.md) - [SharePointObjectType](enumerations/SharePointObjectType.md) +- [SqlDatabaseType](enumerations/SqlDatabaseType.md) - [TransformationStep](enumerations/TransformationStep.md) - [VectorType](enumerations/VectorType.md) @@ -76,6 +79,7 @@ - [S3DataSource](classes/S3DataSource.md) - [SalesforceDataSource](classes/SalesforceDataSource.md) - [SharePointDataSource](classes/SharePointDataSource.md) +- [SqlKnowledgeBase](classes/SqlKnowledgeBase.md) - [ToolChoice](classes/ToolChoice.md) - [Topic](classes/Topic.md) - [VectorKnowledgeBase](classes/VectorKnowledgeBase.md) @@ -121,6 +125,7 @@ - [InferenceConfiguration](interfaces/InferenceConfiguration.md) - [IPrompt](interfaces/IPrompt.md) - [IPromptRouter](interfaces/IPromptRouter.md) +- [ISqlKnowledgeBase](interfaces/ISqlKnowledgeBase.md) - [IVectorKnowledgeBase](interfaces/IVectorKnowledgeBase.md) - [KendraKnowledgeBaseAttributes](interfaces/KendraKnowledgeBaseAttributes.md) - [KendraKnowledgeBaseProps](interfaces/KendraKnowledgeBaseProps.md) @@ -141,6 +146,8 @@ - [SharePointCrawlingFilters](interfaces/SharePointCrawlingFilters.md) - [SharePointDataSourceAssociationProps](interfaces/SharePointDataSourceAssociationProps.md) - [SharePointDataSourceProps](interfaces/SharePointDataSourceProps.md) +- [SqlKnowledgeBaseAttributes](interfaces/SqlKnowledgeBaseAttributes.md) +- [SqlKnowledgeBaseProps](interfaces/SqlKnowledgeBaseProps.md) - [TextPromptVariantProps](interfaces/TextPromptVariantProps.md) - [ToolConfiguration](interfaces/ToolConfiguration.md) - [VectorKnowledgeBaseAttributes](interfaces/VectorKnowledgeBaseAttributes.md) diff --git a/apidocs/namespaces/bedrock/classes/SqlKnowledgeBase.md b/apidocs/namespaces/bedrock/classes/SqlKnowledgeBase.md new file mode 100644 index 00000000..2170fe2b --- /dev/null +++ b/apidocs/namespaces/bedrock/classes/SqlKnowledgeBase.md @@ -0,0 +1,546 @@ +[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md) + +*** + +[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / SqlKnowledgeBase + +# Class: SqlKnowledgeBase + +## Extends + +- `SqlKnowledgeBaseBase` + +## Constructors + +### new SqlKnowledgeBase() + +> **new SqlKnowledgeBase**(`scope`, `id`, `props`): [`SqlKnowledgeBase`](SqlKnowledgeBase.md) + +#### Parameters + +##### scope + +`Construct` + +##### id + +`string` + +##### props + +[`SqlKnowledgeBaseProps`](../interfaces/SqlKnowledgeBaseProps.md) + +#### Returns + +[`SqlKnowledgeBase`](SqlKnowledgeBase.md) + +#### Overrides + +`SqlKnowledgeBaseBase.constructor` + +## Properties + +### description? + +> `readonly` `optional` **description**: `string` + +A description of the knowledge base. + +#### Overrides + +`SqlKnowledgeBaseBase.description` + +*** + +### env + +> `readonly` **env**: `ResourceEnvironment` + +The environment this resource belongs to. +For resources that are created and managed by the CDK +(generally, those created by creating new class instances like Role, Bucket, etc.), +this is always the same as the environment of the stack they belong to; +however, for imported resources +(those obtained from static methods like fromRoleArn, fromBucketName, etc.), +that might be different than the stack they were imported into. + +#### Inherited from + +`SqlKnowledgeBaseBase.env` + +*** + +### instruction? + +> `readonly` `optional` **instruction**: `string` + +#### Inherited from + +`SqlKnowledgeBaseBase.instruction` + +*** + +### knowledgeBaseArn + +> `readonly` **knowledgeBaseArn**: `string` + +The ARN of the knowledge base. + +#### Overrides + +`SqlKnowledgeBaseBase.knowledgeBaseArn` + +*** + +### knowledgeBaseId + +> `readonly` **knowledgeBaseId**: `string` + +The ID of the knowledge base. + +#### Overrides + +`SqlKnowledgeBaseBase.knowledgeBaseId` + +*** + +### knowledgeBaseInstance? + +> `readonly` `optional` **knowledgeBaseInstance**: `CfnKnowledgeBase` + +Instance of knowledge base. + +*** + +### name + +> `readonly` **name**: `string` + +The name of the knowledge base. + +*** + +### node + +> `readonly` **node**: `Node` + +The tree node. + +#### Inherited from + +`SqlKnowledgeBaseBase.node` + +*** + +### physicalName + +> `protected` `readonly` **physicalName**: `string` + +Returns a string-encoded token that resolves to the physical name that +should be passed to the CloudFormation resource. + +This value will resolve to one of the following: +- a concrete value (e.g. `"my-awesome-bucket"`) +- `undefined`, when a name should be generated by CloudFormation +- a concrete name generated automatically during synthesis, in + cross-environment scenarios. + +#### Inherited from + +`SqlKnowledgeBaseBase.physicalName` + +*** + +### role + +> `readonly` **role**: `IRole` + +The role the Knowledge Base uses to access the vector store and data source. + +#### Overrides + +`SqlKnowledgeBaseBase.role` + +*** + +### sqlDatabaseType + +> `readonly` **sqlDatabaseType**: [`REDSHIFT`](../enumerations/SqlDatabaseType.md#redshift) + +The type of the query engine. + +*** + +### stack + +> `readonly` **stack**: `Stack` + +The stack in which this resource is defined. + +#### Inherited from + +`SqlKnowledgeBaseBase.stack` + +*** + +### type + +> `readonly` **type**: [`KnowledgeBaseType`](../enumerations/KnowledgeBaseType.md) = `KnowledgeBaseType.SQL` + +#### Inherited from + +`SqlKnowledgeBaseBase.type` + +## Methods + +### \_enableCrossEnvironment() + +> **\_enableCrossEnvironment**(): `void` + +**`Internal`** + +Called when this resource is referenced across environments +(account/region) to order to request that a physical name will be generated +for this resource during synthesis, so the resource can be referenced +through its absolute name/arn. + +#### Returns + +`void` + +#### Inherited from + +`SqlKnowledgeBaseBase._enableCrossEnvironment` + +*** + +### applyRemovalPolicy() + +> **applyRemovalPolicy**(`policy`): `void` + +Apply the given removal policy to this resource + +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`). + +#### Parameters + +##### policy + +`RemovalPolicy` + +#### Returns + +`void` + +#### Inherited from + +`SqlKnowledgeBaseBase.applyRemovalPolicy` + +*** + +### generatePhysicalName() + +> `protected` **generatePhysicalName**(): `string` + +#### Returns + +`string` + +#### Inherited from + +`SqlKnowledgeBaseBase.generatePhysicalName` + +*** + +### getResourceArnAttribute() + +> `protected` **getResourceArnAttribute**(`arnAttr`, `arnComponents`): `string` + +Returns an environment-sensitive token that should be used for the +resource's "ARN" attribute (e.g. `bucket.bucketArn`). + +Normally, this token will resolve to `arnAttr`, but if the resource is +referenced across environments, `arnComponents` will be used to synthesize +a concrete ARN with the resource's physical name. Make sure to reference +`this.physicalName` in `arnComponents`. + +#### Parameters + +##### arnAttr + +`string` + +The CFN attribute which resolves to the ARN of the resource. +Commonly it will be called "Arn" (e.g. `resource.attrArn`), but sometimes +it's the CFN resource's `ref`. + +##### arnComponents + +`ArnComponents` + +The format of the ARN of this resource. You must +reference `this.physicalName` somewhere within the ARN in order for +cross-environment references to work. + +#### Returns + +`string` + +#### Inherited from + +`SqlKnowledgeBaseBase.getResourceArnAttribute` + +*** + +### getResourceNameAttribute() + +> `protected` **getResourceNameAttribute**(`nameAttr`): `string` + +Returns an environment-sensitive token that should be used for the +resource's "name" attribute (e.g. `bucket.bucketName`). + +Normally, this token will resolve to `nameAttr`, but if the resource is +referenced across environments, it will be resolved to `this.physicalName`, +which will be a concrete name. + +#### Parameters + +##### nameAttr + +`string` + +The CFN attribute which resolves to the resource's name. +Commonly this is the resource's `ref`. + +#### Returns + +`string` + +#### Inherited from + +`SqlKnowledgeBaseBase.getResourceNameAttribute` + +*** + +### grant() + +> **grant**(`grantee`, ...`actions`): `Grant` + +Grant the given principal identity permissions to perform actions on this knowledge base. + +#### Parameters + +##### grantee + +`IGrantable` + +##### actions + +...`string`[] + +#### Returns + +`Grant` + +#### Inherited from + +`SqlKnowledgeBaseBase.grant` + +*** + +### grantQuery() + +> **grantQuery**(`grantee`): `Grant` + +Grant the given identity permissions to query the knowledge base. +This contains: +- Retrieve +- RetrieveAndGenerate + +#### Parameters + +##### grantee + +`IGrantable` + +#### Returns + +`Grant` + +#### Inherited from + +`SqlKnowledgeBaseBase.grantQuery` + +*** + +### grantRetrieve() + +> **grantRetrieve**(`grantee`): `Grant` + +Grant the given identity permissions to retrieve content from the knowledge base. + +#### Parameters + +##### grantee + +`IGrantable` + +#### Returns + +`Grant` + +#### Inherited from + +`SqlKnowledgeBaseBase.grantRetrieve` + +*** + +### grantRetrieveAndGenerate() + +> **grantRetrieveAndGenerate**(`grantee`): `Grant` + +Grant the given identity permissions to retrieve content from the knowledge base. + +#### Parameters + +##### grantee + +`IGrantable` + +#### Returns + +`Grant` + +#### Inherited from + +`SqlKnowledgeBaseBase.grantRetrieveAndGenerate` + +*** + +### toString() + +> **toString**(): `string` + +Returns a string representation of this construct. + +#### Returns + +`string` + +#### Inherited from + +`SqlKnowledgeBaseBase.toString` + +*** + +### fromKnowledgeBaseAttributes() + +> `static` **fromKnowledgeBaseAttributes**(`scope`, `id`, `attrs`): [`ISqlKnowledgeBase`](../interfaces/ISqlKnowledgeBase.md) + +#### Parameters + +##### scope + +`Construct` + +##### id + +`string` + +##### attrs + +[`SqlKnowledgeBaseAttributes`](../interfaces/SqlKnowledgeBaseAttributes.md) + +#### Returns + +[`ISqlKnowledgeBase`](../interfaces/ISqlKnowledgeBase.md) + +*** + +### isConstruct() + +> `static` **isConstruct**(`x`): `x is Construct` + +Checks if `x` is a construct. + +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 + +##### x + +`any` + +Any object + +#### Returns + +`x is Construct` + +true if `x` is an object created from a class which extends `Construct`. + +#### Inherited from + +`SqlKnowledgeBaseBase.isConstruct` + +*** + +### isOwnedResource() + +> `static` **isOwnedResource**(`construct`): `boolean` + +Returns true if the construct was created by CDK, and false otherwise + +#### Parameters + +##### construct + +`IConstruct` + +#### Returns + +`boolean` + +#### Inherited from + +`SqlKnowledgeBaseBase.isOwnedResource` + +*** + +### isResource() + +> `static` **isResource**(`construct`): `construct is Resource` + +Check whether the given construct is a Resource + +#### Parameters + +##### construct + +`IConstruct` + +#### Returns + +`construct is Resource` + +#### Inherited from + +`SqlKnowledgeBaseBase.isResource` diff --git a/apidocs/namespaces/bedrock/enumerations/RedshiftQueryEngineStorageType.md b/apidocs/namespaces/bedrock/enumerations/RedshiftQueryEngineStorageType.md new file mode 100644 index 00000000..ab261a1d --- /dev/null +++ b/apidocs/namespaces/bedrock/enumerations/RedshiftQueryEngineStorageType.md @@ -0,0 +1,21 @@ +[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md) + +*** + +[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / RedshiftQueryEngineStorageType + +# Enumeration: RedshiftQueryEngineStorageType + +The type of data storage service. + +## Enumeration Members + +### AWS\_DATA\_CATALOG + +> **AWS\_DATA\_CATALOG**: `"AWS_DATA_CATALOG"` + +*** + +### REDSHIFT + +> **REDSHIFT**: `"REDSHIFT"` diff --git a/apidocs/namespaces/bedrock/enumerations/RedshiftQueryEngineType.md b/apidocs/namespaces/bedrock/enumerations/RedshiftQueryEngineType.md new file mode 100644 index 00000000..a119ff86 --- /dev/null +++ b/apidocs/namespaces/bedrock/enumerations/RedshiftQueryEngineType.md @@ -0,0 +1,21 @@ +[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md) + +*** + +[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / RedshiftQueryEngineType + +# Enumeration: RedshiftQueryEngineType + +The type of query engine. + +## Enumeration Members + +### PROVISIONED + +> **PROVISIONED**: `"PROVISIONED"` + +*** + +### SERVERLESS + +> **SERVERLESS**: `"SERVERLESS"` diff --git a/apidocs/namespaces/bedrock/enumerations/SqlDatabaseType.md b/apidocs/namespaces/bedrock/enumerations/SqlDatabaseType.md new file mode 100644 index 00000000..794b0ce3 --- /dev/null +++ b/apidocs/namespaces/bedrock/enumerations/SqlDatabaseType.md @@ -0,0 +1,15 @@ +[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md) + +*** + +[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / SqlDatabaseType + +# Enumeration: SqlDatabaseType + +The type of SQL database to connect to the knowledge base. + +## Enumeration Members + +### REDSHIFT + +> **REDSHIFT**: `"REDSHIFT"` diff --git a/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseAttributes.md b/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseAttributes.md index 0e662abb..c64de1eb 100644 --- a/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseAttributes.md +++ b/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseAttributes.md @@ -12,6 +12,7 @@ Common properties for importing a knowledge base (of any type) created outside o - [`VectorKnowledgeBaseAttributes`](VectorKnowledgeBaseAttributes.md) - [`KendraKnowledgeBaseAttributes`](KendraKnowledgeBaseAttributes.md) +- [`SqlKnowledgeBaseAttributes`](SqlKnowledgeBaseAttributes.md) ## Properties diff --git a/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseProps.md b/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseProps.md index 20c91389..5fbb04e1 100644 --- a/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseProps.md +++ b/apidocs/namespaces/bedrock/interfaces/CommonKnowledgeBaseProps.md @@ -12,6 +12,7 @@ Common properties for creating any type of new Knowledge Base. - [`VectorKnowledgeBaseProps`](VectorKnowledgeBaseProps.md) - [`KendraKnowledgeBaseProps`](KendraKnowledgeBaseProps.md) +- [`SqlKnowledgeBaseProps`](SqlKnowledgeBaseProps.md) ## Properties diff --git a/apidocs/namespaces/bedrock/interfaces/IKnowledgeBase.md b/apidocs/namespaces/bedrock/interfaces/IKnowledgeBase.md index d5dae907..4a96207b 100644 --- a/apidocs/namespaces/bedrock/interfaces/IKnowledgeBase.md +++ b/apidocs/namespaces/bedrock/interfaces/IKnowledgeBase.md @@ -16,6 +16,7 @@ Represents a Knowledge Base, either created with CDK or imported, of any type. - [`IVectorKnowledgeBase`](IVectorKnowledgeBase.md) - [`IKendraKnowledgeBase`](IKendraKnowledgeBase.md) +- [`ISqlKnowledgeBase`](ISqlKnowledgeBase.md) ## Properties diff --git a/apidocs/namespaces/bedrock/interfaces/ISqlKnowledgeBase.md b/apidocs/namespaces/bedrock/interfaces/ISqlKnowledgeBase.md new file mode 100644 index 00000000..2f74a1a4 --- /dev/null +++ b/apidocs/namespaces/bedrock/interfaces/ISqlKnowledgeBase.md @@ -0,0 +1,255 @@ +[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md) + +*** + +[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / ISqlKnowledgeBase + +# Interface: ISqlKnowledgeBase + +Represents a Knowledge Base, either created with CDK or imported. + +## Extends + +- [`IKnowledgeBase`](IKnowledgeBase.md) + +## Properties + +### description? + +> `readonly` `optional` **description**: `string` + +The description of the knowledge base. + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`description`](IKnowledgeBase.md#description) + +*** + +### env + +> `readonly` **env**: `ResourceEnvironment` + +The environment this resource belongs to. +For resources that are created and managed by the CDK +(generally, those created by creating new class instances like Role, Bucket, etc.), +this is always the same as the environment of the stack they belong to; +however, for imported resources +(those obtained from static methods like fromRoleArn, fromBucketName, etc.), +that might be different than the stack they were imported into. + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`env`](IKnowledgeBase.md#env) + +*** + +### instruction? + +> `readonly` `optional` **instruction**: `string` + +A narrative instruction of the knowledge base. +A Bedrock Agent can use this instruction to determine if it should +query this Knowledge Base. + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`instruction`](IKnowledgeBase.md#instruction) + +*** + +### knowledgeBaseArn + +> `readonly` **knowledgeBaseArn**: `string` + +The ARN of the knowledge base. + +#### Example + +```ts +"arn:aws:bedrock:us-east-1:123456789012:knowledge-base/KB12345678" +``` + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`knowledgeBaseArn`](IKnowledgeBase.md#knowledgebasearn) + +*** + +### knowledgeBaseId + +> `readonly` **knowledgeBaseId**: `string` + +The ID of the knowledge base. + +#### Example + +```ts +"KB12345678" +``` + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`knowledgeBaseId`](IKnowledgeBase.md#knowledgebaseid) + +*** + +### node + +> `readonly` **node**: `Node` + +The tree node. + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`node`](IKnowledgeBase.md#node) + +*** + +### role + +> `readonly` **role**: `IRole` + +The role associated with the knowledge base. + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`role`](IKnowledgeBase.md#role) + +*** + +### stack + +> `readonly` **stack**: `Stack` + +The stack in which this resource is defined. + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`stack`](IKnowledgeBase.md#stack) + +*** + +### type + +> `readonly` **type**: [`KnowledgeBaseType`](../enumerations/KnowledgeBaseType.md) + +The type of knowledge base. + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`type`](IKnowledgeBase.md#type) + +## Methods + +### applyRemovalPolicy() + +> **applyRemovalPolicy**(`policy`): `void` + +Apply the given removal policy to this resource + +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`). + +#### Parameters + +##### policy + +`RemovalPolicy` + +#### Returns + +`void` + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`applyRemovalPolicy`](IKnowledgeBase.md#applyremovalpolicy) + +*** + +### grant() + +> **grant**(`grantee`, ...`actions`): `Grant` + +Grant the given principal identity permissions to perform actions on this knowledge base. + +#### Parameters + +##### grantee + +`IGrantable` + +##### actions + +...`string`[] + +#### Returns + +`Grant` + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`grant`](IKnowledgeBase.md#grant) + +*** + +### grantQuery() + +> **grantQuery**(`grantee`): `Grant` + +Grant the given identity permissions to query the knowledge base. + +#### Parameters + +##### grantee + +`IGrantable` + +#### Returns + +`Grant` + +#### Inherited from + +[`IKnowledgeBase`](IKnowledgeBase.md).[`grantQuery`](IKnowledgeBase.md#grantquery) + +*** + +### grantRetrieve() + +> **grantRetrieve**(`grantee`): `Grant` + +Grant the given identity permissions to retrieve content from the knowledge base. + +#### Parameters + +##### grantee + +`IGrantable` + +#### Returns + +`Grant` + +*** + +### grantRetrieveAndGenerate() + +> **grantRetrieveAndGenerate**(`grantee`): `Grant` + +Grant the given identity permissions to retrieve content from the knowledge base and generate. + +#### Parameters + +##### grantee + +`IGrantable` + +#### Returns + +`Grant` diff --git a/apidocs/namespaces/bedrock/interfaces/SqlKnowledgeBaseAttributes.md b/apidocs/namespaces/bedrock/interfaces/SqlKnowledgeBaseAttributes.md new file mode 100644 index 00000000..f65fec89 --- /dev/null +++ b/apidocs/namespaces/bedrock/interfaces/SqlKnowledgeBaseAttributes.md @@ -0,0 +1,104 @@ +[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md) + +*** + +[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / SqlKnowledgeBaseAttributes + +# Interface: SqlKnowledgeBaseAttributes + +Properties for importing a knowledge base outside of this stack + +## Extends + +- [`CommonKnowledgeBaseAttributes`](CommonKnowledgeBaseAttributes.md) + +## Properties + +### description? + +> `readonly` `optional` **description**: `string` + +The description of the knowledge base. + +#### Default + +```ts +- No description provided. +``` + +#### Inherited from + +[`CommonKnowledgeBaseAttributes`](CommonKnowledgeBaseAttributes.md).[`description`](CommonKnowledgeBaseAttributes.md#description) + +*** + +### executionRoleArn + +> `readonly` **executionRoleArn**: `string` + +The Service Execution Role associated with the knowledge base. + +#### Example + +```ts +"arn:aws:iam::123456789012:role/AmazonBedrockExecutionRoleForKnowledgeBaseawscdkbdgeBaseKB12345678" +``` + +#### Inherited from + +[`CommonKnowledgeBaseAttributes`](CommonKnowledgeBaseAttributes.md).[`executionRoleArn`](CommonKnowledgeBaseAttributes.md#executionrolearn) + +*** + +### instruction? + +> `readonly` `optional` **instruction**: `string` + +Instructions for agents based on the design and type of information of the +Knowledge Base. This will impact how Agents interact with the Knowledge Base. + +#### Default + +```ts +- No description provided. +``` + +#### Inherited from + +[`CommonKnowledgeBaseAttributes`](CommonKnowledgeBaseAttributes.md).[`instruction`](CommonKnowledgeBaseAttributes.md#instruction) + +*** + +### knowledgeBaseId + +> `readonly` **knowledgeBaseId**: `string` + +The ID of the knowledge base. + +#### Example + +```ts +"KB12345678" +``` + +#### Inherited from + +[`CommonKnowledgeBaseAttributes`](CommonKnowledgeBaseAttributes.md).[`knowledgeBaseId`](CommonKnowledgeBaseAttributes.md#knowledgebaseid) + +*** + +### knowledgeBaseState? + +> `readonly` `optional` **knowledgeBaseState**: `string` + +Specifies whether to use the knowledge base or not when sending an InvokeAgent request. + +#### Default + +```ts +- ENABLED +``` + +#### Inherited from + +[`CommonKnowledgeBaseAttributes`](CommonKnowledgeBaseAttributes.md).[`knowledgeBaseState`](CommonKnowledgeBaseAttributes.md#knowledgebasestate) diff --git a/apidocs/namespaces/bedrock/interfaces/SqlKnowledgeBaseProps.md b/apidocs/namespaces/bedrock/interfaces/SqlKnowledgeBaseProps.md new file mode 100644 index 00000000..8680df07 --- /dev/null +++ b/apidocs/namespaces/bedrock/interfaces/SqlKnowledgeBaseProps.md @@ -0,0 +1,156 @@ +[**@cdklabs/generative-ai-cdk-constructs**](../../../README.md) + +*** + +[@cdklabs/generative-ai-cdk-constructs](../../../README.md) / [bedrock](../README.md) / SqlKnowledgeBaseProps + +# Interface: SqlKnowledgeBaseProps + +Properties for a Sql knowledge base. + +## Extends + +- [`CommonKnowledgeBaseProps`](CommonKnowledgeBaseProps.md) + +## Properties + +### description? + +> `readonly` `optional` **description**: `string` + +The description of the knowledge base. + +#### Default + +```ts +- No description provided. +``` + +#### Inherited from + +[`CommonKnowledgeBaseProps`](CommonKnowledgeBaseProps.md).[`description`](CommonKnowledgeBaseProps.md#description) + +*** + +### existingRole? + +> `readonly` `optional` **existingRole**: `IRole` + +Existing IAM role with policy statements granting appropriate permissions +to invoke the specific embeddings models. +Any entity (e.g., an AWS service or application) that assumes +this role will be able to invoke or use the +specified embeddings model within the Bedrock service. + +#### Inherited from + +[`CommonKnowledgeBaseProps`](CommonKnowledgeBaseProps.md).[`existingRole`](CommonKnowledgeBaseProps.md#existingrole) + +*** + +### instruction? + +> `readonly` `optional` **instruction**: `string` + +A narrative description of the knowledge base. + +A Bedrock Agent can use this instruction to determine if it should +query this Knowledge Base. + +#### Default + +```ts +- No description provided. +``` + +#### Inherited from + +[`CommonKnowledgeBaseProps`](CommonKnowledgeBaseProps.md).[`instruction`](CommonKnowledgeBaseProps.md#instruction) + +*** + +### name? + +> `readonly` `optional` **name**: `string` + +The name of the knowledge base. + +#### Inherited from + +[`CommonKnowledgeBaseProps`](CommonKnowledgeBaseProps.md).[`name`](CommonKnowledgeBaseProps.md#name) + +*** + +### queryGenerationConfiguration? + +> `readonly` `optional` **queryGenerationConfiguration**: `QueryGenerationConfigurationProperty` + +The query generation configuration. + +*** + +### redshiftProvisionedConfiguration? + +> `readonly` `optional` **redshiftProvisionedConfiguration**: `RedshiftProvisionedConfigurationProperty` + +The Amazon Redshift provisioned configuration. +If redshiftQueryEngineType is not of type `PROVISIONED`, +do not include this property as it will throw error. + +*** + +### redshiftQueryEngineAwsDataCatalogStorageConfiguration? + +> `readonly` `optional` **redshiftQueryEngineAwsDataCatalogStorageConfiguration**: `RedshiftQueryEngineAwsDataCatalogStorageConfigurationProperty` + +The storage configuration for AWS Glue Data Catalog. +If redshiftQueryEngineStorageType is not of type `AWS_DATA_CATALOG`, +do not include this property as it will throw error. + +*** + +### redshiftQueryEngineRedshiftStorageConfiguration? + +> `readonly` `optional` **redshiftQueryEngineRedshiftStorageConfiguration**: `RedshiftQueryEngineRedshiftStorageConfigurationProperty` + +The storage configuration for Amazon Redshift. +If redshiftQueryEngineStorageType is no of type `REDSHIFT`, +do not include this property as it will throw error. + +*** + +### redshiftQueryEngineStorageType + +> `readonly` **redshiftQueryEngineStorageType**: [`RedshiftQueryEngineStorageType`](../enumerations/RedshiftQueryEngineStorageType.md) + +The type of data storage service, which can be of `REDSHIFT`, `AWS_DATA_CATALOG` types. + +*** + +### redshiftQueryEngineType + +> `readonly` **redshiftQueryEngineType**: [`RedshiftQueryEngineType`](../enumerations/RedshiftQueryEngineType.md) + +The type of query engine, which can be of `SERVERLESS` or `PROVISIONED` types. + +*** + +### redshiftServerlessConfiguration? + +> `readonly` `optional` **redshiftServerlessConfiguration**: `RedshiftServerlessConfigurationProperty` + +The Amazon Redshift serverless configuration. +If redshiftQueryEngineType is not of type `SERVERLESS`, +do not include this property as it will throw error. + +*** + +### sqlDatabaseType? + +> `readonly` `optional` **sqlDatabaseType**: [`REDSHIFT`](../enumerations/SqlDatabaseType.md#redshift) + +#### Default + +```ts +- Amazon Redshift is the only and default query engine for Sql KB for now. +``` diff --git a/src/cdk-lib/bedrock/index.ts b/src/cdk-lib/bedrock/index.ts index 06922f74..21d7cfac 100644 --- a/src/cdk-lib/bedrock/index.ts +++ b/src/cdk-lib/bedrock/index.ts @@ -55,6 +55,7 @@ export * from './inference-profiles/application-inference-profile'; export * from './knowledge-bases/knowledge-base'; export * from './knowledge-bases/vector-knowledge-base'; export * from './knowledge-bases/kendra-knowledge-base'; +export * from './knowledge-bases/structured-data-knowledge-base'; //=================================== // Prompts diff --git a/src/cdk-lib/bedrock/knowledge-bases/structured-data-knowledge-base.ts b/src/cdk-lib/bedrock/knowledge-bases/structured-data-knowledge-base.ts new file mode 100644 index 00000000..3a0b4f8e --- /dev/null +++ b/src/cdk-lib/bedrock/knowledge-bases/structured-data-knowledge-base.ts @@ -0,0 +1,330 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance + * with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +import { ArnFormat, Stack } from 'aws-cdk-lib'; +import * as bedrock from 'aws-cdk-lib/aws-bedrock'; +import * as iam from 'aws-cdk-lib/aws-iam'; +import { Construct } from 'constructs'; +import { CommonKnowledgeBaseAttributes, CommonKnowledgeBaseProps, IKnowledgeBase, KnowledgeBaseBase, KnowledgeBaseType } from './knowledge-base'; +import { generatePhysicalNameV2 } from '../../../common/helpers/utils'; + +/** + * The type of SQL database to connect to the knowledge base. + */ +export enum SqlDatabaseType { + REDSHIFT = 'REDSHIFT' +} + +/** + * The type of query engine. + */ +export enum RedshiftQueryEngineType { + SERVERLESS = 'SERVERLESS', + PROVISIONED = 'PROVISIONED' +} + +/** + * The type of data storage service. + */ +export enum RedshiftQueryEngineStorageType { + REDSHIFT = 'REDSHIFT', + AWS_DATA_CATALOG = 'AWS_DATA_CATALOG' +} + +export enum RedshiftAuthenticationType { + IAM = 'IAM', + USERNAME_PASSWORD = 'USERNAME_PASSWORD', + USERNAME = 'USERNAME' +} + +/** + * Represents a Knowledge Base, either created with CDK or imported. + */ +export interface ISqlKnowledgeBase extends IKnowledgeBase { + + /** + * Grant the given identity permissions to retrieve content from the knowledge base. + */ + grantRetrieve(grantee: iam.IGrantable): iam.Grant; + + /** + * Grant the given identity permissions to retrieve content from the knowledge base and generate. + */ + grantRetrieveAndGenerate(grantee: iam.IGrantable): iam.Grant; +} + +/****************************************************************************** + * ABSTRACT CLASS + *****************************************************************************/ +/** + * Abstract base class for Sql Knowledge Base. + * Contains methods valid for KBs either created with CDK or imported. + */ +abstract class SqlKnowledgeBaseBase extends KnowledgeBaseBase implements ISqlKnowledgeBase { + public abstract readonly knowledgeBaseArn: string; + public abstract readonly knowledgeBaseId: string; + public abstract readonly role: iam.IRole; + public abstract readonly description?: string; + public readonly instruction?: string; + public readonly type: KnowledgeBaseType = KnowledgeBaseType.SQL; + + constructor(scope: Construct, id: string) { + super(scope, id); + } +} + +/****************************************************************************** + * PROPS FOR NEW CONSTRUCT + *****************************************************************************/ +/** + * Properties for a Sql knowledge base. + */ +export interface SqlKnowledgeBaseProps extends CommonKnowledgeBaseProps { + + /** + * @default - Amazon Redshift is the only and default query engine for Sql KB for now. + */ + readonly sqlDatabaseType?: SqlDatabaseType; + + /** + * The type of query engine, which can be of `SERVERLESS` or `PROVISIONED` types. + */ + readonly redshiftQueryEngineType: RedshiftQueryEngineType; + + /** + * The Amazon Redshift provisioned configuration. + * If redshiftQueryEngineType is not of type `PROVISIONED`, + * do not include this property as it will throw error. + */ + readonly redshiftProvisionedConfiguration?: bedrock.CfnKnowledgeBase.RedshiftProvisionedConfigurationProperty; + + /** + * The Amazon Redshift serverless configuration. + * If redshiftQueryEngineType is not of type `SERVERLESS`, + * do not include this property as it will throw error. + */ + readonly redshiftServerlessConfiguration?: bedrock.CfnKnowledgeBase.RedshiftServerlessConfigurationProperty; + + /** + * The storage configuration for AWS Glue Data Catalog. + * If redshiftQueryEngineStorageType is not of type `AWS_DATA_CATALOG`, + * do not include this property as it will throw error. + */ + readonly redshiftQueryEngineAwsDataCatalogStorageConfiguration?: bedrock.CfnKnowledgeBase + .RedshiftQueryEngineAwsDataCatalogStorageConfigurationProperty; + + /** + * The storage configuration for Amazon Redshift. + * If redshiftQueryEngineStorageType is no of type `REDSHIFT`, + * do not include this property as it will throw error. + */ + readonly redshiftQueryEngineRedshiftStorageConfiguration?: bedrock.CfnKnowledgeBase.RedshiftQueryEngineRedshiftStorageConfigurationProperty; + + /** + * The type of data storage service, which can be of `REDSHIFT`, `AWS_DATA_CATALOG` types. + */ + readonly redshiftQueryEngineStorageType: RedshiftQueryEngineStorageType; + + /** + * The query generation configuration. + */ + readonly queryGenerationConfiguration?: bedrock.CfnKnowledgeBase.QueryGenerationConfigurationProperty | undefined; + +} + +/****************************************************************************** + * ATTRS FOR IMPORTED CONSTRUCT + *****************************************************************************/ +/** + * Properties for importing a knowledge base outside of this stack + */ +export interface SqlKnowledgeBaseAttributes extends CommonKnowledgeBaseAttributes { + +} + +export class SqlKnowledgeBase extends SqlKnowledgeBaseBase { + // ------------------------------------------------------ + // Import Methods + // ------------------------------------------------------ + public static fromKnowledgeBaseAttributes( + scope: Construct, + id: string, + attrs: SqlKnowledgeBaseAttributes, + ): ISqlKnowledgeBase { + const stack = Stack.of(scope); + + class Import extends SqlKnowledgeBaseBase { + public readonly role = iam.Role.fromRoleArn(this, `kb-${attrs.knowledgeBaseId}-role`, attrs.executionRoleArn); + public readonly description = attrs.description; + public readonly instruction = attrs.instruction; + public readonly knowledgeBaseId = attrs.knowledgeBaseId; + public readonly knowledgeBaseArn = stack.formatArn({ + service: 'bedrock', + resource: 'knowledge-base', + resourceName: attrs.knowledgeBaseId, + arnFormat: ArnFormat.SLASH_RESOURCE_NAME, + }); + } + return new Import(scope, id); + } + // ------------------------------------------------------ + // Attributes + // ------------------------------------------------------ + /** + * The name of the knowledge base. + */ + public readonly name: string; + + /** + * Instance of knowledge base. + */ + public readonly knowledgeBaseInstance?: bedrock.CfnKnowledgeBase; + + /** + * The ARN of the knowledge base. + */ + public readonly knowledgeBaseArn: string; + + /** + * The ID of the knowledge base. + */ + public readonly knowledgeBaseId: string; + + /** + * The role the Knowledge Base uses to access the vector store and data source. + */ + public readonly role: iam.IRole; + + /** + * A description of the knowledge base. + */ + readonly description?: string; + + /** + * The type of the query engine. + */ + readonly sqlDatabaseType: SqlDatabaseType; + + constructor(scope: Construct, id: string, props: SqlKnowledgeBaseProps) { + super(scope, id); + + // ------------------------------------------------------ + // Set properties or defaults + // ------------------------------------------------------ + this.sqlDatabaseType = props.sqlDatabaseType ?? SqlDatabaseType.REDSHIFT; + this.name = props.name ?? generatePhysicalNameV2(this, 'KB', { maxLength: 32 }); + this.description = props.description ?? 'CDK deployed Knowledge base'; + + validateConfigs(props); + + if (props.existingRole) { + this.role = props.existingRole; + } else { + const roleName = generatePhysicalNameV2(this, 'AmazonBedrockExecutionRoleForKnowledgeBase', { maxLength: 64 }); + this.role = new iam.Role(this, 'Role', { + roleName: roleName, + assumedBy: new iam.ServicePrincipal('bedrock.amazonaws.com', { + conditions: { + StringEquals: { 'aws:SourceAccount': Stack.of(this).account }, + ArnLike: { + 'aws:SourceArn': Stack.of(this).formatArn({ + service: 'bedrock', + resource: 'knowledge-base', + resourceName: '*', + arnFormat: ArnFormat.SLASH_RESOURCE_NAME, + }), + }, + }, + }), + }); + + this.role.addToPrincipalPolicy( + new iam.PolicyStatement({ + actions: [ + 'redshift-data:*', + 'sqlworkbench:*', + 'secretsmanager:GetSecretValue', + 'redshift-serverless:*', + 'bedrock:*', + ], + resources: ['*'], + }), + ); + } + + // ------------------------------------------------------ + // L1 Instantiation + // ------------------------------------------------------ + const knowledgeBase = new bedrock.CfnKnowledgeBase(this, 'MyCfnKnowledgeBase', { + knowledgeBaseConfiguration: { + type: KnowledgeBaseType.SQL, + sqlKnowledgeBaseConfiguration: { + type: this.sqlDatabaseType, + redshiftConfiguration: { + queryEngineConfiguration: { + provisionedConfiguration: props.redshiftProvisionedConfiguration, + serverlessConfiguration: props.redshiftServerlessConfiguration, + type: props.redshiftQueryEngineType, + }, + queryGenerationConfiguration: props.queryGenerationConfiguration, + storageConfigurations: [ + { + awsDataCatalogConfiguration: props.redshiftQueryEngineAwsDataCatalogStorageConfiguration, + redshiftConfiguration: props.redshiftQueryEngineRedshiftStorageConfiguration, + type: props.redshiftQueryEngineStorageType, + }, + ], + }, + }, + }, + name: this.name, + roleArn: this.role.roleArn, + description: this.description, + }); + + this.knowledgeBaseInstance = knowledgeBase; + this.knowledgeBaseArn = knowledgeBase.attrKnowledgeBaseArn; + this.knowledgeBaseId = knowledgeBase.attrKnowledgeBaseId; + } +} + +/** + * Validate that the Sql Knowledge configuration set correctly. + * It prevents the wrong use of configurations of query engine and storage types together. + */ +function validateConfigs(props: SqlKnowledgeBaseProps) { + if (props.sqlDatabaseType === SqlDatabaseType.REDSHIFT) { + if (!props.redshiftProvisionedConfiguration && !props.redshiftServerlessConfiguration) { + throw new Error('RedshiftProvisionedConfiguration or RedshiftServerlessConfiguration must be provided.'); + } + if (props.redshiftQueryEngineType === RedshiftQueryEngineType.SERVERLESS && props.redshiftProvisionedConfiguration) { + throw new Error('RedshiftProvisionedConfiguration is not supported for RedshiftQueryEngineType.SERVERLESS.'); + } + if (props.redshiftQueryEngineType === RedshiftQueryEngineType.PROVISIONED && props.redshiftServerlessConfiguration) { + throw new Error('RedshiftServerlessConfiguration is not supported for RedshiftQueryEngineType.PROVISIONED.'); + } + if (!props.redshiftQueryEngineAwsDataCatalogStorageConfiguration && !props.redshiftQueryEngineRedshiftStorageConfiguration) { + throw new Error('RedshiftQueryEngineAwsDataCatalogStorageConfiguration or RedshiftQueryEngineRedshiftStorageConfiguration must be provided.'); + } + if (props.redshiftQueryEngineStorageType === RedshiftQueryEngineStorageType.AWS_DATA_CATALOG + && props.redshiftQueryEngineRedshiftStorageConfiguration) { + throw new Error('RedshiftQueryEngineRedshiftStorageConfiguration is not supported for RedshiftQueryEngineStorageType.AWS_DATA_CATALOG.'); + } + if (props.redshiftQueryEngineStorageType === RedshiftQueryEngineStorageType.REDSHIFT + && props.redshiftQueryEngineAwsDataCatalogStorageConfiguration) { + throw new Error('RedshiftQueryEngineAwsDataCatalogStorageConfiguration is not supported for RedshiftQueryEngineStorageType.REDSHIFT.'); + } + } else { + throw new Error(`Only ${SqlDatabaseType.REDSHIFT} is supported.`); + } +} \ No newline at end of file