A vector bucket is a container that stores vector indexes and vector data. To create a vector bucket, you can call the PutVectorBucket operation using the Go SDK V2.
Permissions
Alibaba Cloud accounts have all permissions by default. In contrast, Resource Access Management (RAM) users and RAM roles have no permissions by default. An Alibaba Cloud account or an administrator must grant operation permissions using a RAM policy or a bucket policy.
API | Action | Description |
PutVectorBucket |
| Creates a vector bucket. The name of a vector bucket must be unique for a user ID (UID) within the same region. The name must be 3 to 32 characters long and can contain only lowercase letters, digits, and hyphens (-). The name cannot start or end with a hyphen. |
Method definition
func (c *VectorsClient) PutVectorBucket(ctx context.Context, request *PutVectorBucketRequest, optFns ...func(*Options)) (*PutVectorBucketResult, error)Request parameters
Parameter | Type | Description |
ctx | context.Context | The request context. |
request | *PutVectorBucketRequest | The request parameters. For more information, see PutVectorBucketRequest. |
optFns | ...func(*Options) | (Optional) The operation-level configuration parameters. For more information, see Options. |
Return values
Return value | Type | Description |
result | *PutVectorBucketResult | The return value of the operation. This parameter is valid only when err is nil. For more information, see PutVectorBucketResult. |
err | error | The status of the request. If the request fails, err is not nil. |
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 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(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.PutVectorBucketRequest{
Bucket: oss.Ptr(bucketName),
}
result, err := client.PutVectorBucket(context.TODO(), request)
if err != nil {
log.Fatalf("failed to put vector bucket %v", err)
}
log.Printf("put vector bucket result:%#v\n", result)
}References
For the complete sample code for creating a vector bucket, see put_vector_bucket.go.