This repository has been archived on 2026-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
seahaven-slack-bot/lib/constructs/knowledge-base.ts
Adam Moussa 510834533b Add work order and purchase order lookups to Bedrock agent instructions
The agent's system prompt and KB description didn't mention WO/PO data,
so it refused queries even though the data was already in the knowledge base.
2026-04-13 17:05:26 -04:00

51 lines
2.2 KiB
TypeScript

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { bedrock } from '@cdklabs/generative-ai-cdk-constructs';
export interface KnowledgeBaseProps {
accountId: string;
region: string;
}
export class KnowledgeBaseConstruct extends Construct {
public readonly knowledgeBase: bedrock.VectorKnowledgeBase;
public readonly dataSource: bedrock.S3DataSource;
public readonly docsBucket: s3.Bucket;
constructor(scope: Construct, id: string, props: KnowledgeBaseProps) {
super(scope, id);
// S3 bucket for SA8000 docs, SOPs, employee handbook, work orders, and purchase orders
this.docsBucket = new s3.Bucket(this, 'DocsBucket', {
bucketName: `seahaven-kb-docs-${props.accountId}`,
encryption: s3.BucketEncryption.S3_MANAGED,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
versioned: true,
removalPolicy: cdk.RemovalPolicy.RETAIN,
});
// VectorKnowledgeBase from @cdklabs/generative-ai-cdk-constructs handles:
// - AOSS collection with correct encryption/network/access policies
// - IAM execution role
// - kNN vector index creation via built-in custom resource
// - Bedrock Knowledge Base creation once the index is ready
this.knowledgeBase = new bedrock.VectorKnowledgeBase(this, 'KnowledgeBase', {
embeddingsModel: bedrock.BedrockFoundationModel.TITAN_EMBED_TEXT_V2_1024,
name: 'seahaven-kb',
description: 'SA8000 compliance docs, SOPs, employee handbook, work orders, and purchase orders',
instruction: 'Use this knowledge base to answer questions about Sea Haven Industries company policies, SOPs, SA8000 social accountability compliance requirements, approved vendor lists, the employee handbook, work order status and history, and purchase order details.',
});
// S3 data source — chunking configured via ChunkingStrategy.fixedSize()
this.dataSource = new bedrock.S3DataSource(this, 'S3DataSource', {
bucket: this.docsBucket,
knowledgeBase: this.knowledgeBase,
dataSourceName: 'seahaven-s3-docs',
chunkingStrategy: bedrock.ChunkingStrategy.fixedSize({
maxTokens: 512,
overlapPercentage: 20,
}),
});
}
}