Create a Knowledge Base and an Agent in Amazon Bedrock

Overview

To use the Amazon Bedrock Snaps (Agent Retrieve, Agent Retrieve and Generate, and Invoke Agent) you must create a Knowledge Base and an Agent to access the resources in Amazon Bedrock. To configure these Snaps successfully, create a Knowledge base and agent as described in the procedure below.

Prerequisites

  • An AWS account with IAM role and necessary permissions in Amazon Bedrock.
  • Access to the foundation models (FM) that you want to use.
  • Create an S3 bucket to upload the files you want to query.

Key steps

Create a Knowledge Base in Amazon Bedrock

  1. Log in to the Amazon Bedrock console.
  2. From the left navigation pane, select Knowledge bases and click Create knowledge base.Create Knowledge Base
  3. On the Provide knowledge base details page, configure the following:
    1. Specify a meaningful name for your Knowledge base.
    2. Choose the IAM role that provides Amazon Bedrock permission to access other AWS services and click Next.
      Knowledge Base Details

  4. On the Configure data source page, select Browse S3 and choose the S3 bucket as a data source and click Next.
    Choose S3 bucket

  5. Select an embeddings model and use the default vector database (OpenSearch serverless) and click Next.
    Embedding Model

  6. Review the settings and select Create knowledge base.
    Review and create Knowledge Base

    Note: After the Knowledge base is created in Amazon Bedrock, you can begin to use the Agent Retrieve and Agent Retrieve and Generate Snaps. After configuring your Amazon Bedrock Account, you can locate the newly created Knowledge base in the suggestible property of the field.

Create an Agent in Amazon Bedrock

  1. From the left navigation pane, select Agents and click Create Agent.
    Create Agent

  2. Enter a name for the agent and click Create.
  3. In the Select model section, we recommend you to use Claude 3 Sonnet and add instructions for the Agent. For example, "You are an assistant that will answer questions from the knowledge base and/or the chat history. Note that some questions may require both, so please answer as much as you can without making up information".
    Agent and model details

  4. After a model has been selected, scroll to the top of the page and click Save
    Save agent

    Note: If you do not save, it might result in an error when adding a knowledge base.

Associate the Agent with the Knowledge Base

  1. In the Knowledge bases section, select Add.
    Add Knowledge Base

  2. Choose the newly created knowledge base, and click Add.
    Choose Knowledge Base

  3. Click Save and then click Prepare.
    Save and prepare

  4. Optional. Create an Agent Alias. This is an optional step because Amazon Bedrock creates a test alias for you. An alias is required to use an Invoke Agent Snap. Aliases can be used to associate different versions of the agent, so users can evaluate different models or configurations.
    Test alias


    Test alias

Note: After you have associated the Agent with the Knowledge base, you can begin to use the Invoke Agent Snap. Once you have configured your Amazon Bedrock Account, you can locate the newly created Agent ID and Agent alias ID in the suggestible property of the respective fields.

Configure the Knowledge Base and Agent in the Agent Retrieve and Agent Retrieve and Generate Snaps

  1. Drag the Agent Retrieve or Agent Retrieve and Generate Snap.
  2. Click the Suggestion icon of the Knowledge base ID field. The newly created Knowledge base is displayed.
    Agent-and-Retrieve-Generate-Snap

  1. Drag the Invoke Agent Snap.
  2. Click the Suggestions icon of the Agent ID and Agent Alias ID. The newly created Agent aliases are displayed.
    Invoke agent