I tried to delete the Amazon Bedrock knowledge base and received the "Failed to delete knowledge base" error.
Short description
When you create a knowledge base, the default dataDeletionPolicy is Delete. If you delete the data source that's associated with the knowledge base, then the policy deletes all the data but doesn't delete the vector store. If you set the dataDeletionPolicy to Retain, then the policy retains all the data if you delete your data source.
When you delete an Amazon Bedrock knowledge base, you might receive the following error:
"Failed to delete example-knowledge-base. Unable to delete data from vector store for data source with example-id. Check your vector store configurations and permissions and retry your request. If the issue persists, consider updating the dataDeletionPolicy of the data source to RETAIN and retry your request."
This error occurs because of the following reasons:
- The vector store doesn't exist or you previously deleted it.
- The knowledge base execution role doesn't have AWS Identity and Access Management (IAM) permissions to delete the data that's stored in the vector store.
- The knowledge base service role doesn't have the required permissions to operate specific database APIs.
Resolution
Confirm that the associated vector store exists
Complete the following steps:
- Open the Amazon OpenSearch Service console.
- In the navigation pane, expand Serverless and choose Collections.
- In the search bar, enter the collection associated with the knowledge base. If the collection isn't available, then you already deleted the vector store.
Set the data deletion policy to Retain
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
To set the data deletion policy to Retain with the AWS Management Console, complete the following steps:
- Open the Amazon Bedrock console.
- In the navigation pane, under Build, choose Knowledge Bases.
- Select the knowledge base with the Delete unsuccessful status.
- Choose the data source name for that knowledge base.
- In Data source, select the data source name, and then choose Edit.
- Expand Advanced settings, set the Data deletion policy to Retain.
- Choose Submit.
- Delete the data source.
- Delete the knowledge base.
To set the data deletion policy to Retain with the AWS CLI, complete the following steps:
-
Run the following get-data-source AWS CLI command to retrieve the current data source configuration:
aws bedrock-agent get-data-source --region region-name --data-source-id your-data-source-id --knowledge-base-id your-knowledge-base-id
Note: Replace region-name with your AWS Region, your-data-source-id with your data source id, and your-knowledge-base-id with your knowledge base id.
-
Run the following update-data-source AWS CLI command to change the data source deletion policy:
aws bedrock-agent update-data-source \
--region region-name \
--data-source-id your-data-source-id \
--knowledge-base-id your-knowledge-base-id \
--name "your-knowledge-base-name" \
--data-source-configuration 'COPY FROM get-data-source RESULT' \
--data-deletion-policy "RETAIN"
Note: Replace region-name with your Region, your-data-source-id with your data source id, your-knowledge-base-id with your knowledge base id, and your-knowledge-base-name with your knowledge base name.
(Optional) Update your vector store permissions
If you want to keep the deletion policy set to Delete and remove the indexed data from your vector store, then complete the following steps:
-
For Amazon OpenSearch Serverless, update the data access policy with the permissions to delete.
-
For Amazon Aurora PostgreSQL-Compatible Edition, run the following SQL command to grant permission to the primary user:
GRANT pg_read_all_data, pg_write_all_data TO example-username;
Note: Replace example-username with the primary username.