Amazon Bedrock is a fully managed service that offers a choice of foundation models (FMs) along with a broad set of capabilities for building generative AI applications.
This module includes resources to deploy Bedrock features.
With Knowledge Bases for Amazon Bedrock, you can give FMs and agents contextual information from your company’s private data sources for Retrieval Augmented Generation (RAG) to deliver more relevant, accurate, and customized responses.
A vector index on a vector store is required to create a Knowledge Base. This construct currently supports Amazon OpenSearch Serverless, Amazon RDS Aurora PostgreSQL, Pinecone, and MongoDB. By default, this resource will create an OpenSearch Serverless vector collection and index for each Knowledge Base you create, but you can provide an existing collection to have more control. For other resources you need to have the vector stores already created and credentials stored in AWS Secrets Manager.
The resource accepts an instruction prop that is provided to any Bedrock Agent it is associated with so the agent can decide when to query the Knowledge Base.
To create a knowledge base, make sure you pass in the appropriate variables and set the create_kb
variable to true
.
Example default Opensearch Serverless Agent with Knowledgebase
provider "opensearch" {
url = module.bedrock.default_collection[0].collection_endpoint
healthcheck = false
}
module "bedrock" {
source = "aws-ia/bedrock/aws"
version = "0.0.1"
create_kb = true
create_default_kb = true
foundation_model = "anthropic.claude-v2"
instruction = "You are an automotive assisant who can provide detailed information about cars to a customer."
}
Data sources are the various repositories or systems from which information is extracted and ingested into the knowledge base. These sources provide the raw content that will be processed, indexed, and made available for querying within the knowledge base system. Data sources can include various types of systems such as document management systems, databases, file storage systems, and content management platforms. Supported Data Sources include Amazon S3 buckets.
- Amazon S3. You can either create a new data source by passing in the existing data source arn to the input variable
kb_s3_data_source
or create a new one by leaving that value asnull
whencreate_default_kb
is set to true.
Enable generative AI applications to execute multistep tasks across company systems and data sources.
The following example creates an Agent with a simple instruction and without any action groups or knowedlge bases.
module "bedrock" {
source = "aws-ia/bedrock/aws"
version = "0.0.1"
foundation_model = "anthropic.claude-v2"
instruction = "You are an automotive assisant who can provide detailed information about cars to a customer."
}
To create an Agent with a default Knowledge Base you simply set create_kb
and create_default_kb
to true
:
module "bedrock" {
source = "aws-ia/bedrock/aws"
version = "0.0.1"
create_kb = true
create_default_kb = true
foundation_model = "anthropic.claude-v2"
instruction = "You are an automotive assisant who can provide detailed information about cars to a customer."
}
An action group defines functions your agent can call. The functions are Lambda functions. The action group uses an OpenAPI schema to tell the agent what your functions do and how to call them. You can configure an action group by passing in the appropriate input variables.
The Agent constructs take an optional parameter shouldPrepareAgent to indicate that the Agent should be prepared after any updates to an agent, Knowledge Base association, or action group. This may increase the time to create and update those resources. By default, this value is true.
Bedrock Agents allows you to customize the prompts and LLM configuration for its different steps. You can disable steps or create a new prompt template. Prompt templates can be inserted from plain text files.
Name | Version |
---|---|
terraform | >= 1.0.7 |
aws | ~>5.0 |
awscc | >= 1.0.0 |
opensearch | = 2.2.0 |
random | >= 3.6.0 |
time | ~> 0.6 |
Name | Version |
---|---|
aws | ~>5.0 |
awscc | >= 1.0.0 |
opensearch | = 2.2.0 |
random | >= 3.6.0 |
time | ~> 0.6 |
No modules.
Name | Description | Type | Default | Required |
---|---|---|---|---|
foundation_model | The foundation model for the Bedrock agent. | string |
n/a | yes |
instruction | A narrative instruction to provide the agent as context. | string |
n/a | yes |
action_group_description | Description of the action group. | string |
null |
no |
action_group_name | Name of the action group. | string |
null |
no |
action_group_state | State of the action group. | string |
null |
no |
agent_description | A description of agent. | string |
null |
no |
agent_name | The name of your agent. | string |
"TerraformBedrockAgents" |
no |
api_schema_payload | String OpenAPI Payload. | string |
null |
no |
api_schema_s3_bucket_name | A bucket in S3. | string |
null |
no |
api_schema_s3_object_key | An object key in S3. | string |
null |
no |
base_prompt_template | Defines the prompt template with which to replace the default prompt template. | string |
null |
no |
collection_arn | The ARN of the collection. | string |
null |
no |
collection_name | The name of the collection. | string |
null |
no |
connection_string | The endpoint URL for your index management page. | string |
null |
no |
create_ag | Whether or not to create an action group. | bool |
false |
no |
create_agent | Whether or not to deploy an agent. | bool |
true |
no |
create_default_kb | Whether or not to create the default knowledge base. | bool |
false |
no |
create_kb | Whether or not to attach a knowledge base. | bool |
false |
no |
create_mongo_config | Whether or not to use MongoDB Atlas configuration | bool |
false |
no |
create_opensearch_config | Whether or not to use Opensearch Serverless configuration | bool |
false |
no |
create_pinecone_config | Whether or not to use Pinecone configuration | bool |
false |
no |
create_rds_config | Whether or not to use RDS configuration | bool |
false |
no |
credentials_secret_arn | The ARN of the secret in Secrets Manager that is linked to your database | string |
null |
no |
custom_control | Custom control of action execution. | string |
null |
no |
database_name | Name of the database. | string |
null |
no |
endpoint | Database endpoint | string |
null |
no |
endpoint_service_name | MongoDB Atlas endpoint service name. | string |
null |
no |
existing_kb | The ID of the existing knowledge base. | string |
null |
no |
function_description | Description of function. | string |
null |
no |
function_name | Name for a resource. | string |
null |
no |
function_parameters_description | Description of function parameter. | string |
null |
no |
function_parameters_required | If a parameter is required for a function call. | bool |
false |
no |
function_parameters_type | Parameter type. | string |
null |
no |
idle_session_ttl | How long sessions should be kept open for the agent. | number |
600 |
no |
kb_description | Description of knowledge base. | string |
"Terraform deployed Knowledge Base" |
no |
kb_embedding_model_arn | The ARN of the model used to create vector embeddings for the knowledge base. | string |
"arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1" |
no |
kb_name | Name of the knowledge base. | string |
"knowledge-base" |
no |
kb_role_arn | The ARN of the IAM role with permission to invoke API operations on the knowledge base. | string |
null |
no |
kb_s3_data_source | The S3 data source ARN for the knowledge base. | string |
null |
no |
kb_state | State of knowledge base; whether it is enabled or disabled | string |
"ENABLED" |
no |
kb_storage_type | The storage type of a knowledge base. | string |
null |
no |
kb_tags | A map of tags keys and values for the knowledge base. | map(string) |
null |
no |
kb_type | The type of a knowledge base. | string |
null |
no |
kms_key_arn | KMS encryption key to use for the agent. | string |
null |
no |
lambda_action_group_executor | ARN of Lambda. | string |
null |
no |
max_length | The maximum number of tokens to generate in the response. | number |
0 |
no |
metadata_field | The name of the field in which Amazon Bedrock stores metadata about the vector store. | string |
"AMAZON_BEDROCK_METADATA" |
no |
name_prefix | This value is appended at the beginning of resource names. | string |
"BedrockAgents" |
no |
namespace | The namespace to be used to write new data to your pinecone database | string |
null |
no |
override_lambda_arn | The ARN of the Lambda function to use when parsing the raw foundation model output in parts of the agent sequence. | string |
null |
no |
parent_action_group_signature | Action group signature for a builtin action. | string |
null |
no |
parser_mode | Specifies whether to override the default parser Lambda function. | string |
null |
no |
primary_key_field | The name of the field in which Bedrock stores the ID for each entry. | string |
null |
no |
prompt_creation_mode | Specifies whether to override the default prompt template. | string |
null |
no |
prompt_override | Whether to provide prompt override configuration. | bool |
false |
no |
prompt_state | Specifies whether to allow the agent to carry out the step specified in the promptType. | string |
null |
no |
prompt_type | The step in the agent sequence that this prompt configuration applies to. | string |
null |
no |
resource_arn | The ARN of the vector store. | string |
null |
no |
skip_resource_in_use | Specifies whether to allow deleting action group while it is in use. | bool |
null |
no |
stop_sequences | A list of stop sequences. | list(string) |
[] |
no |
table_name | The name of the table in the database. | string |
null |
no |
tags | Tag bedrock agent resource. | map(string) |
null |
no |
temperature | The likelihood of the model selecting higher-probability options while generating a response. | number |
0 |
no |
text_field | The name of the field in which Amazon Bedrock stores the raw text from your data. | string |
"AMAZON_BEDROCK_TEXT_CHUNK" |
no |
top_k | Sample from the k most likely next tokens. | number |
50 |
no |
top_p | Cumulative probability cutoff for token selection. | number |
0.5 |
no |
vector_field | The name of the field where the vector embeddings are stored | string |
"bedrock-knowledge-base-default-vector" |
no |
vector_index_name | The name of the vector index. | string |
"bedrock-knowledge-base-default-index" |
no |
Name | Description |
---|---|
default_collection | Opensearch default collection value. |