

# Augment response generation for your agent with knowledge base
<a name="agents-kb-add"></a>

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](knowledge-base.md) to learn about knowledge bases and create one. You can associate a knowledge base during [agent creation](agents-create.md) 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](https://console.aws.amazon.com/bedrock).

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

1. Choose **Edit in Agent builder**

1. For the **Knowledge bases** section, choose **Add**.

1. Choose a knowledge base that you have created and provide instructions for how the agent should interact with it.

1. Choose **Add**. A success banner appears at the top.

1. 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](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_AssociateAgentKnowledgeBase.html) request with a [Agents for Amazon Bedrock build-time endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt).

The following list describes the fields in the request:
+ The following fields are required:  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/bedrock/latest/userguide/agents-kb-add.html)
+ The following fields are optional:  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/bedrock/latest/userguide/agents-kb-add.html)

------

You can modify the [query configurations](kb-test-config.md) of a knowledge base attached to your agent by using the `sessionState` field in the [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html) request when you invoke your agent. For more information, see [Control agent session context](agents-session-state.md).

# View information about an agent-knowledge base association
<a name="agents-kb-view"></a>

To learn how to view information about a knowledge base, choose the tab for your preferred method, and then follow the steps:

------
#### [ Console ]

**To view information about a knowledge base that's associated with an agent**

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](https://console.aws.amazon.com/bedrock).

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

1. Choose **Edit in Agent builder**

1. In the **Knowledge bases** section, select the knowledge base for which you want to view information.

------
#### [ API ]

To get information about a knowledge base associated with an agent, send a [GetAgentKnowledgeBase](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_GetAgentKnowledgeBase.html) request with an [Agents for Amazon Bedrock build-time endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt). Specify the following fields:

To list information about the knowledge bases associated with an agent, send a [ListAgentKnowledgeBases](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_ListAgentKnowledgeBases.html) request with an [Agents for Amazon Bedrock build-time endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt). Specify the `agentId` and `agentVersion` for which you want to see associated knowledge bases.


****  

| Field | Short description | 
| --- | --- | 
| maxResults | The maximum number of results to return in a response. | 
| nextToken | If there are more results than the number you specified in the maxResults field, the response returns a nextToken value. To see the next batch of results, send the nextToken value in another request. | 

[See code examples](https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-agent_example_bedrock-agent_ListAgentKnowledgeBases_section.html)

------

# Modify an agent-knowledge base association
<a name="agents-kb-edit"></a>

To learn how to modify an agent-knowledge base association, choose the tab for your preferred method, and then follow the steps:

------
#### [ Console ]

**To modify an agent-knowledge base association**

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](https://console.aws.amazon.com/bedrock).

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

1. Choose **Edit in Agent builder**

1. In the **Action groups** section, select an action group to edit. Then choose **Edit**.

1. Edit the existing fields as necessary. For more information, see [Augment response generation for your agent with knowledge base](agents-kb-add.md).

1. To control whether the agent can use the knowledge base, select **Enabled** or **Disabled**. Use this function to help troubleshoot your agent's behavior.

1. To remain in the same window so that you can test your change, choose **Save**. To return to the **Working draft** page, choose **Save and exit**.

1. To apply the changes that you made to the agent before testing it, choose **Prepare** in the **Test** window or at the top of the **Working draft** page.

------
#### [ API ]

To modify the configuration of a knowledge base associated with an agent, send an [UpdateAgentKnowledgeBase](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_UpdateAgentKnowledgeBase.html) request with an [Agents for Amazon Bedrock build-time endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt). Because all fields will be overwritten, include both fields that you want to update as well as fields that you want to keep the same. You must specify the `agentVersion` as `DRAFT`. For more information about required and optional fields, see [Augment response generation for your agent with knowledge base](agents-kb-add.md).

To apply the changes to the working draft, send a [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_PrepareAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_PrepareAgent.html) request with an [Agents for Amazon Bedrock build-time endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt). Include the `agentId` in the request. The changes apply to the `DRAFT` version, which the `TSTALIASID` alias points to.

------

# Disassociate a knowledge base from an agent
<a name="agents-kb-delete"></a>

To learn how to disassociate a knowledge base from an agent, choose the tab for your preferred method, and then follow the steps:

------
#### [ Console ]

**To disassociate a knowledge base from an agent**

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](https://console.aws.amazon.com/bedrock).

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

1. Choose **Edit in Agent builder**

1. In the **Knowledge bases** section, choose the option button that's next to the knowledge base that you want to delete. Then choose **Delete**.

1. Confirm the message that appears and then choose **Delete**.

1. To apply the changes that you made to the agent before testing it, choose **Prepare** in the **Test** window or at the top of the **Working draft** page.

------
#### [ API ]

To disassociate a knowledge base from an agent, send a [DisassociateAgentKnowledgeBase](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_DisassociateAgentKnowledgeBase.html) request with an [Agents for Amazon Bedrock build-time endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt). Specify the `knowledgeBaseId` and the `agentId` and `agentVersion` of the agent from which to disassociate it.

To apply the changes to the working draft, send a [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_PrepareAgent.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_PrepareAgent.html) request with an [Agents for Amazon Bedrock build-time endpoint](https://docs.aws.amazon.com/general/latest/gr/bedrock.html#bra-bt). Include the `agentId` in the request. The changes apply to the `DRAFT` version, which the `TSTALIASID` alias points to.

------