You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Vector bucket
CreateVectorBucket(TOS Vectors Java SDK)
Copy page
Download PDF
CreateVectorBucket(TOS Vectors Java SDK)
The createVectorBucket API is used to create vector buckets. This article explains how to create vector buckets using the createVectorBucket API in the TOS Vectors Java SDK.​
Notes​
  • To prevent key leakage, the sample code in this article reads the Access Key ID and Secret Access Key from environment variables. Therefore, before using the SDK, you need to configure long-term access credentials. For details, see configure long-term access credentials.​
  • The TOS Vectors Java SDK supports using temporary access credentials and allows for flexible settings such as timeout mechanisms and retry policies to enhance application security based on business needs. For details, see common configuration scenarios.​
  • Anonymous requests to create buckets are not allowed, and a user can create up to 100 vector buckets (including normal buckets) globally.​
Permissions required​
The main account has all permissions by default, but IAM users have no permissions by default. If you need to perform the createVectorBucket operation using a sub-account, the primary account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:CreateVectorBucket​
Code example​
Create vector bucket​
​
// Create a vector storage bucket.​
import com.volcengine.tos.TOSVectorsClientBuilder;​
import com.volcengine.tos.TOSVectors;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.vectors.CreateVectorBucketInput;​
import com.volcengine.tos.model.vectors.CreateVectorBucketOutput;​
​
public class CreateVectorBucketExample {​
public static void main(String[] args) {​
String endpoint = 'Provide your endpoint';​
String region = 'Provide your region';​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY");​
​
// Fill in the vector bucket name.​
String vectorBucketName = 'Provide your bucket name';​
​
// Initialize client​
TOSVectors client = new TOSVectorsClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try {​
// Create a vector storage bucket. ​
// The bucket name must follow these rules:​
// 1. Be between 3 and 32 characters long​
// 2. Contain only lowercase letters, numbers, and hyphens (-)​
// 3. Cannot start or end with a hyphen (-)​
CreateVectorBucketInput input = CreateVectorBucketInput.builder()​
.vectorBucketName(vectorBucketName)​
.build();​
​
CreateVectorBucketOutput output = client.createVectorBucket(input);​
​
// Print the request result.​
System.out.println("Vector bucket created successfully");​
System.out.println("RequestID: " + output.getRequestInfo().getRequestId());​
System.out.println("StatusCode: " + output.getRequestInfo().getStatusCode());​
​
} catch (TosClientException e) {​
// Operation failed, caught Client exception. Generally, it is a request parameter error, and in this case, the request was not sent.​
System.out.println("Operation failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
// Operation failed, server exception captured, and detailed error information returned from the server can be obtained.​
System.out.println("Operation failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
// As a fallback to catch other exceptions, it generally won't execute here.​
System.out.println("Operation failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Related documentation​
For the API documentation of CreateVectorBucket, see CreateVectorBucket.​
Last updated: 2026.02.06 18:01:48