You need to enable JavaScript to run this app.
文档中心
对象存储

对象存储

复制全文
下载 pdf
向量索引
DeleteIndex(TOS Vectors Node.js SDK)
复制全文
下载 pdf
DeleteIndex(TOS Vectors Node.js SDK)
DeleteIndex 接口用于删除指定向量索引,本文介绍如何通过 TOS Vectors Node.js SDK 的 DeleteIndex 接口完成该操作。​
注意事项​
  • 为了防止密钥泄露,本文示例代码需要从环境变量中读取 Access Key ID 和 Secret Access Key。因此使用 SDK 前,您需要配置长期访问凭证,详细介绍,请参见配置长期访问凭证。​
  • TOS Vectors Node.js SDK 支持使用临时访问凭证;也支持配置超时机制、重试策略等多种机制,您可以根据业务需求灵活设置,提升应用安全性,详细介绍,请参见常见配置场景。​
权限说明​
主账号默认拥有全部权限,但是 IAM 用户默认没有任何权限。如果您需要使用 IAM 用户执行 DeleteIndex 操作,主账号需通过 IAM策略和桶策略为该 IAM 用户授予以下权限:tosvectors:DeleteIndex​
代码示例​
删除指定向量索引​
​
// 删除指定向量索引​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// 从环境变量中获取认证信息和配置​
const client = new TosVectorsClient({​
accessKeyId: process.env["TOS_ACCESS_KEY"] as string, // TOS_ACCESS_KEY: 您的 Access Key ID​
accessKeySecret: process.env["TOS_SECRET_KEY"] as string, // TOS_SECRET_KEY: 您的 Secret Key​
region: 'Provide your region',​
endpoint: 'Provide your vector endpoint',​
});​
​
// 从环境变量中读取向量桶名称、账号 ID 和待删除的索引名称​
const vectorBucketName = 'Provide your vector bucket name';​
const accountId = process.env["TOS_ACCOUNT_ID"];​
const indexName = "test";​
​
/**​
* 处理 SDK 调用过程中可能出现的错误。​
* @param error 捕获到的错误对象​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// 客户端异常,通常是参数错误或网络问题​
console.log("Client Error:");​
console.log(" Message:", error.message);​
if (error.stack) {​
console.log(" Stack:", error.stack);​
}​
} else if (error instanceof TosServerError) {​
// 服务端异常,表示请求已送达但处理失败​
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 {​
// 其他未知异常​
console.log("Unexpected Error:");​
console.log(" Message:", error.message);​
}​
}​
​
async function main() {​
try {​
// 1. 根据用例场景,准备 API 需要的参数。​
console.log(​
`开始删除向量索引: ${indexName},所属向量桶: ${vectorBucketName} ...`,​
);​
​
// 2. 调用 deleteIndex 方法删除指定的向量索引。​
const result = await client.deleteIndex({​
vectorBucketName,​
accountID: accountId,​
indexName,​
});​
​
// 3. 打印通用返回信息和业务数据。​
console.log("Request Succeeded:");​
console.log(" Request ID:", result.requestId);​
console.log(" Status Code:", result.statusCode);​
console.log(" Headers:", result.headers);​
​
// DeleteIndexOutput 当前为空对象,直接打印 Result Data 即可。​
console.log(" Result Data:", result.data);​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
​
最近更新时间:2026.08.03 11:05:44
这个页面对您有帮助吗?
有用
有用
无用
无用