View a markdown version of this page

Augment response generation for your agent with knowledge base - Amazon Bedrock

Augment response generation for your agent with knowledge base

Amazon Bedrock Knowledge Bases help you take advantage of Retrieval Augmented Generation (RAG), a popular technique that involves drawing information from a data store to augment the responses generated by Large Language Models (LLMs). When you set up a knowledge base with your data source and vector store, your application can query the knowledge base to return information to answer the query either with direct quotations from sources or with natural responses generated from the query results.

To use Amazon Bedrock Knowledge Bases with your Amazon Bedrock Agent, you'll have to first create a knowledge base and then associate the knowledge base with the agent. If you haven't yet created a knowledge base, see Retrieve data and generate AI responses with Amazon Bedrock Knowledge Bases to learn about knowledge bases and create one. You can associate a knowledge base during agent creation or after an agent has been created. To associate a knowledge base to an existing agent, choose the tab for your preferred method, and then follow the steps:

Console
To add a knowledge base
  1. Sign in to the AWS Management Console with an IAM identity that has permissions to use the Amazon Bedrock console. Then, open the Amazon Bedrock console at https://console.aws.amazon.com/bedrock.

  2. Select Agents from the left navigation pane. Then, choose an agent in the Agents section.

  3. Choose Edit in Agent builder

  4. For the Knowledge bases section, choose Add.

  5. Choose a knowledge base that you have created and provide instructions for how the agent should interact with it. These instructions tell the agent when and how to query this knowledge base during a conversation. The agent includes these instructions in its prompt context to decide whether to retrieve information from the knowledge base for a given user request. For example: Use this knowledge base to answer questions about company HR policies, benefits, and employee guidelines. Only query it when the user asks about internal company policies.

  6. Choose Add. A success banner appears at the top.

  7. To apply the changes that you made to the agent before testing it, choose Prepare before testing it.

API

To associate a knowledge base with an agent, send an AssociateAgentKnowledgeBase request with a Agents for Amazon Bedrock build-time endpoint.

The following list describes the fields in the request:

  • The following fields are required:

    Field Short description
    agentId ID of the agent
    agentVersion Version of the agent
    knowledgeBaseId ID of the knowledge base
  • The following fields are optional:

    Field Short description
    description Instructions that tell the agent when and how to query this knowledge base. The agent includes this text in its prompt to determine whether to retrieve information from the knowledge base for a given user request. Write it as a directive describing what the knowledge base contains and when to use it. For example: Use this knowledge base to answer customer questions about product specifications, pricing, and availability. Do not query it for general conversation.
    knowledgeBaseState To prevent the agent from querying the knowledge base, specify DISABLED

You can modify the query configurations of a knowledge base attached to your agent by using the sessionState field in the InvokeAgent request when you invoke your agent. For more information, see Control agent session context.