All Products
Search
Document Center

Object Storage Service:List vector indexes (Go SDK V2)

Last Updated:Mar 20, 2026

Use the Go SDK V2 to call ListVectorIndexes and retrieve all vector indexes in a vector bucket. Results are returned via a paginator, so you can iterate through large index sets.

Permissions

By default, an Alibaba Cloud account has full permissions on its resources. Resource Access Management (RAM) users and RAM roles have no permissions by default. The account owner or an administrator must grant permissions via a RAM Policy or a Bucket Policy.

APIActionDescription
ListVectorIndexesoss:ListVectorIndexesLists vector indexes

Method definition

func (c *VectorsClient) ListVectorIndexes(ctx context.Context, request *ListVectorIndexesRequest, optFns ...func(*oss.Options)) (*ListVectorIndexesResult, error)

Parameters

ParameterTypeDescription
request*ListVectorIndexesRequestRequest parameters, including the bucket name. See ListVectorIndexesRequest.
optFns...func(*Options)(Optional) API-level configuration. See Options.

Return value

ParameterTypeDescription
result*ListVectorIndexesPaginatorThe paginator used to traverse the list of vector indexes. See ListVectorIndexesPaginator.

Call HasNext() and NextPage() on the paginator to iterate through pages of results. Use oss.ToString() to dereference string pointer fields and oss.ToTime() for time fields.

Sample code

Quick reference

The following snippet shows the core pagination pattern after the client is set up:

request := &vectors.ListVectorIndexesRequest{
    Bucket: oss.Ptr(bucketName),
}
p := client.NewListVectorIndexesPaginator(request)

for p.HasNext() {
    page, err := p.NextPage(context.TODO())
    if err != nil {
        log.Fatalf("failed to get page: %v", err)
    }
    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),
        )
    }
}

Complete example

The following example lists all vector indexes in a bucket. It accepts the region, bucket name, and account ID as command-line flags, and reads credentials from environment variables.

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(&region, "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 the vector 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)

	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)
		}

		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, see list_vector_indexes.go.