All Products
Search
Document Center

Object Storage Service:Get vector index information (Go SDK V2)

Last Updated:Sep 24, 2025

Use the Go SDK V2 to call the GetVectorIndex operation and retrieve information about a specified vector index.

Permissions

An Alibaba Cloud account has all permissions by default. By contrast, Resource Access Management (RAM) users and RAM roles have 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

GetVectorIndex

oss:GetVectorIndex

Gets vector index information.

Method definition

func (c *VectorsClient) GetVectorIndex(ctx context.Context, request *GetVectorIndexRequest, optFns ...func(*oss.Options)) (*GetVectorIndexResult, error) 

Request parameters

Parameter

Type

Description

ctx

context.Context

The request context.

request

*GetVectorIndexRequest

The request parameters. These include the name of the bucket to query and the index name. For more information, see GetVectorIndexRequest.

optFns

...func(*Options)

(Optional) The interface-level configuration parameters.

For more information, see Options.

Return values

Parameter

Type

Description

result

*GetVectorIndexResult

The return value. This is valid when err is nil. For more information, see GetVectorIndexResult.

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

	client := vectors.NewVectorsClient(cfg)

	request := &vectors.GetVectorIndexRequest{
		Bucket:    oss.Ptr(bucketName),
		IndexName: oss.Ptr(indexName),
	}
	result, err := client.GetVectorIndex(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to get vector index %v", err)
	}
	log.Printf("get vector index result:%#v\n", result)
}

References

For the complete sample code for retrieving vector index information, see get_vector_index.go.