Use the Python SDK V2 to permanently delete a vector index from a bucket. This operation calls the DeleteVectorIndex API and cannot be undone.
Permissions
By default, an Alibaba Cloud account has full permissions. Resource Access Management (RAM) users and RAM roles have no permissions by default and must be granted access through a RAM policy or a bucket policy.
| API | Action | Description |
|---|---|---|
| DeleteVectorIndex | oss:DeleteVectorIndex | Deletes a vector index. |
Prerequisites
Before you begin, ensure that you have:
An OSS bucket with a vector index to delete
The
oss:DeleteVectorIndexpermission granted to your account or RAM userThe OSS Python SDK V2 installed
Your credentials set as environment variables
Delete a vector index
Deleting a vector index is irreversible. All index data is permanently removed and cannot be recovered. Verify the index name before proceeding.
Minimal example
The following snippet shows the core call. Replace <bucket-name> and <index-name> with your actual values.
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
cfg = oss.config.load_default()
cfg.credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg.region = "<region-id>"
cfg.account_id = "<account-id>"
vector_client = oss_vectors.Client(cfg)
result = vector_client.delete_vector_index(
oss_vectors.models.DeleteVectorIndexRequest(
bucket="<bucket-name>",
index_name="<index-name>",
)
)
print(f"Status code: {result.status_code}, Request ID: {result.request_id}")| Placeholder | Description | Example |
|---|---|---|
<region-id> | Region where the bucket is located | cn-hangzhou |
<account-id> | Your Alibaba Cloud account ID | — |
<bucket-name> | Name of the bucket | my-bucket |
<index-name> | Name of the vector index to delete | my-vector-index |
Full runnable example
The following script accepts command-line arguments and serves as a standalone reference implementation.
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
parser = argparse.ArgumentParser(description="vector delete vector index sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
parser.add_argument('--account_id', help='The account id.', required=True)
def main():
args = parser.parse_args()
# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
cfg.account_id = args.account_id
if args.endpoint is not None:
cfg.endpoint = args.endpoint
vector_client = oss_vectors.Client(cfg)
result = vector_client.delete_vector_index(oss_vectors.models.DeleteVectorIndexRequest(
bucket=args.bucket,
index_name=args.index_name,
))
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
)
if __name__ == "__main__":
main()Run the script:
python delete_vector_index.py \
--region cn-hangzhou \
--bucket <bucket-name> \
--index_name <index-name> \
--account_id <account-id>If the deletion fails, check the following:
| Error | Cause | Resolution |
|---|---|---|
403 / AccessDenied | The account or RAM user lacks the oss:DeleteVectorIndex permission. | Add oss:DeleteVectorIndex to the RAM policy or bucket policy for your account. |
Method reference
delete_vector_index(request: DeleteVectorIndexRequest, **kwargs) → DeleteVectorIndexResultRequest parameters
| Parameter | Type | Description |
|---|---|---|
request | DeleteVectorIndexRequest | Specifies the bucket name and the name of the index to delete. See DeleteVectorIndexRequest. |
Return values
| Type | Description |
|---|---|
DeleteVectorIndexResult | The result object containing the status code and request ID. See DeleteVectorIndexResult. |
For the complete method definition, see delete_vector_index.
References
Complete sample code: delete_vector_index.py