Call the DeleteVectors operation using the Go SDK V2 to delete vector data based on specified keys. This is an irreversible operation, so proceed with caution.
Permissions
An Alibaba Cloud account has all permissions by default. A Resource Access Management (RAM) user or RAM role has no permissions by default. The Alibaba Cloud account or an administrator must grant permissions using a RAM policy or a bucket policy.
|
API |
Action |
Description |
|
DeleteVectors |
|
Deletes vector data. |
Method definition
func (c *VectorsClient) DeleteVectors(ctx context.Context, request *DeleteVectorsRequest, optFns ...func(*oss.Options)) (*DeleteVectorsResult, error)
Request parameters
|
Parameter |
Type |
Description |
|
ctx |
context.Context |
The request context. |
|
request |
*DeleteVectorsRequest |
The request parameters. These include the bucket name, index name, and a list of vector keys. For more information, see DeleteVectorsRequest. |
|
optFns |
...func(*Options) |
(Optional) The operation-level configuration parameters. For more information, see Options. |
Return values
|
Parameter |
Type |
Description |
|
result |
*DeleteVectorsResult |
The return value. For more information, see DeleteVectorsResult. |
|
err |
error |
The error message. This 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
accountId string
)
func init() {
// Define command-line parameters.
flag.StringVar(®ion, "region", "", "The region in which the vector bucket is located.")
flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
flag.StringVar(&accountId, "account-id", "", "The Alibaba Cloud account ID.")
}
func main() {
// Parse command-line parameters.
flag.Parse()
// Verify required parameters.
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(accountId) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, accountId required")
}
// Create a configuration and set the credential provider, region, and account ID.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region).
WithAccountId(accountId).
// To enable public access, set this to false or remove this line.
WithUseInternalEndpoint(true)
// Create a Vectors client.
client := vectors.NewVectorsClient(cfg)
// Build the request to delete vector data.
request := &vectors.DeleteVectorsRequest{
Bucket: oss.Ptr(bucketName),
IndexName: oss.Ptr("index"),
Keys: [ ]string{
"key1", "key2", // A list of vector keys to delete.
},
}
// Execute the operation to delete vector data.
result, err := client.DeleteVectors(context.TODO(), request)
if err != nil {
log.Fatalf("failed to delete vectors %v", err)
}
// Print the operation result.
log.Printf("delete vectors result:%#v\n", result)
}
References
For the complete sample code for deleting vector data, see delete_vectors.go.