Skip to content

chore(doc): add python code snippets for cdk-lib folder #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ The official samples repository https://github.com/aws-samples/generative-ai-cdk
| [amazon-bedrock-rag](https://github.com/aws-samples/amazon-bedrock-rag) | Fully managed RAG solution using Knowledge Bases for Amazon Bedrock. |
| [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. |
| [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. |
| [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. |

# Contributors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

• `Readonly` **embeddingsModelVectorDimension**: `number`

The embeddings model for the knowledge base.
Must be identical as in the KnowledgeBaseV2 construct.
The embeddings model vector dimension for the knowledge base.
Must be identical as in the KnowledgeBase construct.
This is due to the factor that the embeddings models
have different vector dimensions and this construct
needs to know the vector dimensions to create the vector
Expand Down
39 changes: 39 additions & 0 deletions src/cdk-lib/amazonaurora/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
| **Language** | **Package** |
|:-------------|-----------------|
|![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) TypeScript|`@cdklabs/generative-ai-cdk-constructs`|
|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`cdklabs.generative_ai_cdk_constructs`|

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.

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

## Amazon Aurora Vector Store

TypeScript

```ts
import { amazonaurora } from '@cdklabs/generative-ai-cdk-constructs';

Expand All @@ -47,12 +50,48 @@ new amazonaurora.AmazonAuroraVectoStore(
});
```

Python

```python

from cdklabs.generative_ai_cdk_constructs import (
amazonaurora
)

aurora = amazonaurora.AmazonAuroraVectorStore(
credentials_secret_arn='arn:aws:secretsmanager:your-region:123456789876:secret:your-key-name',
database_name='bedrock_vector_db',
metadata_field='metadata',
primary_key_field='id',
resource_arn='arn:aws:rds:your-region:123456789876:cluster:aurora-cluster-manual',
table_name='bedrock_integration.bedrock_kb',
text_field='chunks',
vector_field='embedding',
)
```

## Amazon Aurora Default Vector Store

TypeScript

```ts
import { amazonaurora } from '@cdklabs/generative-ai-cdk-constructs';

new amazonaurora.AmazonAuroraDefaultVectorStore(stack, 'AuroraDefaultVectorStore', {
embeddingsModel: BedrockFoundationModel.COHERE_EMBED_ENGLISH_V3.vectorDimensions!,
});
```

Python
```python
from cdklabs.generative_ai_cdk_constructs import (
amazonaurora,
bedrock
)

dimension = bedrock.BedrockFoundationModel.COHERE_EMBED_ENGLISH_V3.vector_dimensions

aurora = amazonaurora.AmazonAuroraDefaultVectorStore(self, 'AuroraDefaultVectorStore',
embeddings_model_vector_dimension=dimension
)
```
4 changes: 2 additions & 2 deletions src/cdk-lib/amazonaurora/aurora-default-vector-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { buildVpc, DefaultVpcProps } from '../../common/helpers/vpc-helper';

export interface AmazonAuroraDefaultVectorStoreProps {
/**
* The embeddings model for the knowledge base.
* Must be identical as in the KnowledgeBaseV2 construct.
* The embeddings model vector dimension for the knowledge base.
* Must be identical as in the KnowledgeBase construct.
* This is due to the factor that the embeddings models
* have different vector dimensions and this construct
* needs to know the vector dimensions to create the vector
Expand Down
Loading