Call the GetVectorIndex operation through Go SDK V2 to retrieve information about a specified vector index.
Permissions
Alibaba Cloud accounts have full permissions by default. RAM users and RAM roles require explicit authorization through a RAM policy or a bucket policy.
|
API |
Action |
Description |
|
GetVectorIndex |
|
Retrieves 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, including the bucket name and the index name. For more information, see GetVectorIndexRequest. |
|
optFns |
...func(*Options) |
(Optional) Operation-level configuration parameters. For more information, see Options. |
Return values
|
Parameter |
Type |
Description |
|
result |
*GetVectorIndexResult |
The operation result. Valid only when err is nil. For more information, see GetVectorIndexResult. |
|
err |
error |
The error message. Returns nil on success. |
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(®ion, "region", "", "The region where the bucket is located.")
flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
flag.StringVar(&indexName, "index", "", "The name of the vector index.")
flag.StringVar(&accountId, "account-id", "", "The ID of the Alibaba Cloud 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).
// To access the service over a public endpoint, set this to false or remove this line.
WithUseInternalEndpoint(true)
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, see get_vector_index.go.