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.