A vector bucket stores vector indexes and vector data. Use the PutVectorBucket operation in the OSS Go SDK V2 to create one.
Prerequisites
Before you begin, ensure that you have:
Go SDK V2 installed
An Alibaba Cloud account, or a Resource Access Management (RAM) user or RAM role with the
oss:PutVectorBucketpermissionA region ID and account ID for the vector bucket
Permissions
Alibaba Cloud accounts have all permissions by default. RAM users and RAM roles have no permissions by default. An Alibaba Cloud account or an administrator must grant the required permissions using a RAM policy or a bucket policy.
| API | Action | Description |
|---|---|---|
| PutVectorBucket | oss:PutVectorBucket | Creates a vector bucket. |
Naming rules
Vector bucket names must meet the following requirements:
Unique for a user ID (UID) within the same region
3 to 32 characters long
Contain only lowercase letters, digits, and hyphens (-)
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) Operation-level configuration parameters. For more information, see Options. |
Return values
| Return value | Type | Description |
|---|---|---|
| result | *PutVectorBucketResult | The return value of the operation. Valid only when err is nil. For more information, see PutVectorBucketResult. |
| err | error | The request status. If the request fails, err is not nil. |
Sample code
The following example creates a vector bucket by:
Loading credentials from environment variables using
NewEnvironmentVariableCredentialsProviderInitializing a
VectorsClientwith the target region and account IDCalling
PutVectorBucketwith the bucket name
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, see put_vector_bucket.go.