@@ -99,6 +99,11 @@ export interface KnowledgeBaseProps {
99
99
*/
100
100
readonly embeddingsModel : BedrockFoundationModel ;
101
101
102
+ /**
103
+ * The name of the knowledge base.
104
+ */
105
+ readonly name ?: string ;
106
+
102
107
/**
103
108
* The description of the knowledge base.
104
109
*
@@ -241,7 +246,7 @@ export class KnowledgeBase extends Construct {
241
246
const textField = 'AMAZON_BEDROCK_TEXT_CHUNK' ;
242
247
const metadataField = 'AMAZON_BEDROCK_METADATA' ;
243
248
244
- this . description = props . description ?? 'CDK deployed Knowledge base' ; // even though this prop is optional, if no value is provided it will fail to deploy
249
+ this . description = props . description ?? 'CDK deployed Knowledge base' ; // even though this prop is optional, if no value is provided it will fail to deploy
245
250
this . knowledgeBaseState = props . knowledgeBaseState ?? 'ENABLED' ;
246
251
247
252
@@ -251,10 +256,11 @@ export class KnowledgeBase extends Construct {
251
256
validateIndexParameters ( props . vectorIndex , indexName , vectorField ) ;
252
257
}
253
258
254
- this . name = generatePhysicalNameV2 (
259
+ this . name = props . name ?? generatePhysicalNameV2 (
255
260
this ,
256
261
'KB' ,
257
262
{ maxLength : 32 } ) ;
263
+
258
264
const roleName = generatePhysicalNameV2 (
259
265
this ,
260
266
'AmazonBedrockExecutionRoleForKnowledgeBase' ,
@@ -422,7 +428,7 @@ export class KnowledgeBase extends Construct {
422
428
tags : props . tags ,
423
429
} ) ;
424
430
425
- this . knowledgeBaseInstance = knowledgeBase ;
431
+ this . knowledgeBaseInstance = knowledgeBase ;
426
432
427
433
const kbCRPolicy = new iam . Policy ( this , 'KBCRPolicy' , {
428
434
// roles: [crProvider.role],
@@ -583,8 +589,7 @@ export class KnowledgeBase extends Construct {
583
589
* @returns The instance of VectorCollection, VectorStoreType.
584
590
* @internal This is an internal core function and should not be called directly.
585
591
*/
586
- private handleOpenSearchDefaultVectorCollection ( ) :
587
- {
592
+ private handleOpenSearchDefaultVectorCollection ( ) : {
588
593
vectorStore : VectorCollection ;
589
594
vectorStoreType : VectorStoreType ;
590
595
} {
@@ -606,7 +611,7 @@ export class KnowledgeBase extends Construct {
606
611
knowledgeBaseId : this . knowledgeBaseId ,
607
612
knowledgeBaseState : this . knowledgeBaseState ,
608
613
} ;
609
- agent . knowledgeBases = [ agentKnowledgeBaseProperty ] ;
614
+ agent . knowledgeBases = [ agentKnowledgeBaseProperty ] ;
610
615
}
611
616
}
612
617
@@ -636,15 +641,15 @@ function validateVectorIndex(
636
641
) {
637
642
if ( ! ( vectorStore instanceof VectorCollection ) && vectorIndex ) {
638
643
throw new Error ( 'If vectorStore is not of type VectorCollection, vectorIndex should not be provided ' +
639
- 'in KnowledgeBase construct.' ) ;
644
+ 'in KnowledgeBase construct.' ) ;
640
645
}
641
646
if ( ! ( vectorStore instanceof VectorCollection ) && indexName ) {
642
647
throw new Error ( 'If vectorStore is not of type VectorCollection, indexName should not be provided ' +
643
- 'in KnowledgeBase construct.' ) ;
648
+ 'in KnowledgeBase construct.' ) ;
644
649
}
645
650
if ( ! ( vectorStore instanceof VectorCollection ) && vectorField ) {
646
651
throw new Error ( 'If vectorStore is not of type VectorCollection, vectorField should not be provided ' +
647
- 'in KnowledgeBase construct.' ) ;
652
+ 'in KnowledgeBase construct.' ) ;
648
653
}
649
654
}
650
655
@@ -667,19 +672,19 @@ function validateIndexParameters(
667
672
if ( vectorIndex . indexName !== 'bedrock-knowledge-base-default-index' ) {
668
673
if ( vectorIndex . indexName !== indexName ) {
669
674
throw new Error ( 'Default value of indexName is `bedrock-knowledge-base-default-index`.' +
670
- ' If you create VectorIndex manually and assign vectorIndex to value other than' +
671
- ' `bedrock-knowledge-base-default-index` then you must provide the same value in KnowledgeBase construct.' +
672
- ' If you created VectorIndex manually and set it to `bedrock-knowledge-base-default-index`' +
673
- ' then do not assign indexName in KnowledgeBase construct.' ) ;
675
+ ' If you create VectorIndex manually and assign vectorIndex to value other than' +
676
+ ' `bedrock-knowledge-base-default-index` then you must provide the same value in KnowledgeBase construct.' +
677
+ ' If you created VectorIndex manually and set it to `bedrock-knowledge-base-default-index`' +
678
+ ' then do not assign indexName in KnowledgeBase construct.' ) ;
674
679
}
675
680
}
676
681
if ( vectorIndex . vectorField !== 'bedrock-knowledge-base-default-vector' ) {
677
682
if ( vectorIndex . vectorField !== vectorField ) {
678
683
throw new Error ( 'Default value of vectorField is `bedrock-knowledge-base-default-vector`.' +
679
- ' If you create VectorIndex manually and assign vectorField to value other than' +
680
- ' `bedrock-knowledge-base-default-field` then you must provide the same value in KnowledgeBase construct.' +
681
- ' If you created VectorIndex manually and set it to `bedrock-knowledge-base-default-vector`' +
682
- ' then do not assign vectorField in KnowledgeBase construct.' ) ;
684
+ ' If you create VectorIndex manually and assign vectorField to value other than' +
685
+ ' `bedrock-knowledge-base-default-field` then you must provide the same value in KnowledgeBase construct.' +
686
+ ' If you created VectorIndex manually and set it to `bedrock-knowledge-base-default-vector`' +
687
+ ' then do not assign vectorField in KnowledgeBase construct.' ) ;
683
688
}
684
689
}
685
690
}
0 commit comments