All Products
Search
Document Center

Object Storage Service:Create a vector bucket (Go SDK V2)

Last Updated:Jun 03, 2026

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

By default, an Alibaba Cloud account has all permissions. A Resource Access Management (RAM) user or RAM role has no permissions by default. The Alibaba Cloud account owner or an administrator must grant permissions using a RAM policy or a bucket policy.

API

Action

Description

PutVectorBucket

oss:PutVectorBucket

Creates a vector bucket. The name of a vector bucket must be unique for a UID within the same region. The name must be 3 to 32 characters in length. It 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(&region, "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 account ID.")
}

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).
		// To use a public endpoint, set this parameter to false or remove this line.
		WithUseInternalEndpoint(true)

	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.