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/scripts/create-aoss-index.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

87 lines
2.6 KiB
TypeScript

/**
* Creates the kNN vector index in the OpenSearch Serverless collection.
*
* Run this ONCE after `cdk deploy` creates the AOSS collection but BEFORE
* triggering a Bedrock Knowledge Base sync/ingestion job.
*
* Usage:
* npx ts-node scripts/create-aoss-index.ts <collection-endpoint>
*
* The collection endpoint is printed as a stack output after deploy:
* npx cdk deploy --outputs-file outputs.json
* cat outputs.json
*
* Requirements:
* npm install --save-dev @opensearch-project/opensearch aws4 ts-node typescript
* AWS credentials must have aoss:APIAccessAll on the collection.
*/
import { Client } from '@opensearch-project/opensearch';
import { AwsSigv4Signer } from '@opensearch-project/opensearch/aws';
import { defaultProvider } from '@aws-sdk/credential-provider-node';
const INDEX_NAME = 'seahaven-kb-index';
// Field names must match exactly what's configured in knowledge-base.ts
const INDEX_BODY = {
settings: {
'index.knn': true,
},
mappings: {
properties: {
// Titan Embed Text v2 with 1024 dimensions
'bedrock-knowledge-base-default-vector': {
type: 'knn_vector',
dimension: 1024,
method: {
name: 'hnsw',
space_type: 'l2',
engine: 'faiss',
parameters: { ef_construction: 512, m: 16 },
},
},
AMAZON_BEDROCK_TEXT_CHUNK: { type: 'text' },
AMAZON_BEDROCK_METADATA: { type: 'text', index: false },
},
},
};
async function main(): Promise<void> {
const endpoint = process.argv[2];
if (!endpoint) {
console.error('Usage: npx ts-node scripts/create-aoss-index.ts <collection-endpoint>');
console.error('Example: npx ts-node scripts/create-aoss-index.ts https://abc123.us-east-1.aoss.amazonaws.com');
process.exit(1);
}
const client = new Client({
...AwsSigv4Signer({
region: 'us-east-1',
service: 'aoss',
getCredentials: defaultProvider(),
}),
node: endpoint,
});
console.log(`Creating index "${INDEX_NAME}" on ${endpoint} …`);
const exists = await client.indices.exists({ index: INDEX_NAME });
if (exists.statusCode === 200) {
console.log(`Index "${INDEX_NAME}" already exists — nothing to do.`);
return;
}
const res = await client.indices.create({
index: INDEX_NAME,
body: INDEX_BODY,
});
console.log('Index created:', JSON.stringify(res.body, null, 2));
console.log('\nNext step: trigger a sync from the Bedrock console or run:');
console.log(' aws bedrock-agent start-ingestion-job --knowledge-base-id <KB_ID> --data-source-id <DS_ID>');
}
main().catch((err) => {
console.error('Failed to create index:', err);
process.exit(1);
});