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

Torch Object Storage

Copy page
Download PDF
Vector index
GetIndex(TOS Vectors Node.js SDK)
Copy page
Download PDF
GetIndex(TOS Vectors Node.js SDK)
The getIndex API retrieves information about a specified vector index. This article explains how to perform this operation using the getIndex API in the TOS Vectors Node.js SDK.​
Notes​
  • You need to fill in the region and access domain in the sample code according to your actual situation. For details, see regions and endpoints.​
  • 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, configure long-term access credentials. For details, see configure long-term access credentials.​
  • The TOS Vectors Node.js SDK supports temporary access credentials and allows configuration of timeout mechanisms, retry policies, and other settings. You can adjust these flexibly based on your business needs 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 a sub-account needs to perform the getIndex operation, the primary account must grant the following permissions to the sub-account via IAM policies and bucket policies:​
tosvectors:GetIndex​
Code example​
Retrieve information for the specified vector index​
​
// Retrieve information for the specified vector index​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// Get authentication and configuration from environment variables​
const client = new TosVectorsClient({​
accessKeyId: process.env["TOS_ACCESS_KEY"], // TOS_ACCESS_KEY: Your Access Key ID​
accessKeySecret: process.env["TOS_SECRET_KEY"], // TOS_SECRET_KEY: Your Secret Key​
region: 'Provide your region',​
endpoint: 'Provide your vector endpoint',​
});​
​
const vectorBucketName = 'Provide your vector bucket name';​
const accountId = process.env["TOS_ACCOUNT_ID"];​
const indexName = "example-index-1769428012143";​
​
/**​
* handle possible errors during sdk calls.​
*@paramerror the caught error object​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// client exceptions, usually parameter errors 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 exceptions, indicating the request was received but failed processing​
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 exceptions​
console.log("Unexpected Error:");​
console.log(" Message:", error.message);​
}​
}​
​
async function main() {​
try {​
console.log(​
`Getting information for index: ${indexName} in vector bucket: ${vectorBucketName}...`,​
);​
​
// 1. call getIndex method to get details of the specified vector index​
const result = await client.getIndex({​
vectorBucketName,​
accountID: accountId,​
indexName,​
});​
​
// 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. print core configuration fields of the index​
const index = result.data.index;​
console.log(" Index Info:");​
console.log(` - Index Name: ${index.indexName}`);​
console.log(` - Index TRN: ${index.indexTrn}`);​
console.log(` - Creation Time: ${index.creationTime}`);​
console.log(` - Data Type: ${index.dataType}`);​
console.log(` - Dimension: ${index.dimension}`);​
console.log(` - Distance Metric: ${index.distanceMetric}`);​
console.log(` - Vector Bucket Name: ${index.vectorBucketName}`);​
console.log(​
" - Non-filterable Metadata Keys:",​
index.metadataConfiguration.nonFilterableMetadataKeys,​
);​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
Related documentation​
For API documentation on GetIndex, see GetIndex.​
​
Last updated: 2026.02.06 18:01:45