@@ -78,15 +78,7 @@ export class EpsAssistMeStack extends Stack {
7878
7979 const endpoint = openSearchResources . collection . endpoint
8080
81- // Create VectorKnowledgeBase construct
82- const vectorKB = new VectorKnowledgeBaseResources ( this , "VectorKB" , {
83- docsBucket : storage . kbDocsBucket . bucket ,
84- bedrockExecutionRole : iamResources . bedrockExecutionRole ,
85- collectionArn : `arn:aws:aoss:${ region } :${ account } :collection/${ openSearchResources . collection . collection . attrId } ` ,
86- vectorIndexName : VECTOR_INDEX_NAME
87- } )
88-
89- // Create Functions construct
81+ // Create Functions construct without vector KB dependencies
9082 const functions = new Functions ( this , "Functions" , {
9183 stackName : props . stackName ,
9284 version : props . version ,
@@ -96,10 +88,10 @@ export class EpsAssistMeStack extends Stack {
9688 createIndexManagedPolicy : iamResources . createIndexManagedPolicy ,
9789 slackBotTokenParameter : secrets . slackBotTokenParameter ,
9890 slackSigningSecretParameter : secrets . slackSigningSecretParameter ,
99- guardrailId : vectorKB . guardrail . attrGuardrailId ,
100- guardrailVersion : vectorKB . guardrail . attrVersion ,
91+ guardrailId : "" , // Will be set after vector KB is created
92+ guardrailVersion : "" , // Will be set after vector KB is created
10193 collectionId : openSearchResources . collection . collection . attrId ,
102- knowledgeBaseId : vectorKB . knowledgeBase . attrKnowledgeBaseId ,
94+ knowledgeBaseId : "" , // Will be set after vector KB is created
10395 region,
10496 account,
10597 slackBotTokenSecret : secrets . slackBotTokenSecret ,
@@ -114,11 +106,21 @@ export class EpsAssistMeStack extends Stack {
114106 endpoint
115107 } )
116108
117- // Ensure dependencies are created before knowledge base
109+ // Create VectorKnowledgeBase construct after vector index
110+ const vectorKB = new VectorKnowledgeBaseResources ( this , "VectorKB" , {
111+ docsBucket : storage . kbDocsBucket . bucket ,
112+ bedrockExecutionRole : iamResources . bedrockExecutionRole ,
113+ collectionArn : `arn:aws:aoss:${ region } :${ account } :collection/${ openSearchResources . collection . collection . attrId } ` ,
114+ vectorIndexName : VECTOR_INDEX_NAME
115+ } )
116+
117+ // Ensure knowledge base waits for vector index
118118 vectorKB . knowledgeBase . node . addDependency ( vectorIndex . vectorIndex )
119- vectorKB . knowledgeBase . node . addDependency ( functions . functions . createIndex )
120- vectorKB . knowledgeBase . node . addDependency ( openSearchResources . collection . collection )
121- vectorKB . knowledgeBase . node . addDependency ( iamResources . bedrockExecutionRole )
119+
120+ // Update SlackBot Lambda environment variables with vector KB info
121+ functions . functions . slackBot . function . addEnvironment ( "GUARD_RAIL_ID" , vectorKB . guardrail . attrGuardrailId )
122+ functions . functions . slackBot . function . addEnvironment ( "GUARD_RAIL_VERSION" , vectorKB . guardrail . attrVersion )
123+ functions . functions . slackBot . function . addEnvironment ( "KNOWLEDGEBASE_ID" , vectorKB . knowledgeBase . attrKnowledgeBaseId )
122124
123125 // Create Apis and pass the Lambda function
124126 const apis = new Apis ( this , "Apis" , {
0 commit comments