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 f7e63e50c9 Initial scaffold: Bedrock-backed Slack DM bot
- CDK stack for Sea Haven Industries internal Slack assistant
- Bedrock Agent (Claude 3.5 Sonnet) with QBO + Google Maps action groups
- VectorKnowledgeBase via @cdklabs/generative-ai-cdk-constructs (AOSS + S3)
- Slack webhook/processor Lambdas with DM-only filtering
- API Gateway HTTP API on bot.seahaven.com
- DynamoDB conversation log with 90-day TTL
- Secrets Manager references for Slack, QBO OAuth, and Google Maps
2026-04-11 23:15:15 -04:00

51 lines
2.1 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, and employee handbook
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, and employee handbook',
instruction: 'Use this knowledge base to answer questions about Sea Haven Industries company policies, SOPs, SA8000 social accountability compliance requirements, approved vendor lists, and the employee handbook.',
});
// 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,
}),
});
}
}