All Products
Search
Document Center

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

Last Updated:Jun 03, 2026

Call the DeleteVectorIndex operation with the Go SDK V2 to delete a specified vector index. This operation is irreversible. Use caution.

Permissions

An Alibaba Cloud account has all permissions by default. By default, Resource Access Management (RAM) users and RAM roles have no permissions. The Alibaba Cloud account or an administrator must grant the required permissions using a RAM policy overview or a bucket policy.

API

Action

Description

DeleteVectorIndex

oss:DeleteVectorIndex

Delete a vector index.

Method definition

func (c *VectorsClient) DeleteVectorIndex(ctx context.Context, request *DeleteVectorIndexRequest, optFns ...func(*oss.Options)) (*DeleteVectorIndexResult, error)

Request parameters

Parameter

Type

Description

ctx

context.Context

The request context.

request

*DeleteVectorIndexRequest

The request parameters. For more information, see DeleteVectorIndexRequest.

optFns

...func(*Options)

(Optional) The API-level configuration parameters.

For more information, see Options.

Return values

Parameter

Type

Description

result

*DeleteVectorIndexResult

The return value. This parameter is valid only when err is nil. For more information, see DeleteVectorIndexResult.

err

error

The error message. This parameter is nil if the operation is successful.

Sample code

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)

var (
	region     string
	bucketName string
	indexName  string
	accountId  string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the vector bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
	flag.StringVar(&indexName, "index", "", "The name of the vector index.")
	flag.StringVar(&accountId, "account-id", "", "The ID of the Alibaba Cloud account.")
}

func main() {
	flag.Parse()
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	if len(indexName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, index required")
	}

	if len(accountId) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, accountId required")
	}

	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId).
		// To access OSS over the Internet, set this to false or remove this line.
		WithUseInternalEndpoint(true)

	client := vectors.NewVectorsClient(cfg)

	request := &vectors.DeleteVectorIndexRequest{
		Bucket:    oss.Ptr(bucketName),
		IndexName: oss.Ptr(indexName),
	}
	result, err := client.DeleteVectorIndex(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to delete vector index %v", err)
	}

	log.Printf("delete vector index result:%#v\n", result)
}

References

For the complete sample code on deleting a vector index, see delete_vector_index.go.