All Products
Search
Document Center

Object Storage Service:Delete a vector index (Python SDK V2)

Last Updated:Mar 20, 2026

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.

APIActionDescription
DeleteVectorIndexoss:DeleteVectorIndexDeletes a vector index.

Prerequisites

Before you begin, ensure that you have:

  • An OSS bucket with a vector index to delete

  • The oss:DeleteVectorIndex permission granted to your account or RAM user

  • The OSS Python SDK V2 installed

  • Your credentials set as environment variables

Delete a vector index

Warning

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}")
PlaceholderDescriptionExample
<region-id>Region where the bucket is locatedcn-hangzhou
<account-id>Your Alibaba Cloud account ID
<bucket-name>Name of the bucketmy-bucket
<index-name>Name of the vector index to deletemy-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:

ErrorCauseResolution
403 / AccessDeniedThe 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) → DeleteVectorIndexResult

Request parameters

ParameterTypeDescription
requestDeleteVectorIndexRequestSpecifies the bucket name and the name of the index to delete. See DeleteVectorIndexRequest.

Return values

TypeDescription
DeleteVectorIndexResultThe result object containing the status code and request ID. See DeleteVectorIndexResult.

For the complete method definition, see delete_vector_index.

References