Skip to content

Commit 5db3c64

Browse files
authored
chore(doc): add python code snippets for cdk-lib folder (#369)
chore(doc): add python code snippets for cdk-lib
1 parent d31433d commit 5db3c64

File tree

9 files changed

+421
-7
lines changed

9 files changed

+421
-7
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ The official samples repository https://github.com/aws-samples/generative-ai-cdk
108108
| [amazon-bedrock-rag](https://github.com/aws-samples/amazon-bedrock-rag) | Fully managed RAG solution using Knowledge Bases for Amazon Bedrock. |
109109
| [Amazon Bedrock Knowledge Bases with Private Data](https://blog.serverlessadvocate.com/amazon-bedrock-knowledge-bases-with-private-data-7685d04ef396) | Blog post and associated code sample demonstrating how to integrate Knowledge Bases into Amazon Bedrock to provide foundational models with contextual data from private data sources. |
110110
| [Automating tasks using Amazon Bedrock Agents and AI](https://blog.serverlessadvocate.com/automating-tasks-using-amazon-bedrock-agents-and-ai-4b6fb8856589) | 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. |
111+
| [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) | Create Agents for Amazon Bedrock using event handlers and auto generation of OpenAPI schemas. |
111112

112113
# Contributors
113114

apidocs/interfaces/amazonaurora.AmazonAuroraDefaultVectorStoreProps.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
`Readonly` **embeddingsModelVectorDimension**: `number`
1818

19-
The embeddings model for the knowledge base.
20-
Must be identical as in the KnowledgeBaseV2 construct.
19+
The embeddings model vector dimension for the knowledge base.
20+
Must be identical as in the KnowledgeBase construct.
2121
This is due to the factor that the embeddings models
2222
have different vector dimensions and this construct
2323
needs to know the vector dimensions to create the vector

src/cdk-lib/amazonaurora/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
| **Language** | **Package** |
1717
|:-------------|-----------------|
1818
|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) TypeScript|`@cdklabs/generative-ai-cdk-constructs`|
19+
|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`cdklabs.generative_ai_cdk_constructs`|
1920

2021
This construct library provides a class that defines a `AmazonAuroraVectorStore` class for an existing Amazon Aurora to be used for a vector store for a Knowledge Base. Additionally, it provides an `AmazonAuroraDefaultVectorStore` L3 resource that creates a VPC with 3 subnets (public private with NAT Gateway, private without NAT Gateway), with the Amazon Aurora Serverless V2 Cluster. The cluster has 1 writer/reader instance with PostgreSQL 15.5 version (min capacity 0.5, max capacity 4). Lambda custom resource executes required pgvector and Amazon Bedrock Knowledge Base SQL queries (see more [here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.VectorDB.html)) against Aurora cluster during deployment. The secret containing databases credentials is being deployed and securely stored in AWS Secrets Manager. You must specify the same embeddings model that you are going to use in KnowledgeBase construct.
2122

@@ -31,6 +32,8 @@ See the [API documentation](../../../apidocs/modules/amazonaurora.md).
3132

3233
## Amazon Aurora Vector Store
3334

35+
TypeScript
36+
3437
```ts
3538
import { amazonaurora } from '@cdklabs/generative-ai-cdk-constructs';
3639

@@ -47,12 +50,48 @@ new amazonaurora.AmazonAuroraVectoStore(
4750
});
4851
```
4952

53+
Python
54+
55+
```python
56+
57+
from cdklabs.generative_ai_cdk_constructs import (
58+
amazonaurora
59+
)
60+
61+
aurora = amazonaurora.AmazonAuroraVectorStore(
62+
credentials_secret_arn='arn:aws:secretsmanager:your-region:123456789876:secret:your-key-name',
63+
database_name='bedrock_vector_db',
64+
metadata_field='metadata',
65+
primary_key_field='id',
66+
resource_arn='arn:aws:rds:your-region:123456789876:cluster:aurora-cluster-manual',
67+
table_name='bedrock_integration.bedrock_kb',
68+
text_field='chunks',
69+
vector_field='embedding',
70+
)
71+
```
72+
5073
## Amazon Aurora Default Vector Store
5174

75+
TypeScript
76+
5277
```ts
5378
import { amazonaurora } from '@cdklabs/generative-ai-cdk-constructs';
5479

5580
new amazonaurora.AmazonAuroraDefaultVectorStore(stack, 'AuroraDefaultVectorStore', {
5681
embeddingsModel: BedrockFoundationModel.COHERE_EMBED_ENGLISH_V3.vectorDimensions!,
5782
});
5883
```
84+
85+
Python
86+
```python
87+
from cdklabs.generative_ai_cdk_constructs import (
88+
amazonaurora,
89+
bedrock
90+
)
91+
92+
dimension = bedrock.BedrockFoundationModel.COHERE_EMBED_ENGLISH_V3.vector_dimensions
93+
94+
aurora = amazonaurora.AmazonAuroraDefaultVectorStore(self, 'AuroraDefaultVectorStore',
95+
embeddings_model_vector_dimension=dimension
96+
)
97+
```

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { buildVpc, DefaultVpcProps } from '../../common/helpers/vpc-helper';
2525

2626
export interface AmazonAuroraDefaultVectorStoreProps {
2727
/**
28-
* The embeddings model for the knowledge base.
29-
* Must be identical as in the KnowledgeBaseV2 construct.
28+
* The embeddings model vector dimension for the knowledge base.
29+
* Must be identical as in the KnowledgeBase construct.
3030
* This is due to the factor that the embeddings models
3131
* have different vector dimensions and this construct
3232
* needs to know the vector dimensions to create the vector

0 commit comments

Comments
 (0)