Skip to content

Commit 936a8bd

Browse files
authored
chore(aurora): aurora bug fix and readme misc updates (#981)
* chore(misc): aurora bug fix and readme misc updates --------- Signed-off-by: Alain Krok <[email protected]>
1 parent 876bf3e commit 936a8bd

File tree

9 files changed

+145
-27
lines changed

9 files changed

+145
-27
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ The official [samples repository](https://github.com/aws-samples/generative-ai-c
168168
| [Automating tasks using Amazon Bedrock Agents and AI](https://blog.serverlessadvocate.com/automating-tasks-using-amazon-bedrock-agents-and-ai-4b6fb8856589) | Blog post + Code sample | Blog post and associated code sample demonstrating how to deploy an Amazon Bedrock Agent and a Knowledge Base through a hotel and spa use case. |
169169
| [Agents for Amazon Bedrock - Powertools for AWS Lambda (Python)](https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/bedrock_agents/#using-aws-cloud-developer-kit-cdk) | Code sample | Create Agents for Amazon Bedrock using event handlers and auto generation of OpenAPI schemas. |
170170
| [Text to SQL Bedrock Agent](https://github.com/aws-samples/amazon-bedrock-samples/tree/main/agents-for-bedrock/use-case-examples/text-2-sql-agent-cdk-enhanced) | Code sample | Harnessing the power of natural language processing, the "Text to SQL Bedrock Agent" facilitates the automatic transformation of natural language questions into executable SQL queries. |
171+
| [Dynamic Text-to-SQL for Enterprise Workloads with Amazon Bedrock Agent](https://github.com/aws-samples/sample-Dynamic-Text-to-SQL-with-Amazon-Bedrock-Agent) | Code sample | Elevate your data analysis with an end-to-end agentic Text-to-SQL solution, built on AWS for enterprise-scale adaptability and resilience. Ideal for complex scenarios like fraud detection in financial services. |
171172

172173
## Contributors
173174

apidocs/namespaces/amazonaurora/interfaces/AmazonAuroraVectorStoreProps.md

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ Properties for configuring an Amazon Aurora Vector Store.
1414

1515
## Properties
1616

17+
### clusterId?
18+
19+
> `readonly` `optional` **clusterId**: `string`
20+
21+
Cluster identifier.
22+
23+
***
24+
1725
### databaseName?
1826

1927
> `readonly` `optional` **databaseName**: `string`

apidocs/namespaces/bedrock/classes/BedrockFoundationModel.md

+28
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,28 @@ The ARN of the Bedrock invokable abstraction.
9595
9696
***
9797

98+
### AI21\_JAMBA\_1\_5\_LARGE\_V1
99+
100+
> `readonly` `static` **AI21\_JAMBA\_1\_5\_LARGE\_V1**: [`BedrockFoundationModel`](BedrockFoundationModel.md)
101+
102+
*************************************************************************
103+
AI21
104+
*************************************************************************
105+
106+
***
107+
108+
### AI21\_JAMBA\_1\_5\_MINI\_V1
109+
110+
> `readonly` `static` **AI21\_JAMBA\_1\_5\_MINI\_V1**: [`BedrockFoundationModel`](BedrockFoundationModel.md)
111+
112+
***
113+
114+
### AI21\_JAMBA\_INSTRUCT\_V1
115+
116+
> `readonly` `static` **AI21\_JAMBA\_INSTRUCT\_V1**: [`BedrockFoundationModel`](BedrockFoundationModel.md)
117+
118+
***
119+
98120
### AMAZON\_NOVA\_LITE\_V1
99121

100122
> `readonly` `static` **AMAZON\_NOVA\_LITE\_V1**: [`BedrockFoundationModel`](BedrockFoundationModel.md)
@@ -243,6 +265,12 @@ The ARN of the Bedrock invokable abstraction.
243265
244266
***
245267

268+
### META\_LLAMA\_3\_3\_70B\_INSTRUCT\_V1
269+
270+
> `readonly` `static` **META\_LLAMA\_3\_3\_70B\_INSTRUCT\_V1**: [`BedrockFoundationModel`](BedrockFoundationModel.md)
271+
272+
***
273+
246274
### TITAN\_EMBED\_TEXT\_V1
247275

248276
> `readonly` `static` **TITAN\_EMBED\_TEXT\_V1**: [`BedrockFoundationModel`](BedrockFoundationModel.md)

apidocs/namespaces/bedrock/interfaces/BedrockFoundationModelProps.md

+29
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@
88

99
## Properties
1010

11+
### legacy?
12+
13+
> `readonly` `optional` **legacy**: `boolean`
14+
15+
https://docs.aws.amazon.com/bedrock/latest/userguide/model-lifecycle.html
16+
A version is marked Legacy when there is a more recent version which provides superior performance. Amazon Bedrock sets an EOL date for Legacy versions.
17+
18+
#### Default
19+
20+
```ts
21+
- false
22+
```
23+
24+
***
25+
26+
### optimizedForAgents?
27+
28+
> `readonly` `optional` **optimizedForAgents**: `boolean`
29+
30+
Currently, some of the offered models are optimized with prompts/parsers fine-tuned for integrating with the agents architecture.
31+
32+
#### Default
33+
34+
```ts
35+
- false
36+
```
37+
38+
***
39+
1140
### supportedVectorType?
1241

1342
> `readonly` `optional` **supportedVectorType**: [`VectorType`](../enumerations/VectorType.md)[]

lambda/amazon-aurora-pgvector-custom-resources/custom_resources/amazon_aurora_pgvector.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,18 @@ def execute_sql_commands(
8585
):
8686
try:
8787
with conn.cursor() as cur:
88-
8988
cur.execute("CREATE EXTENSION IF NOT EXISTS vector;")
90-
cur.execute("CREATE SCHEMA IF NOT EXISTS %s;", (schema_name,))
89+
cur.execute(f"CREATE SCHEMA IF NOT EXISTS {schema_name};")
9190

92-
cur.execute("CREATE ROLE bedrock_user WITH PASSWORD %s LOGIN;", (password,))
93-
cur.execute("GRANT ALL ON SCHEMA %s TO bedrock_user;", (schema_name,))
91+
cur.execute(f"CREATE ROLE bedrock_user WITH PASSWORD '{password}' LOGIN;")
92+
cur.execute(f"GRANT ALL ON SCHEMA {schema_name} TO bedrock_user;")
9493

9594
cur.execute(
9695
f"CREATE TABLE {schema_name}.{table_name} ("
9796
f"{pk_field} uuid PRIMARY KEY, "
98-
f"{vector_field} vector(%s), "
97+
f"{vector_field} vector({vector_dimensions}), "
9998
f"{text_field} text, "
100-
f"{metadata_field} json);",
101-
(vector_dimensions,),
99+
f"{metadata_field} json);"
102100
)
103101

104102
cur.execute(

src/cdk-lib/amazonaurora/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const auroraDb = amazonaurora.AmazonAuroraVectorStore.fromExistingAuroraVectorSt
9595
),
9696
});
9797

98-
const kb = new bedrock.KnowledgeBase(this, "KnowledgeBase", {
98+
const kb = new bedrock.VectorKnowledgeBase(this, "KnowledgeBase", {
9999
embeddingsModel: foundation_models.BedrockFoundationModel.COHERE_EMBED_ENGLISH_V3,
100100
vectorStore: auroraDb,
101101
instruction:
@@ -158,7 +158,7 @@ aurora_db = amazonaurora.AmazonAuroraVectorStore.from_existing_aurora_vector_sto
158158
)
159159
)
160160

161-
kb = bedrock.KnowledgeBase(self, 'KnowledgeBase',
161+
kb = bedrock.VectorKnowledgeBase(self, 'KnowledgeBase',
162162
embeddings_model= foundation_models.BedrockFoundationModel.TITAN_EMBED_TEXT_V1,
163163
vector_store=aurora_db,
164164
instruction= 'Use this knowledge base to answer questions about books. ' +

src/cdk-lib/amazonaurora/aurora-vector-store.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ export interface AmazonAuroraVectorStoreProps extends BaseAuroraVectorStoreProps
104104
* User's VPC in which they want to deploy Aurora Database.
105105
*/
106106
readonly vpc?: ec2.IVpc;
107+
108+
/**
109+
* Cluster identifier.
110+
*/
111+
readonly clusterId?: string;
107112
}
108113

109114
/**
@@ -482,6 +487,7 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
482487
const databaseClusterResources = this.createDatabaseCluster(
483488
props.postgreSQLVersion ?? SupportedPostgreSQLVersions.AURORA_POSTGRESQL_V15_5,
484489
props.vpc,
490+
props.clusterId,
485491
);
486492
const auroraPgCRPolicy = this.createAuroraPgCRPolicy(databaseClusterResources.clusterIdentifier);
487493
const lambdaSecurityGroup = this.createLambdaSecurityGroup(databaseClusterResources.vpc);
@@ -504,6 +510,7 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
504510
private createDatabaseCluster(
505511
postgreSQLVersion: SupportedPostgreSQLVersions,
506512
existingVpc: ec2.IVpc | undefined,
513+
clusterIdentifier: string | undefined,
507514
): DatabaseClusterResources {
508515
const vpc = buildVpc(this, {
509516
existingVpc: existingVpc,
@@ -524,7 +531,7 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
524531
version: postgreSQLVersion,
525532
}),
526533
credentials: rds.Credentials.fromGeneratedSecret('postgres'),
527-
clusterIdentifier: `aurora-serverless-vector-cluster-${cdk.Stack.of(this).account}`,
534+
clusterIdentifier: clusterIdentifier ?? generatePhysicalNameV2(this, 'aurora-serverless', { maxLength: 63, lower: true, separator: '-' }),
528535
defaultDatabaseName: this.databaseName,
529536
vpc,
530537
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED },

src/cdk-lib/bedrock/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const auroraDb = new amazonaurora.AmazonAuroraVectorStore(stack, 'AuroraDefaultV
148148

149149
const kb = new bedrock.VectorKnowledgeBase(this, 'KnowledgeBase', {
150150
vectorStore: auroraDb,
151-
embeddingsModelVectorDimension: embeddingsModelVectorDimension,
151+
embeddingsModel: foundation_models.BedrockFoundationModel.TITAN_EMBED_TEXT_V1,
152152
instruction: 'Use this knowledge base to answer questions about books. ' + 'It contains the full text of novels.',
153153
});
154154

@@ -185,19 +185,19 @@ aurora_db = amazonaurora.AmazonAuroraVectorStore(self, 'AuroraDefaultVectorStore
185185
)
186186

187187
kb = bedrock.VectorKnowledgeBase(self, 'KnowledgeBase',
188-
vector_store= aurora_db,
189-
embeddings_model_vector_dimension=embeddings_model_vector_dimension,
190-
instruction= 'Use this knowledge base to answer questions about books. ' +
191-
'It contains the full text of novels.'
192-
)
188+
vector_store= aurora_db,
189+
embeddings_model= foundation_models.BedrockFoundationModel.TITAN_EMBED_TEXT_V1,
190+
instruction= 'Use this knowledge base to answer questions about books. ' +
191+
'It contains the full text of novels.'
192+
)
193193

194194
docBucket = s3.Bucket(self, 'DockBucket')
195195

196196
bedrock.S3DataSource(self, 'DataSource',
197-
bucket= docBucket,
198-
knowledge_base=kb,
199-
data_source_name='books',
200-
chunking_strategy= bedrock.ChunkingStrategy.FIXED_SIZE,
197+
bucket= docBucket,
198+
knowledge_base=kb,
199+
data_source_name='books',
200+
chunking_strategy= bedrock.ChunkingStrategy.FIXED_SIZE,
201201
)
202202

203203
```

src/cdk-lib/bedrock/models.ts

+54-7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ export interface BedrockFoundationModelProps {
5757
* @default - false
5858
*/
5959
readonly supportsAgents?: boolean;
60+
/**
61+
* Currently, some of the offered models are optimized with prompts/parsers fine-tuned for integrating with the agents architecture.
62+
*
63+
* @default - false
64+
*/
65+
readonly optimizedForAgents?: boolean;
66+
/**
67+
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-lifecycle.html
68+
* A version is marked Legacy when there is a more recent version which provides superior performance. Amazon Bedrock sets an EOL date for Legacy versions.
69+
*
70+
* @default - false
71+
*/
72+
readonly legacy?: boolean;
6073
/**
6174
* Bedrock Knowledge Base can use this model.
6275
*
@@ -86,6 +99,20 @@ export interface BedrockFoundationModelProps {
8699
* can instantiate a `BedrockFoundationModel` object, e.g: `new BedrockFoundationModel('my-model')`.
87100
*/
88101
export class BedrockFoundationModel implements IInvokable {
102+
/****************************************************************************
103+
* AI21
104+
***************************************************************************/
105+
public static readonly AI21_JAMBA_1_5_LARGE_V1 = new BedrockFoundationModel('ai21.jamba-1-5-large-v1:0', {
106+
supportsAgents: true,
107+
});
108+
109+
public static readonly AI21_JAMBA_1_5_MINI_V1 = new BedrockFoundationModel('ai21.jamba-1-5-mini-v1:0', {
110+
supportsAgents: true,
111+
});
112+
113+
public static readonly AI21_JAMBA_INSTRUCT_V1 = new BedrockFoundationModel('ai21.jamba-instruct-v1:0', {
114+
supportsAgents: true,
115+
});
89116
/****************************************************************************
90117
* AMAZON
91118
***************************************************************************/
@@ -100,16 +127,19 @@ export class BedrockFoundationModel implements IInvokable {
100127
public static readonly AMAZON_NOVA_MICRO_V1 = new BedrockFoundationModel('amazon.nova-micro-v1:0', {
101128
supportsAgents: true,
102129
supportsCrossRegion: true,
130+
optimizedForAgents: true,
103131
});
104132

105133
public static readonly AMAZON_NOVA_LITE_V1 = new BedrockFoundationModel('amazon.nova-lite-v1:0', {
106134
supportsAgents: true,
107135
supportsCrossRegion: true,
136+
optimizedForAgents: true,
108137
});
109138

110139
public static readonly AMAZON_NOVA_PRO_V1 = new BedrockFoundationModel('amazon.nova-pro-v1:0', {
111140
supportsAgents: true,
112141
supportsCrossRegion: true,
142+
optimizedForAgents: true,
113143
});
114144

115145
public static readonly TITAN_EMBED_TEXT_V1 = new BedrockFoundationModel('amazon.titan-embed-text-v1', {
@@ -140,49 +170,56 @@ export class BedrockFoundationModel implements IInvokable {
140170
***************************************************************************/
141171
public static readonly ANTHROPIC_CLAUDE_3_7_SONNET_V1_0 = new BedrockFoundationModel(
142172
'anthropic.claude-3-7-sonnet-20250219-v1:0',
143-
{ supportsAgents: true, supportsCrossRegion: true },
173+
174+
{ supportsAgents: true, supportsCrossRegion: true, optimizedForAgents: false },
144175
);
145176

146177
public static readonly ANTHROPIC_CLAUDE_3_5_SONNET_V2_0 = new BedrockFoundationModel(
147178
'anthropic.claude-3-5-sonnet-20241022-v2:0',
148-
{ supportsAgents: true, supportsCrossRegion: true },
179+
{ supportsAgents: true, supportsCrossRegion: true, optimizedForAgents: true },
149180
);
150181

151182
public static readonly ANTHROPIC_CLAUDE_3_5_SONNET_V1_0 = new BedrockFoundationModel(
152183
'anthropic.claude-3-5-sonnet-20240620-v1:0',
153-
{ supportsAgents: true, supportsCrossRegion: true },
184+
{ supportsAgents: true, supportsCrossRegion: true, optimizedForAgents: true },
154185
);
155186

156187
public static readonly ANTHROPIC_CLAUDE_3_5_HAIKU_V1_0 = new BedrockFoundationModel(
157188
'anthropic.claude-3-5-haiku-20241022-v1:0',
158-
{ supportsAgents: true, supportsCrossRegion: true },
189+
{ supportsAgents: true, supportsCrossRegion: true, optimizedForAgents: true },
159190
);
160191

161192
public static readonly ANTHROPIC_CLAUDE_OPUS_V1_0 = new BedrockFoundationModel(
162193
'anthropic.claude-3-opus-20240229-v1:0',
163-
{ supportsAgents: true },
194+
{ supportsAgents: true, optimizedForAgents: true },
164195
);
165196

166197
public static readonly ANTHROPIC_CLAUDE_SONNET_V1_0 = new BedrockFoundationModel(
167198
'anthropic.claude-3-sonnet-20240229-v1:0',
168-
{ supportsAgents: true, supportsCrossRegion: true },
199+
{ supportsAgents: true, supportsCrossRegion: true, legacy: true, optimizedForAgents: true },
169200
);
170201

171202
public static readonly ANTHROPIC_CLAUDE_HAIKU_V1_0 = new BedrockFoundationModel(
172203
'anthropic.claude-3-haiku-20240307-v1:0',
173-
{ supportsAgents: true, supportsCrossRegion: true },
204+
{ supportsAgents: true, supportsCrossRegion: true, optimizedForAgents: true },
174205
);
175206

176207
public static readonly ANTHROPIC_CLAUDE_V2_1 = new BedrockFoundationModel('anthropic.claude-v2:1', {
177208
supportsAgents: true,
209+
legacy: true,
210+
optimizedForAgents: true,
178211
});
179212

180213
public static readonly ANTHROPIC_CLAUDE_V2 = new BedrockFoundationModel('anthropic.claude-v2', {
181214
supportsAgents: true,
215+
legacy: true,
216+
optimizedForAgents: true,
182217
});
183218

184219
public static readonly ANTHROPIC_CLAUDE_INSTANT_V1_2 = new BedrockFoundationModel('anthropic.claude-instant-v1', {
185220
supportsAgents: true,
221+
legacy: true,
222+
optimizedForAgents: true,
186223
});
187224

188225
/****************************************************************************
@@ -204,28 +241,38 @@ export class BedrockFoundationModel implements IInvokable {
204241
* META
205242
***************************************************************************/
206243
public static readonly META_LLAMA_3_1_8B_INSTRUCT_V1 = new BedrockFoundationModel('meta.llama3-1-8b-instruct-v1:0', {
244+
supportsAgents: true,
207245
supportsCrossRegion: true,
208246
});
209247

210248
public static readonly META_LLAMA_3_1_70B_INSTRUCT_V1 = new BedrockFoundationModel(
211249
'meta.llama3-1-70b-instruct-v1:0',
212250
{
251+
supportsAgents: true,
213252
supportsCrossRegion: true,
214253
},
215254
);
216255

217256
public static readonly META_LLAMA_3_2_11B_INSTRUCT_V1 = new BedrockFoundationModel(
218257
'meta.llama3-2-11b-instruct-v1:0',
219258
{
259+
supportsAgents: true,
220260
supportsCrossRegion: true,
221261
},
222262
);
223263

224264
public static readonly META_LLAMA_3_2_3B_INSTRUCT_V1 = new BedrockFoundationModel('meta.llama3-2-3b-instruct-v1:0', {
265+
supportsAgents: true,
225266
supportsCrossRegion: true,
226267
});
227268

228269
public static readonly META_LLAMA_3_2_1B_INSTRUCT_V1 = new BedrockFoundationModel('meta.llama3-2-1b-instruct-v1:0', {
270+
supportsAgents: true,
271+
supportsCrossRegion: true,
272+
});
273+
274+
public static readonly META_LLAMA_3_3_70B_INSTRUCT_V1 = new BedrockFoundationModel('meta.llama3-3-70b-instruct-v1:0', {
275+
supportsAgents: true,
229276
supportsCrossRegion: true,
230277
});
231278

0 commit comments

Comments
 (0)