bedrockagentscdk

package module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

[!CAUTION] This construct is not being maintained and is retired. Please refer to the AWS-managed generative-ai-cdk-constructs repository.

[!NOTE] This is an experimental construct and is not affiliated with AWS Bedrock team. Things can break so do not use them in production. Currently, there is no support for updates of the construct but it is planned to be added soon. All classes are under active development and subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.

Bedrock Agent and Bedrock Knowledge Base Constructs

See API.md for more information about the construct.

Also, see TypeScript deployment examples below. All of the examples assume you have appropriate IAM permissions for provisioning resources in AWS.

Example - deploy agent only

This example will create an agent without Action Group and with the default IAM role. If agentResourceRoleArn is not specified a default IAM role with no policies attached to it will be provisioned for your agent.

import * as cdk from 'aws-cdk-lib';
import { BedrockAgent } from 'bedrock-agents-cdk';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'BedrockAgentStack');

const agent = new BedrockAgent(stack, "BedrockAgent", {
  agentName: "BedrockAgent",
  instruction: "This is a test instruction. You were built by AWS CDK construct to answer all questions.",
})

// You can retrieve `agentId` and `agentArn` of the created agent
// back from the construct.

// const agentId = agent.agentId
// const agentArn = agent.agentArn

Example - deploy knowledge base only

This example will create a knowledge base backed by Amazon OpenSearch Serverless collection that could be used without an agent. This example assumes you have already created Amazon OpenSearch Serverless collection (collectionArn).

Note: The IAM role creation in this example is for illustration only. Always provision IAM roles with the least required privileges.

import * as cdk from 'aws-cdk-lib';
import { BedrockKnowledgeBase } from 'bedrock-agents-cdk';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'BedrockKnowledgeBaseStack');

const kbName = 'MyTestKnowledgeBase';
const dataSourceName = 'MyDataSource';
const collectionArn = 'arn:aws:aoss:yourCollectionRegion:yourAWSAccountId:collection/yourCollectionId';
const vectorIndexName = 'my-test-index';
const vectorFieldName = 'my-test-vector';
const textField = 'text-field';
const metadataField = 'metadata-field';
const storageConfigurationType = 'OPENSEARCH_SERVERLESS';
const dataSourceType = 'S3';
const dataSourceBucketArn = 'yourDataSourceBucketArn';

// Bedrock Knowledge Base IAM role
const kbRoleArn = new iam.Role(stack, 'BedrockKnowledgeBaseRole', {
  roleName: 'AmazonBedrockExecutionRoleForKnowledgeBase_kb_test',
  assumedBy: new iam.ServicePrincipal('bedrock.amazonaws.com'),
  managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')],
}).roleArn;

// Create Bedrock Knowledge Base backed by OpenSearch Serverless
const knowledgeBase = new BedrockKnowledgeBase(stack, 'BedrockOpenSearchKnowledgeBase', {
  name: kbName,
  roleArn: kbRoleArn,
  storageConfiguration: {
    opensearchServerlessConfiguration: {
      collectionArn: collectionArn,
      fieldMapping: {
        metadataField: metadataField,
        textField: textField,
        vectorField: vectorFieldName,
      },
      vectorIndexName: vectorIndexName,
    },
    type: storageConfigurationType,
  },
  dataSource: {
    name: dataSourceName,
    dataSourceConfiguration: {
      s3Configuration: {
        bucketArn: dataSourceBucketArn,
      },
      type: dataSourceType,
    },
  },
});

// You can retrieve `knowledgeBaseId`, `knowledgeBaseArn`
// and `dataSourceId` of the created knowledge base
// and data source back from the construct.

// const knowledgeBaseId = knowledgeBase.knowledgeBaseId
// const knowledgeBaseArn = knowledgeBase.knowledgeBaseArn
// const dataSourceId = knowledgeBase.dataSourceId

Example - deploy agent with a single action group

This example will create an agent with an Action Group and with your IAM role (agentResourceRoleArn). It assumes that you already have an S3 bucket and a stored JSON or yml Open API schema file that will be included in your action group. Additionally, pathToLambdaFile should contain the path to your function code file inside your cdk project that you want to be attached to your agent's action group. Resource-based policy statement will be attached to your Lambda function allowing Bedrock Agent to invoke it.

Note: The IAM role creation in this example is for illustration only. Always provision IAM roles with the least required privileges.

import * as path from 'path';
import * as cdk from 'aws-cdk-lib';
import { BedrockAgent } from 'bedrock-agents-cdk';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'BedrockAgentStack');

const pathToLambdaFile = 'pathToYourLambdaFunctionFile';
const s3BucketName = 'nameOfYourS3Bucket';
const s3ObjectKey = 'nameOfYourOpenAPISchemaFileInS3Bucket';

const agentResourceRoleArn = new cdk.aws_iam.Role(stack, 'BedrockAgentRole', {
  roleName: 'AmazonBedrockExecutionRoleForAgents_agent_test',
  assumedBy: new cdk.aws_iam.ServicePrincipal('bedrock.amazonaws.com'),
  managedPolicies: [cdk.aws_iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')],
}).roleArn;

const lambdaFunctionRole = new cdk.aws_iam.Role(stack, 'BedrockAgentLambdaFunctionRole', {
  roleName: 'BedrockAgentLambdaFunctionRole',
  assumedBy: new cdk.aws_iam.ServicePrincipal('lambda.amazonaws.com'),
  managedPolicies: [cdk.aws_iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')],
});

const actionGroupExecutor = new cdk.aws_lambda.Function(stack, 'BedrockAgentActionGroupExecutor', {
  runtime: cdk.aws_lambda.Runtime.PYTHON_3_10,
  handler: 'youLambdaFileName.nameOfYourHandler',
  code: cdk.aws_lambda.Code.fromAsset(path.join(__dirname, pathToLambdaFile)),
  timeout: cdk.Duration.seconds(600),
  role: lambdaFunctionRole,
});

new BedrockAgent(stack, "BedrockAgentStack", {
  agentName: "BedrockAgent",
  instruction: "This is a test instruction. You were built by AWS CDK construct to answer all questions.",
  agentResourceRoleArn: agentResourceRoleArn,
  actionGroups: [{
    actionGroupName: "BedrockAgentActionGroup",
    actionGroupExecutor: actionGroupExecutor.functionArn,
    s3BucketName: s3BucketName,
    s3ObjectKey: s3ObjectKey,
  }]
})

Example - create an agent with 2 action groups, and 2 knowledge bases that you associate with the agent

Below is an example of how you can create 2 Amazon Bedrock Knowledge Bases (1 backed by OpenSearch Serverless and 1 backed by Pinecone), Amazon Bedrock Agent with 2 action groups, and associate 2 knowledge bases to the agent.

This example assumes you have AWS Lambda function(s) ARN (actionGroupLambdaArn), Amazon S3 bucket name (actionGroupS3BucketName) with Open API json or yaml files (actionGroupS3ObjectKey1 and actionGroupS3ObjectKey1) that you want your agent to use, as well as Amazon S3 bucket ARN (dataSourceBucketArn) where you have files that you want the Knowledge Base to perform ebeddings on. It also assumes that you already have OpenSearch Serverless ARN collection (openSearchCollectionArn), Pinecone index created and copied it's host name (pineconeConnectionString) and created and stored an API key in AWS Secrets Manager (pineconeCredentialsSecretArn).

Using 2 Knowledge Bases and/or 2 agent action groups is not required, this is just an example. Feel free to experiment with as many Knowledge Bases or Action Groups as you'd like.

Note: The IAM role creation in this example is for illustration only. Always provion IAM roles with the least required priviliges.

import * as cdk from 'aws-cdk-lib';
import { BedrockAgent, BedrockKnowledgeBase } from 'bedrock-agents-cdk';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'BedrockKnowledgeBaseStack');

const agentName = 'MyTestAgent';
const openSearchKbName = 'MyTestOpenSearchKnowledgeBase';
const pineconeKbName = 'MyTestPineconeKnowledgeBase';
const actionGroupName1 = 'MyTestActionGroup1';
const actionGroupName2 = 'MyTestActionGroup2';
const foundationModel = 'anthropic.claude-instant-v1';
const agentInstruction = 'This is a template instruction for my agent. You were created by AWS CDK.';
const kbInstruction = 'This is a template instruction for my knowledge base. You were created by AWS CDK.';
const openSearchCollectionArn = 'arn:aws:aoss:yourCollectionRegion:yourAWSAccountId:collection/yourCollectionId';
const pineconeCredentialsSecretArn = 'arn:aws:secretsmanager:yourSecretRegion:yourAWSAccountId:secret:yourSecretName';
const pineconeConnectionString = 'https://name-index-aa12345.svc.pineconeRegion.pinecone.io';
const vectorIndexName = 'my-test-index';
const vectorFieldName = 'my-test-vector';
const textField = 'text-field';
const metadataField = 'metadata-field';
const openSearchStorageConfigurationType = 'OPENSEARCH_SERVERLESS';
const pineconeStorageConfigurationType = 'PINECONE';
const dataSourceBucketArn = 'yourDataSourceBucketArn';
const inclusionPrefix = 'yourFolder/';
const actionGroupLambdaArn = 'yourActionGroupLambdaArn';
const actionGroupS3BucketName = 'yourActionGroupApiSchemaBucketName';
const actionGroupS3ObjectKey1 = 'yourActionGroupApiSchemaKey1';
const actionGroupS3ObjectKey2 = 'yourActionGroupApiSchemaKey2';

// Bedrock Agent IAM role
const agentResourceRoleArn = new cdk.aws_iam.Role(stack, 'BedrockAgentRole', {
  roleName: 'AmazonBedrockExecutionRoleForAgents_agent_test',
  assumedBy: new cdk.aws_iam.ServicePrincipal('bedrock.amazonaws.com'),
  managedPolicies: [cdk.aws_iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')],
}).roleArn;

// Bedrock Knowledge Base IAM role
const knowledgeBaseRoleArn = new iam.Role(stack, 'BedrockKnowledgeBaseRole', {
  roleName: 'AmazonBedrockExecutionRoleForKnowledgeBase_kb_test',
  assumedBy: new iam.ServicePrincipal('bedrock.amazonaws.com'),
  managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')],
}).roleArn;

const myOpenSearchKb = new BedrockKnowledgeBase(stack, 'BedrockOpenSearchKnowledgeBase', {
  name: openSearchKbName,
  roleArn: knowledgeBaseRoleArn,
  storageConfiguration: {
    opensearchServerlessConfiguration: {
      collectionArn: openSearchCollectionArn,
      fieldMapping: {
        metadataField: metadataField,
        textField: textField,
        vectorField: vectorFieldName,
      },
      vectorIndexName: vectorIndexName,
    },
    type: openSearchStorageConfigurationType,
  },
  dataSource: {
    dataSourceConfiguration: {
      s3Configuration: {
        bucketArn: dataSourceBucketArn,
      },
    },
  },
});

const myPineconeKb = new BedrockKnowledgeBase(stack, 'BedrockPineconeKnowledgeBase', {
  name: pineconeKbName,
  roleArn: knowledgeBaseRoleArn,
  storageConfiguration: {
    pineconeConfiguration: {
      credentialsSecretArn: pineconeCredentialsSecretArn,
      connectionString: pineconeConnectionString,
      fieldMapping: {
        metadataField: metadataField,
        textField: textField,
      },
    },
    type: pineconeStorageConfigurationType,
  },
  dataSource: {
    dataSourceConfiguration: {
      s3Configuration: {
        bucketArn: dataSourceBucketArn,
        inclusionPrefixes: [inclusionPrefix],
      },
    },
  },
});

const agent = new BedrockAgent(stack, 'BedrockAgent', {
  agentName: agentName,
  instruction: agentInstruction,
  foundationModel: foundationModel,
  agentResourceRoleArn: agentResourceRoleArn,
  actionGroups: [{
    actionGroupName: actionGroupName1,
    actionGroupExecutor: actionGroupLambdaArn,
    s3BucketName: actionGroupS3BucketName,
    s3ObjectKey: actionGroupS3ObjectKey1,
    desription: 'This is a test action group 1 description.',
  },
  {
    actionGroupName: actionGroupName2,
    actionGroupExecutor: actionGroupLambdaArn,
    s3BucketName: actionGroupS3BucketName,
    s3ObjectKey: actionGroupS3ObjectKey2,
  }],
  knowledgeBaseAssociations: [{
    knowledgeBaseName: openSearchKbName,
    instruction: kbInstruction,
  },
  {
    knowledgeBaseName: pineconeKbName,
    instruction: kbInstruction,
  }],
});

agent.node.addDependency(myOpenSearchKb);
agent.node.addDependency(myPineconeKb);

Example - deploy agent, create Amazon OpenSearch Serverless collection and knowledge base backed by it

Below is an example of how you can provision an AWS OpenSearch Serverless collection, Amazon Bedrock Agent and Amazon Bedrock Knowledge using these constructs.

This example assumes you have an AWS Lambda function ARN (actionGroupLambdaArn), Amazon S3 bucket name (actionGroupS3BucketName) with Open API json or yaml file (actionGroupS3ObjectKey) that you want your agent to use, as well as Amazon S3 bucket ARN (dataSourceBucketArn) where you have files that you want the Knowledge Base to perform ebeddings on.

You can substitute the other variables (such as collectionName, vectorIndexName, etc.) as you'd like. It is also important to download custom_resource and lambda_layer folders and include it in your cdk deployment. Substitute lambdaLayerZipFilePath and customResourcePythonFilePath respectively depending on how you structure your project. This custom resource insures provisioning of OpenSearch indices.

Note: The IAM role creation in this example is for illustration only. Always provion IAM roles with the least required priviliges.

import * as path from 'path';
import {
  App,
  Stack,
  aws_iam as iam,
  aws_opensearchserverless as oss,
  aws_lambda as lambda,
  Duration,
  CustomResource,
  aws_logs as logs,
  custom_resources,
} from 'aws-cdk-lib';
import { BedrockAgent, BedrockKnowledgeBase } from 'bedrock-agents-cdk';

const app = new App();

const stack = new Stack(app, 'BedrockAgentStack');

const agentName = 'MyTestAgent';
const kbName = 'MyTestKnowledgeBase';
const actionGroupName = 'MyTestActionGroup';
const dataSourceName = 'MyDataSource';
const foundationModel = 'anthropic.claude-instant-v1';
const agentInstruction = 'This is a template instruction for my agent. You were created by AWS CDK.';
const kbInstruction = 'This is a template instruction for my knowledge base. You were created by AWS CDK.';
const collectionName = 'my-test-collection';
const vectorIndexName = 'my-test-index';
const vectorFieldName = 'my-test-vector';
const textField = 'text-field';
const metadataField = 'metadata-field';
const storageConfigurationType = 'OPENSEARCH_SERVERLESS';
const dataSourceType = 'S3';
const dataSourceBucketArn = 'yourDataSourceBucketArn';
const actionGroupLambdaArn = 'yourActionGroupLambdaArn';
const actionGroupS3BucketName = 'yourActionGroupApiSchemaBucketName';
const actionGroupS3ObjectKey = 'yourActionGroupApiSchemaKey';
const lambdaLayerZipFilePath = '../lambda_layer/bedrock-agent-layer.zip';
const customResourcePythonFilePath = '../custom_resource';

// Bedrock Agent IAM role
const agentRoleArn = new iam.Role(stack, 'BedrockAgentRole', {
  roleName: 'AmazonBedrockExecutionRoleForAgents_agent_test',
  assumedBy: new iam.ServicePrincipal('bedrock.amazonaws.com'),
  managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')],
}).roleArn;

// Bedrock Knowledge Base IAM role
const kbRoleArn = new iam.Role(stack, 'BedrockKnowledgeBaseRole', {
  roleName: 'AmazonBedrockExecutionRoleForKnowledgeBase_kb_test',
  assumedBy: new iam.ServicePrincipal('bedrock.amazonaws.com'),
  managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess')],
}).roleArn;

// Lambda IAM role
const customResourceRole = new iam.Role(stack, 'CustomResourceRole', {
  assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
  managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')],
});

// Opensearch encryption policy
const encryptionPolicy = new oss.CfnSecurityPolicy(stack, 'EncryptionPolicy', {
  name: 'embeddings-encryption-policy',
  type: 'encryption',
  description: `Encryption policy for ${collectionName} collection.`,
  policy: `
  {
    "Rules": [
      {
        "ResourceType": "collection",
        "Resource": ["collection/${collectionName}*"]
      }
    ],
    "AWSOwnedKey": true
  }
  `,
});

// Opensearch network policy
const networkPolicy = new oss.CfnSecurityPolicy(stack, 'NetworkPolicy', {
  name: 'embeddings-network-policy',
  type: 'network',
  description: `Network policy for ${collectionName} collection.`,
  policy: `
    [
      {
        "Rules": [
          {
            "ResourceType": "collection",
            "Resource": ["collection/${collectionName}*"]
          },
          {
            "ResourceType": "dashboard",
            "Resource": ["collection/${collectionName}*"]
          }
        ],
        "AllowFromPublic": true
      }
    ]
  `,
});

// Opensearch data access policy
const dataAccessPolicy = new oss.CfnAccessPolicy(stack, 'DataAccessPolicy', {
  name: 'embeddings-access-policy',
  type: 'data',
  description: `Data access policy for ${collectionName} collection.`,
  policy: `
    [
      {
        "Rules": [
          {
            "ResourceType": "collection",
            "Resource": ["collection/${collectionName}*"],
            "Permission": [
              "aoss:CreateCollectionItems",
              "aoss:DescribeCollectionItems",
              "aoss:DeleteCollectionItems",
              "aoss:UpdateCollectionItems"
            ]
          },
          {
            "ResourceType": "index",
            "Resource": ["index/${collectionName}*/*"],
            "Permission": [
              "aoss:CreateIndex",
              "aoss:DeleteIndex",
              "aoss:UpdateIndex",
              "aoss:DescribeIndex",
              "aoss:ReadDocument",
              "aoss:WriteDocument"
            ]
          }
        ],
        "Principal": [
          "${customResourceRole.roleArn}",
          "${kbRoleArn}"
        ]
      }
    ]
  `,
});

// Opensearch servelrless collection
const opensearchServerlessCollection = new oss.CfnCollection(stack, 'OpenSearchServerlessCollection', {
  name: collectionName,
  description: 'Collection created by CDK to explore vector embeddings and Bedrock Agents.',
  type: 'VECTORSEARCH',
});

// Allow Lambda access to OpenSearch data plane
customResourceRole.addToPolicy(
  new iam.PolicyStatement({
    resources: [opensearchServerlessCollection.attrArn],
    actions: ['aoss:APIAccessAll'],
  }),
);

// Lambda layer
const layer = new lambda.LayerVersion(stack, 'OpenSearchCustomResourceLayer', {
  code: lambda.Code.fromAsset(path.join(__dirname, lambdaLayerZipFilePath)),
  compatibleRuntimes: [lambda.Runtime.PYTHON_3_10],
  description: 'Required dependencies for Lambda',
});

// Lambda function
const onEvent = new lambda.Function(stack, 'OpenSearchCustomResourceFunction', {
  runtime: lambda.Runtime.PYTHON_3_10,
  handler: 'indices_custom_resource.on_event',
  code: lambda.Code.fromAsset(path.join(__dirname, customResourcePythonFilePath)),
  layers: [layer],
  timeout: Duration.seconds(600),
  environment: {
    COLLECTION_ENDPOINT: opensearchServerlessCollection.attrCollectionEndpoint,
    VECTOR_FIELD_NAME: vectorFieldName,
    VECTOR_INDEX_NAME: vectorIndexName,
    TEXT_FIELD: textField,
    METADATA_FIELD: metadataField,
  },
  role: customResourceRole,
});

// Custom resource provider
const provider = new custom_resources.Provider(stack, 'CustomResourceProvider', {
  onEventHandler: onEvent,
  logRetention: logs.RetentionDays.ONE_DAY,
});

// Custom resource
new CustomResource(stack, 'CustomResource', {
  serviceToken: provider.serviceToken,
});

// Create Bedrock Knowledge Base backed by OpenSearch Servereless
const myOpenSearchKb = new BedrockKnowledgeBase(stack, 'BedrockOpenSearchKnowledgeBase', {
  name: kbName,
  roleArn: kbRoleArn,
  storageConfiguration: {
    opensearchServerlessConfiguration: {
      collectionArn: opensearchServerlessCollection.attrArn,
      fieldMapping: {
        metadataField: metadataField,
        textField: textField,
        vectorField: vectorFieldName,
      },
      vectorIndexName: vectorIndexName,
    },
    type: storageConfigurationType,
  },
  dataSource: {
    name: dataSourceName,
    dataSourceConfiguration: {
      s3Configuration: {
        bucketArn: dataSourceBucketArn,
      },
      type: dataSourceType,
    },
  },
});

// Amazon Bedrock Agent and Knowledge Base backed by Opensearch Serverless
const bedrockAgent = new BedrockAgent(stack, 'BedrockAgent', {
  agentName: agentName,
  instruction: agentInstruction,
  foundationModel: foundationModel,
  agentResourceRoleArn: agentRoleArn,
  actionGroups: [{
    actionGroupName: actionGroupName,
    actionGroupExecutor: actionGroupLambdaArn,
    s3BucketName: actionGroupS3BucketName,
    s3ObjectKey: actionGroupS3ObjectKey,
  }],
  knowledgeBaseAssociations: [{
    knowledgeBaseName: kbName,
    instruction: kbInstruction,
  }],
});

opensearchServerlessCollection.node.addDependency(encryptionPolicy);
opensearchServerlessCollection.node.addDependency(networkPolicy);
opensearchServerlessCollection.node.addDependency(dataAccessPolicy);
onEvent.node.addDependency(opensearchServerlessCollection);
bedrockAgent.node.addDependency(onEvent);
bedrockAgent.node.addDependency(myOpenSearchKb);

Documentation

Overview

bedrock-agents-cdk

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BedrockAgent_IsConstruct

func BedrockAgent_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Returns: true if `x` is an object created from a class which extends `Construct`. Deprecated: use `x instanceof Construct` instead.

func BedrockKnowledgeBase_IsConstruct added in v0.0.5

func BedrockKnowledgeBase_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Returns: true if `x` is an object created from a class which extends `Construct`. Deprecated: use `x instanceof Construct` instead.

func NewBedrockAgent_Override

func NewBedrockAgent_Override(b BedrockAgent, scope constructs.Construct, name *string, props *BedrockAgentProps)

func NewBedrockKnowledgeBase_Override added in v0.0.5

func NewBedrockKnowledgeBase_Override(b BedrockKnowledgeBase, scope constructs.Construct, name *string, props *BedrockKnowledgeBaseProps)

Types

type ActionGroup

type ActionGroup struct {
	// Required.
	//
	// Lambda function ARN that will be used in this action group.
	// The provided Lambda function will be assigned a resource-based policy
	// to allow access from the newly created agent.
	ActionGroupExecutor *string `field:"required" json:"actionGroupExecutor" yaml:"actionGroupExecutor"`
	// Required.
	//
	// Action group name.
	ActionGroupName *string `field:"required" json:"actionGroupName" yaml:"actionGroupName"`
	// Required.
	//
	// S3 bucket name where Open API schema is stored.
	// Bucket must be in the same region where agent is created.
	S3BucketName *string `field:"required" json:"s3BucketName" yaml:"s3BucketName"`
	// Required.
	//
	// S3 bucket key for the actual schema.
	// Must be either JSON or yaml file.
	S3ObjectKey *string `field:"required" json:"s3ObjectKey" yaml:"s3ObjectKey"`
	// Optional.
	//
	// Description for the action group.
	Description *string `field:"optional" json:"description" yaml:"description"`
}

type BaseFieldMapping

type BaseFieldMapping struct {
	// Required.
	//
	// Metadata field that you configured in your Vector DB.
	// Bedrock will store metadata that is required to carry out source attribution
	// and enable data ingestion and querying.
	MetadataField *string `field:"required" json:"metadataField" yaml:"metadataField"`
	// Required.
	//
	// Text field that you configured in your Vector DB.
	// Bedrock will store raw text from your data in chunks in this field.
	TextField *string `field:"required" json:"textField" yaml:"textField"`
}

type BedrockAgent

type BedrockAgent interface {
	constructs.Construct
	// `agentArn` is the ARN for the created agent.
	AgentArn() *string
	// `agentId` is the unique identifier for the created agent.
	AgentId() *string
	// The tree node.
	Node() constructs.Node
	// Returns a string representation of this construct.
	ToString() *string
}

func NewBedrockAgent

func NewBedrockAgent(scope constructs.Construct, name *string, props *BedrockAgentProps) BedrockAgent

type BedrockAgentProps

type BedrockAgentProps struct {
	// Required.
	//
	// Name of the agent.
	AgentName *string `field:"required" json:"agentName" yaml:"agentName"`
	// Required.
	//
	// Instruction for the agent.
	// Characters length:.
	Instruction *string `field:"required" json:"instruction" yaml:"instruction"`
	// Optional.
	//
	// Action group for the agent. If specified must contain “s3BucketName“ and “s3ObjectKey“ with JSON
	// or yaml Open API schema, as well as Lambda ARN for the action group executor,
	// and action group name.
	ActionGroups *[]*ActionGroup `field:"optional" json:"actionGroups" yaml:"actionGroups"`
	// Optional.
	//
	// Resource role ARN for an agent.
	// Role name must start with “AmazonBedrockExecutionRoleForAgents_“ prefix and assumed by “bedrock.amazonaws.com“.
	// If role is not specified the default one will be created with no attached policies to it.
	// If actionGroup is specified and the role is not, then the default created role will have an attached S3 read access
	// to the bucket provided in the actionGroup.
	AgentResourceRoleArn *string `field:"optional" json:"agentResourceRoleArn" yaml:"agentResourceRoleArn"`
	// Optional.
	//
	// Description for the agent.
	Description *string `field:"optional" json:"description" yaml:"description"`
	// Optional.
	//
	// Foundation model.
	//
	// Example:
	//   - "anthropic.claude-instant-v1" or "anthropic.claude-v2"
	//
	// Default: - "anthropic.claude-v2"
	//
	FoundationModel *string `field:"optional" json:"foundationModel" yaml:"foundationModel"`
	// Optional.
	//
	// Max Session Time in seconds.
	// Default: - 3600.
	//
	IdleSessionTTLInSeconds *float64 `field:"optional" json:"idleSessionTTLInSeconds" yaml:"idleSessionTTLInSeconds"`
	// Optional.
	//
	// A list of knowledge base association objects
	// consisting of name and instruction for the associated knowledge base.
	//
	// Example:
	//   knowledgeBaseAssociations: [
	//     {
	//       knowledgeBaseName: "knowledge-base-name",
	//       instruction: "instruction-for-knowledge-base"
	//     }
	//
	KnowledgeBaseAssociations *[]*KnowledgeBaseAssociation `field:"optional" json:"knowledgeBaseAssociations" yaml:"knowledgeBaseAssociations"`
}

type BedrockKnowledgeBase added in v0.0.5

type BedrockKnowledgeBase interface {
	constructs.Construct
	// `dataSourceId` is the unique identifier for the created data source.
	DataSourceId() *string
	// `knowledgeBaseArn` is the ARN for the created knowledge base.
	KnowledgeBaseArn() *string
	// `knowledgeBaseId` is the unique identifier for the created knowledge base.
	KnowledgeBaseId() *string
	// The tree node.
	Node() constructs.Node
	// Returns a string representation of this construct.
	ToString() *string
}

func NewBedrockKnowledgeBase added in v0.0.5

func NewBedrockKnowledgeBase(scope constructs.Construct, name *string, props *BedrockKnowledgeBaseProps) BedrockKnowledgeBase

type BedrockKnowledgeBaseProps added in v0.0.5

type BedrockKnowledgeBaseProps struct {
	// Required.
	//
	// Data source configuration.
	DataSource *DataSource `field:"required" json:"dataSource" yaml:"dataSource"`
	// Required.
	//
	// Name of the KnowledgeBase.
	Name *string `field:"required" json:"name" yaml:"name"`
	// Required.
	//
	// Resource role ARN for a knowledge base.
	// Role name must start with “AmazonBedrockExecutionRoleForKnowledgeBase_“ prefix and assumed by “bedrock.amazonaws.com“.
	// Role must have access to the S3 bucket used as a data source as a knowledge base.
	// If you use OpenSearch serverless, the role must have “aoss:APIAccessAll“ policy attached to it
	// allowing it to make API calls against your collection's data plane. Your collection
	// must also allow data access from KnowledgeBase role.
	// See more here @see https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html
	RoleArn *string `field:"required" json:"roleArn" yaml:"roleArn"`
	// Required.
	//
	// KnowledgeBase storage configuration.
	// Has to be either “opensearchServerlessConfiguration“,
	// “pineconeConfiguration“, “redisEnterpriseCloudConfiguration“ or `rdsConfiguration`
	// and respective type field mapping.
	StorageConfiguration interface{} `field:"required" json:"storageConfiguration" yaml:"storageConfiguration"`
	// Optional.
	//
	// Description for the knowledge base.
	Description *string `field:"optional" json:"description" yaml:"description"`
	// Optional.
	//
	// KnowledgeBase configuration.
	// Default: type: "VECTOR",
	// vectorKnowledgeBaseConfiguration: {
	//     embeddingModelArn: "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1"
	// }.
	//
	KnowledgeBaseConfiguration *KnowledgeBaseConfiguration `field:"optional" json:"knowledgeBaseConfiguration" yaml:"knowledgeBaseConfiguration"`
	// Optional.
	//
	// Removal Policy. If you want to keep your Knowledge Base intact
	// in case you destroy this CDK make sure you set removalPolicy to
	// “cdk.RemovalPolicy.RETAIN“. By default your Knowledge Base will be
	// deleted along with the agent.
	// Default: - cdk.RemovalPolicy.DESTROY
	//
	RemovalPolicy awscdk.RemovalPolicy `field:"optional" json:"removalPolicy" yaml:"removalPolicy"`
}

type DataSource

type DataSource struct {
	// Required.
	//
	// Data Source Configuration.
	//
	// Example:
	//   dataSourceConfiguration = {
	//   s3Configuration: {
	//     bucketArn: "yourS3BucketArn",
	//   },
	//     "type": "S3"
	//   }
	//
	DataSourceConfiguration *DataSourceConfiguration `field:"required" json:"dataSourceConfiguration" yaml:"dataSourceConfiguration"`
	// Optional.
	//
	// Name for your data source.
	// Default: - `MyDataSource-${agentName}` or `MyDataSource-${knowledgeBaseName}`.
	//
	Name *string `field:"optional" json:"name" yaml:"name"`
}

type DataSourceConfiguration

type DataSourceConfiguration struct {
	// Required.
	//
	// S3 Configuration.
	//
	// Example:
	//     s3Configuration: {
	//       bucketArn: "yourS3BucketArn"
	//     }
	//
	S3Configuration *S3Configuration `field:"required" json:"s3Configuration" yaml:"s3Configuration"`
	// Optional.
	//
	// Type of configuration.
	// Default: - "S3".
	//
	Type *string `field:"optional" json:"type" yaml:"type"`
}

type KnowledgeBaseAssociation added in v0.0.5

type KnowledgeBaseAssociation struct {
	// Required.
	//
	// Instruction based on the design and type of information of the knowledge base.
	// This will impact how the knowledge base interacts with the agent.
	Instruction *string `field:"required" json:"instruction" yaml:"instruction"`
	// Required.
	//
	// Name of the existing Knowledge Base that
	// you want to associate with the agent.
	KnowledgeBaseName *string `field:"required" json:"knowledgeBaseName" yaml:"knowledgeBaseName"`
}

type KnowledgeBaseConfiguration

type KnowledgeBaseConfiguration struct {
	// Required.
	//
	// Type of configuration.
	// Default: - "VECTOR".
	//
	Type *string `field:"required" json:"type" yaml:"type"`
	// Required.
	//
	// Embeddings model to convert your data into an embedding.
	// Default: - vectorKnowledgeBaseConfiguration: {
	// embeddingModelArn: "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1"
	// }.
	//
	VectorKnowledgeBaseConfiguration *VectorKnowledgeBaseConfiguration `field:"required" json:"vectorKnowledgeBaseConfiguration" yaml:"vectorKnowledgeBaseConfiguration"`
}

type OpenSearchFieldMapping

type OpenSearchFieldMapping struct {
	// Required.
	//
	// Metadata field that you configured in your Vector DB.
	// Bedrock will store metadata that is required to carry out source attribution
	// and enable data ingestion and querying.
	MetadataField *string `field:"required" json:"metadataField" yaml:"metadataField"`
	// Required.
	//
	// Text field that you configured in your Vector DB.
	// Bedrock will store raw text from your data in chunks in this field.
	TextField *string `field:"required" json:"textField" yaml:"textField"`
	// Required.
	//
	// Vector field that you configured in OpenSearch.
	// Bedrock will store the vector embeddings in this field.
	VectorField *string `field:"required" json:"vectorField" yaml:"vectorField"`
}

type OpenSearchServerlessConfiguration

type OpenSearchServerlessConfiguration struct {
	// Required.
	//
	// ARN of your OpenSearch Serverless Collection.
	CollectionArn *string `field:"required" json:"collectionArn" yaml:"collectionArn"`
	// Required.
	//
	// Field mapping consisting of “vectorField“,
	// “textField“ and “metadataField“.
	FieldMapping *OpenSearchFieldMapping `field:"required" json:"fieldMapping" yaml:"fieldMapping"`
	// Required.
	//
	// Vector index name of your OpenSearch Serverless Collection.
	VectorIndexName *string `field:"required" json:"vectorIndexName" yaml:"vectorIndexName"`
}

type OpenSearchServerlessStorageConfiguration

type OpenSearchServerlessStorageConfiguration struct {
	// Required.
	//
	// OpenSearch Serverless Configuration.
	//
	// Example:
	//   opensearchServerlessConfiguration: {
	//       collectionArn: "arn:aws:opensearchserverless:us-east-1:123456789012:collection/my-collection",
	//       fieldMapping: {
	//           textField: "text",
	//           metadataField: "metadata",
	//           vectorField: "vector"
	//       },
	//       vectorIndexName: "my-index",
	//   },
	//
	OpensearchServerlessConfiguration *OpenSearchServerlessConfiguration `field:"required" json:"opensearchServerlessConfiguration" yaml:"opensearchServerlessConfiguration"`
	// Required.
	//
	// Has to be “"OPENSEARCH_SERVERLESS"“ for Opensearch Serverless Configuration.
	Type *string `field:"required" json:"type" yaml:"type"`
}

type PineconeConfiguration

type PineconeConfiguration struct {
	// Required.
	//
	// Connection string for your Pinecone index management page.
	ConnectionString *string `field:"required" json:"connectionString" yaml:"connectionString"`
	// Required.
	//
	// ARN of the secret containing the API Key to use when connecting to the Pinecone database.
	// Learn more in the link below.
	// See: https://www.pinecone.io/blog/amazon-bedrock-integration/
	//
	CredentialsSecretArn *string `field:"required" json:"credentialsSecretArn" yaml:"credentialsSecretArn"`
	// Required.
	//
	// Field mapping consisting of “textField“ and “metadataField“.
	FieldMapping *PineconeFieldMapping `field:"required" json:"fieldMapping" yaml:"fieldMapping"`
	// Optional.
	//
	// Name space that will be used for writing new data to your Pinecone database.
	Namespace *string `field:"optional" json:"namespace" yaml:"namespace"`
}

type PineconeFieldMapping

type PineconeFieldMapping struct {
	// Required.
	//
	// Metadata field that you configured in your Vector DB.
	// Bedrock will store metadata that is required to carry out source attribution
	// and enable data ingestion and querying.
	MetadataField *string `field:"required" json:"metadataField" yaml:"metadataField"`
	// Required.
	//
	// Text field that you configured in your Vector DB.
	// Bedrock will store raw text from your data in chunks in this field.
	TextField *string `field:"required" json:"textField" yaml:"textField"`
}

type PineconeStorageConfiguration

type PineconeStorageConfiguration struct {
	// Required.
	//
	// Pinecone Configuration.
	//
	// Example:
	//   pineconeConfiguration: {
	//       credentialsSecretArn: 'arn:aws:secretsmanager:your-region:123456789098:secret:apiKey';
	//       connectionString: 'https://your-connection-string.pinecone.io';
	//       fieldMapping: {
	//           metadataField: 'metadata-field',
	//           textField: 'text-field'
	//       },
	//   },
	//
	PineconeConfiguration *PineconeConfiguration `field:"required" json:"pineconeConfiguration" yaml:"pineconeConfiguration"`
	// Required.
	//
	// Has to be “"PINECONE"“ for Pinecone Configuration.
	Type *string `field:"required" json:"type" yaml:"type"`
}

type RdsConfiguration added in v0.0.8

type RdsConfiguration struct {
	// Required.
	//
	// The Secret ARN of you Amazon Aurora DB cluster.
	CredentialsSecretArn *string `field:"required" json:"credentialsSecretArn" yaml:"credentialsSecretArn"`
	// Required.
	//
	// The name of your Database.
	DatabaseName *string `field:"required" json:"databaseName" yaml:"databaseName"`
	// Required.
	//
	// Field mapping consisting of “vectorField“, “primaryKeyField“,
	// “textField“ and “metadataField“.
	FieldMapping *RdsFieldMapping `field:"required" json:"fieldMapping" yaml:"fieldMapping"`
	// Required.
	//
	// The ARN of your Amazon Aurora DB cluster.
	ResourceArn *string `field:"required" json:"resourceArn" yaml:"resourceArn"`
	// Required.
	//
	// The Table Name of your Amazon Aurora DB cluster.
	TableName *string `field:"required" json:"tableName" yaml:"tableName"`
}

type RdsFieldMapping added in v0.0.8

type RdsFieldMapping struct {
	// Required.
	//
	// Metadata field that you configured in your Vector DB.
	// Bedrock will store metadata that is required to carry out source attribution
	// and enable data ingestion and querying.
	MetadataField *string `field:"required" json:"metadataField" yaml:"metadataField"`
	// Required.
	//
	// Text field that you configured in your Vector DB.
	// Bedrock will store raw text from your data in chunks in this field.
	TextField *string `field:"required" json:"textField" yaml:"textField"`
	// Required.
	//
	// The primary key that you configured in Amazon Aurora.
	PrimaryKeyField *string `field:"required" json:"primaryKeyField" yaml:"primaryKeyField"`
	// Required.
	//
	// Vector field that you configured in Amazon Aurora.
	// Bedrock will store the vector embeddings in this field.
	VectorField *string `field:"required" json:"vectorField" yaml:"vectorField"`
}

type RdsStorageConfiguration added in v0.0.8

type RdsStorageConfiguration struct {
	// Required.
	//
	// RDS Configuration.
	//
	// Example:
	//   rdsConfiguration: {
	//       resourceArn: "arn:aws:rds:us-east-2:12345:cluster:my-aurora-cluster-1",
	//       databaseName: "mydbcluster",
	//       tableName: "mytable",
	//       credentialsSecretArn: "arn:aws:rds:us-east-2:12345:cluster:my-aurora-cluster-1",
	//       fieldMapping: {
	//           vectorField: "vectorField",
	//           textField: "text"
	//           metadataField: "metadata",
	//           primaryKeyField: "id",
	//       },
	//   },
	//
	RdsConfiguration *RdsConfiguration `field:"required" json:"rdsConfiguration" yaml:"rdsConfiguration"`
	// Required.
	//
	// Has to be “"RDS"“ for RDS (Aurora) Configuration.
	Type *string `field:"required" json:"type" yaml:"type"`
}

type RedisEnterpriseCloudConfiguration

type RedisEnterpriseCloudConfiguration struct {
	// Required.
	//
	// ARN of the secret defining the username, password, serverCertificate,
	// clientCertificate and clientPrivateKey to use when connecting to the Redis Enterprise Cloud database.
	// Learn more in the link below.
	// See: https://docs.redis.com/latest/rc/cloud-integrations/aws-marketplace/aws-bedrock/set-up-redis/
	//
	CredentialsSecretArn *string `field:"required" json:"credentialsSecretArn" yaml:"credentialsSecretArn"`
	// Required.
	//
	// The endpoint URL for your Redis Enterprise Cloud database.
	EndpointUrl *string `field:"required" json:"endpointUrl" yaml:"endpointUrl"`
	// Required.
	//
	// Field mapping consisting of “vectorField“,
	// “textField“ and “metadataField“.
	FieldMapping *RedisFieldMapping `field:"required" json:"fieldMapping" yaml:"fieldMapping"`
	// Required.
	//
	// Vector index name of your Redis Enterprise Cloud.
	VectorIndexName *string `field:"required" json:"vectorIndexName" yaml:"vectorIndexName"`
}

type RedisEnterpriseCloudStorageConfiguration

type RedisEnterpriseCloudStorageConfiguration struct {
	// Required.
	//
	// Redis Enterprise Cloud Configuration.
	//
	// Example:
	//   redisEnterpriseCloudConfiguration: {
	//       credentialsSecretArn: 'arn:aws:secretsmanager:your-region:123456789098:secret:apiKey';
	//       endpointUrl: 'your-endpoint-url';
	//       fieldMapping: {
	//           metadataField: 'metadata-field',
	//           textField: 'text-field',
	//           vectorField: "vector"
	//       },
	//       vectorIndexName: 'your-vector-index-name',
	//   },
	//
	RedisEnterpriseCloudConfiguration *RedisEnterpriseCloudConfiguration `field:"required" json:"redisEnterpriseCloudConfiguration" yaml:"redisEnterpriseCloudConfiguration"`
	// Required.
	//
	// Has to be “"REDIS_ENTERPRISE_CLOUD"“ for Redis Enterprise Cloud Configuration.
	Type *string `field:"required" json:"type" yaml:"type"`
}

type RedisFieldMapping

type RedisFieldMapping struct {
	// Required.
	//
	// Metadata field that you configured in your Vector DB.
	// Bedrock will store metadata that is required to carry out source attribution
	// and enable data ingestion and querying.
	MetadataField *string `field:"required" json:"metadataField" yaml:"metadataField"`
	// Required.
	//
	// Text field that you configured in your Vector DB.
	// Bedrock will store raw text from your data in chunks in this field.
	TextField *string `field:"required" json:"textField" yaml:"textField"`
	// Required.
	//
	// Vector field that you configured in Redis Enterprise Cloud.
	// Bedrock will store the vector embeddings in this field.
	VectorField *string `field:"required" json:"vectorField" yaml:"vectorField"`
}

type S3Configuration

type S3Configuration struct {
	// Required.
	//
	// S3 bucket with files that you want to create embeddings
	// on for agent to make search on.
	BucketArn *string `field:"required" json:"bucketArn" yaml:"bucketArn"`
	// Optional.
	//
	// Prefix for a bucket if your files located in a folder.
	// If you have a folder “files“inside the bucket,
	// and the folder contains files you want to perform
	// search on, then use “[files/]“ as an “inclusionPrefixes“.
	InclusionPrefixes *[]*string `field:"optional" json:"inclusionPrefixes" yaml:"inclusionPrefixes"`
}

type VectorKnowledgeBaseConfiguration

type VectorKnowledgeBaseConfiguration struct {
	// Required.
	//
	// Embeddings model to convert your data into an embedding.
	// Default: - "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1"
	//
	EmbeddingModelArn *string `field:"required" json:"embeddingModelArn" yaml:"embeddingModelArn"`
}

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL