Bir vektör paketinde vektör dizini oluşturmak için Go SDK V2 kullanarak PutVectorIndex işlemine çağrı yapın.
İzinler
Varsayılan olarak Alibaba Cloud hesapları tüm izinlere sahipken, Resource Access Management (RAM) kullanıcıları ve RAM rolleri herhangi bir izne sahip değildir. Alibaba Cloud hesabı veya bir yönetici, bir RAM ilkesi veya paket ilkesi aracılığıyla izinleri vermelidir.
|
|
|
|
|
|
|
|
Yöntem tanımı
func (c *VectorsClient) PutVectorIndex(ctx context.Context, request *PutVectorIndexRequest, optFns ...func(*oss.Options)) (*PutVectorIndexResult, error)
İstek parametreleri
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(İsteğe bağlı) İşlem düzeyindeki yapılandırma parametreleri. Daha fazla bilgi için bkz. Options. |
Dönüş değerleri
|
|
|
|
|
|
|
|
|
|
|
|
Örnek kod
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
indexName 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 the Alibaba Cloud account.")
flag.StringVar(&indexName, "index", "", "The name of the vector index.")
}
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(accountId) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, accountId required")
}
if len(indexName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, index 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.PutVectorIndexRequest{
Bucket: oss.Ptr(bucketName),
DataType: oss.Ptr("float32"),
Dimension: oss.Ptr(128),
DistanceMetric: oss.Ptr("cosine"),
IndexName: oss.Ptr(indexName),
Metadata: map[string]any{
"nonFilterableMetadataKeys": []string{"foo", "bar"},
},
}
result, err := client.PutVectorIndex(context.TODO(), request)
if err != nil {
log.Fatalf("failed to put vector index: %v", err)
}
log.Printf("put vector index result: %#v\n", result)
}
Başvurular
Vektör dizini oluşturmaya ilişkin tam örnek kod için bkz. put_vector_index.go.