You can use the Go SDK V2 to call the ListVectorIndexes operation to list all vector indexes in a specified vector bucket.
Permissions
An Alibaba Cloud account has full permissions to access all API operations. By default, RAM users and RAM roles cannot call this operation. You must create and attach a RAM policy or a bucket policy to grant the required permissions.
|
API |
Action |
Description |
|
ListVectorIndexes |
|
Lists vector indexes. |
Method definition
func (c *VectorsClient) ListVectorIndexes(ctx context.Context, request *ListVectorIndexesRequest, optFns ...func(*oss.Options)) (*ListVectorIndexesResult, error)
Request parameters
|
Parameter |
Type |
Description |
|
params |
*ListVectorIndexesRequest |
The request parameters, such as the bucket name. For more information, see ListVectorIndexesRequest. |
|
optFns |
...func(*Options) |
(Optional) The API-level configuration parameters. For more information, see Options. |
Return values
|
Parameter |
Type |
Description |
|
result |
*ListVectorIndexesPaginator |
The paginator used to traverse the list of vector indexes. For more information, see ListVectorIndexesPaginator. |
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() {
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 ID of your Alibaba Cloud account.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket 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 the service over the public internet, set this parameter to false or remove this line.
WithUseInternalEndpoint(true)
client := vectors.NewVectorsClient(cfg)
request := &vectors.ListVectorIndexesRequest{
Bucket: oss.Ptr(bucketName),
}
p := client.NewListVectorIndexesPaginator(request)
var i int
log.Println("Vector Indexes:")
for p.HasNext() {
i++
page, err := p.NextPage(context.TODO())
if err != nil {
log.Fatalf("failed to get page %v, %v", i, err)
}
// Log the found indexes.
for _, index := range page.Indexes {
log.Printf("index:%v, %v, %v, %v\n", oss.ToString(index.IndexName), oss.ToTime(index.CreateTime), oss.ToString(index.DataType), oss.ToString(index.Status))
}
}
}
References
For the complete sample code for listing vector indexes, see list_vector_indexes.go.