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

Torch Object Storage

Copy page
Download PDF
Vector
DeleteVectors(TOS Vectors Java SDK)
Copy page
Download PDF
DeleteVectors(TOS Vectors Java SDK)
The deleteVectors interface is used to delete specified vectors. This article explains how to delete vectors using the deleteVectors interface of the TOS Vectors Java SDK.​
Notes​
  • To prevent key leakage, the sample code 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; it also supports timeout settings, retry strategies, and other mechanisms. You can configure these flexibly based on your business needs to enhance application security. For details, see Common Configuration Scenarios.​
Permissions required​
The root account has full permissions by default, but IAM users have no permissions by default. If you need a sub-account to perform the deleteVectors operation, the root account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:DeleteVectors​
Code examples​
Batch delete vectors​
​
// Batch delete vectors.​
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.DeleteVectorsInput;​
import com.volcengine.tos.model.vectors.DeleteVectorsOutput;​
​
import java.util.Arrays;​
​
public class DeleteVectorsExample {​
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");​
String accountID = System.getenv("TOS_ACCOUNT_ID");​
​
// Fill in BucketName.​
String bucketName = 'Provide your bucket name';​
​
// Initialize client.​
TOSVectors client = new TOSVectorsClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try {​
// Create batch delete vector input parameters.​
DeleteVectorsInput input = new DeleteVectorsInput()​
.setVectorBucketName(bucketName)​
.setAccountId(accountID)​
.setIndexName("testindex") // Set the name of the vector collection.​
.setKeys(Arrays.asList("product-vector-001", "product-vector-002", "product-vector-003")); // Set the list of vector IDs to be deleted.​
​
// Call the batch delete vector API.​
DeleteVectorsOutput output = client.deleteVectors(input);​
​
// Process the return result.​
System.out.println("Batch delete vectors successfully");​
System.out.println("RequestID: " + output.getRequestInfo().getRequestId());​
​
} 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 DeleteVectors, see DeleteVectors.​
Last updated: 2026.02.06 18:01:47