Skip to content

Commit 301ae48

Browse files
committed
Create VectorKnowledgeBase construct after vector index
1 parent 8d94b68 commit 301ae48

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

packages/cdk/resources/Functions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ export class Functions extends Construct {
8989
environmentVariables: {
9090
"RAG_MODEL_ID": RAG_MODEL_ID,
9191
"SLACK_SLASH_COMMAND": SLACK_SLASH_COMMAND,
92-
"KNOWLEDGEBASE_ID": props.knowledgeBaseId,
92+
"KNOWLEDGEBASE_ID": props.knowledgeBaseId || "placeholder",
9393
"BEDROCK_KB_DATA_SOURCE": BEDROCK_KB_DATA_SOURCE,
9494
"LAMBDA_MEMORY_SIZE": LAMBDA_MEMORY_SIZE,
9595
"SLACK_BOT_TOKEN_PARAMETER": props.slackBotTokenParameter.parameterName,
9696
"SLACK_SIGNING_SECRET_PARAMETER": props.slackSigningSecretParameter.parameterName,
97-
"GUARD_RAIL_ID": props.guardrailId,
98-
"GUARD_RAIL_VERSION": props.guardrailVersion
97+
"GUARD_RAIL_ID": props.guardrailId || "placeholder",
98+
"GUARD_RAIL_VERSION": props.guardrailVersion || "placeholder"
9999
}
100100
})
101101

packages/cdk/stacks/EpsAssistMeStack.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)