Use the Go SDK V2 to delete a specified vector index from a bucket. This operation is irreversible.
Prerequisites
Before you begin, ensure that you have:
A vector bucket with at least one vector index to delete
The
oss:DeleteVectorIndexpermission granted to your Alibaba Cloud account, RAM user, or RAM role via a RAM policy or a bucket policy
An Alibaba Cloud account has full permissions by default. RAM users and RAM roles have no permissions by default and must be granted the required permissions explicitly.
Method definition
func (c *VectorsClient) DeleteVectorIndex(ctx context.Context, request *DeleteVectorIndexRequest, optFns ...func(*oss.Options)) (*DeleteVectorIndexResult, error)Parameters
| Parameter | Type | Description |
|---|---|---|
| ctx | context.Context | The request context. |
| request | *DeleteVectorIndexRequest | The request parameters. For details, see DeleteVectorIndexRequest. |
| optFns | ...func(*Options) | (Optional) API-level configuration parameters. For details, see Options. |
Return values
| Value | Type | Description |
|---|---|---|
| result | *DeleteVectorIndexResult | The result object. Valid only when err is nil. For details, see DeleteVectorIndexResult. |
| err | error | The error. nil if the operation succeeds. |
Sample code
The following example deletes a vector index named my-index from a bucket. Credentials are loaded from environment variables.
package main
import (
"context"
"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"
)
func main() {
// Load credentials from environment variables:
// OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion("<region>").
WithAccountId("<account-id>")
client := vectors.NewVectorsClient(cfg)
request := &vectors.DeleteVectorIndexRequest{
Bucket: oss.Ptr("<bucket-name>"),
IndexName: oss.Ptr("<index-name>"),
}
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)
}Replace the following placeholders with your actual values:
| Placeholder | Description |
|---|---|
<region> | The region where the vector bucket is located, for example, cn-hangzhou. |
<account-id> | The ID of the vector account. |
<bucket-name> | The name of the vector bucket. |
<index-name> | The name of the vector index to delete. |
Deleting a vector index is irreversible. Verify the index name before running this operation.
References
For the complete sample code, see delete_vector_index.go.