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

Torch Object Storage

Copy page
Download PDF
Vector
DeleteVectors(TOS Vectors Node.js SDK)
Copy page
Download PDF
DeleteVectors(TOS Vectors Node.js SDK)
deleteVectors interface is used for batch deleting vectors. This article explains how to perform this operation using the deleteVectors interface of the TOS Vectors Node.js 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 detailed instructions, see Configuring Long-Term Access Credentials.​
  • The TOS Vectors Node.js SDK supports using temporary access credentials; it also supports various mechanisms such as timeout settings and retry policies. You can flexibly configure these according to your business needs to enhance application security. For detailed instructions, see Common Configuration Scenarios.​
Permissions required​
The main account has all permissions by default, but IAM users have no permissions by default. If you need to use a sub-account to perform the deleteVectors operation, the main account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:DeleteVectors​
Code example​
Batch delete vectors​
​
// Batch delete vectors​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// Retrieve authentication and configuration from environment variables​
const client = new TosVectorsClient({​
accessKeyId: process.env["TOS_ACCESS_KEY"] as string, // TOS_ACCESS_KEY: your Access Key ID​
accessKeySecret: process.env["TOS_SECRET_KEY"] as string, // TOS_SECRET_KEY: your Secret Key​
region: 'Provide your region',​
endpoint: 'Provide your vector endpoint',​
});​
​
// Read vector bucket name and account ID from environment variables​
const vectorBucketName = 'Provide your vector bucket name';​
const accountId = process.env["TOS_ACCOUNT_ID"];​
const indexName = "test";​
​
/**​
* Handle potential errors during SDK calls.​
*@paramerror The caught error object​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// Client error, usually due to parameter issues or network problems​
console.log("Client Error:");​
console.log(" Message:", error.message);​
if (error.stack) {​
console.log(" Stack:", error.stack);​
}​
} else if (error instanceof TosServerError){​
// Server error, indicating the request was received but failed to process​
console.log("Server Error:");​
console.log(" Request ID:", error.requestId);​
console.log(" Status Code:", error.statusCode);​
console.log(" Code:", error.code);​
console.log(" Message:", error.message);​
console.log(" Headers:", error.headers);​
} else {​
// Other unknown errors​
console.log("Unexpected Error:");​
console.log(" Message:", error.message);​
}​
}​
​
async function main() {​
// List of vector keys to delete; the example uses three placeholder keys—replace with actual business vector keys​
const keys = ["key1", "key2", "key3"];​
​
try {​
console.log(​
`Starting batch deletion of vectors, vector bucket: ${vectorBucketName}, index: ${indexName}, number of keys to be deleted: ${keys.length}...`,​
);​
​
// 1. Call the deleteVectors method to batch delete vectors by the specified keys​
const result = await client.deleteVectors({​
vectorBucketName,​
accountID: accountId,​
indexName,​
keys,​
});​
​
// 2. print general return information​
console.log("Request Succeeded:");​
console.log(" Request ID:", result.requestId);​
console.log(" Status Code:", result.statusCode);​
console.log(" Headers:", result.headers);​
​
// 3. DeleteVectorsOutput is currently an empty object but still prints Result Data for debugging and future interface extensions​
console.log(" Result Data:", result.data);​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
Related documentation​
For API documentation on DeleteVectors, see DeleteVectors.​
​
Last updated: 2026.02.06 18:01:45