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 set to 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.
To resolve this error, complete one or more of the resolutions.
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.
Complete the following steps:
- Open the Amazon Bedrock console.
- In the navigation pane, under Build, choose Knowledge Bases.
- Find the knowledge base with the Delete unsuccessful status.
- Select the data source name for that knowledge base.
- Choose Edit.
- Expand Advanced settings, set the Data deletion policy to Retain.
- Choose Submit.
- Delete the data source.
- Delete the knowledge base.
You can also run the 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 '{"s3Configuration":{"bucketArn":"arn:aws:s3:::<S3_Bucket_Name>"},"type":"S3"}' --vector-ingestion-configuration '{"parsingConfiguration":{"bedrockFoundationModelConfiguration":{"modelArn":"arn:aws:bedrock:region: account-id:inference-profile/model_id"},"parsingStrategy":"BEDROCK_FOUNDATION_MODEL"}}' --data-deletion-policy "RETAIN"
Note: Replace the following values:
- region-name with your AWS Region
- your-data-source-id with your data source id
- your-knowledge-base-id with your knowledge base id
- your-knowledge-base-name with your knowledge base name
- region with your Region
- account-id with your AWS account id
- model_id with your Amazon Bedrock model id
Grant the IAM role permissions to delete data
To resolve your permission issues, take one of the following actions based on the service that you use for the vector store:
-
For Amazon OpenSearch Serverless, update the data access policy with the permissions to delete.
-
For Amazon Aurora PostgreSQL-Compatible Edition, run one of the following SQL commands 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.
-or-
Run the following code:
GRANT SELECT, DELETE ON example-schema-name. example-table-name TO example-username;
Note: Replace example-schema-name with the schema name, example-table-name with the table name, and example-username with the primary user.
-
For third-party databases, make sure that you have the required permissions for data deletion.