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

Torch Object Storage

Copy page
Download PDF
Vector index
DeleteIndex(TOS Vectors Node.js SDK)
Copy page
Download PDF
DeleteIndex(TOS Vectors Node.js SDK)
The deleteIndex API deletes a specified vector index. This article explains how to perform this operation using the deleteIndex API of the TOS Vectors Node.js 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, configure long-term access credentials. For details, see Configure Long-Term Access Credentials.​
  • TOS Vectors Node.js SDK supports temporary access credentials. It also supports timeout settings, retry policies, and other mechanisms. You can configure these flexibly to enhance application security. For details, see Common Configuration Scenarios.​
Permissions required​
The primary account has all permissions by default, but IAM users have no permissions by default. If you need a sub-account to execute the deleteIndex operation, the primary account must grant the sub-account the following permissions via IAM policies and bucket policies:​
tosvectors:DeleteIndex​
Code example​
Delete the specified vector index​
​
// Delete the specified vector index​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// Obtain authentication info 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, account ID, and the index name to delete from environment variables​
const vectorBucketName = 'Provide your vector bucket name';​
const accountId = process.env["TOS_ACCOUNT_ID"];​
const indexName = "test";​
​
/**​
* handle errors that may occur during sdk calls.​
*@paramerror the caught error object​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// client-side error, usually caused by invalid parameters or network issues​
console.log("Client Error:");​
console.log(" Message:", error.message);​
if (error.stack) {​
console.log(" Stack:", error.stack);​
}​
} else if (error instanceof TosServerError){​
// server-side 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() {​
try {​
// 1. Prepare the parameters required by the API based on the use case scenario.​
console.log(​
`Starting to delete vector index: ${indexName}, belonging to vector bucket: ${vectorBucketName} ...`,​
);​
​
// 2. Call the deleteIndex method to remove the specified vector index.​
const result = await client.deleteIndex({​
vectorBucketName,​
accountID: accountId,​
indexName,​
});​
​
// 3. Print the general return information and business data.​
console.log("Request Succeeded:");​
console.log(" Request ID:", result.requestId);​
console.log(" Status Code:", result.statusCode);​
console.log(" Headers:", result.headers);​
​
// DeleteIndexOutput is currently an empty object, print Result Data directly.​
console.log(" Result Data:", result.data);​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
Related documentation​
For the API documentation on DeleteIndex, see DeleteIndex.​
​
Last updated: 2026.02.06 18:01:45