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

Torch Object Storage

Copy page
Download PDF
Vector index
GetIndex(TOS Vectors Python SDK)
Copy page
Download PDF
GetIndex(TOS Vectors Python SDK)
The get_index API is used to query metadata and status of a specified vector index. This article explains how to obtain index configuration, dimensions, distance type, and creation time via the get_index API in the TOS Vectors Python 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 details, see Configure Long-Term Access Credentials.​
  • The TOS Vectors Python SDK supports using temporary access credentials and allows configuration of timeout mechanisms, retry policies, and other settings. You can flexibly adjust these to enhance application security according to business needs. For details, see Common Configuration Scenarios.​
Permissions required​
The primary account has all permissions by default, but IAM users do not have any permissions by default. If you need a sub-account to perform the get_index operation, the primary account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:GetIndex​
Code examples​
Get information for the specified vector index​
​
# Get information about the specified vector index.​
import os​
import tos​
​
# Retrieve AK and SK information from environment variables.​
ak = os.getenv('TOS_ACCESS_KEY')​
sk = os.getenv('TOS_SECRET_KEY')​
# Fill in your endpoint and your region with the endpoint corresponding to the bucket's region. # For example, for China (Beijing), set your endpoint to https://tosvectors-cn-beijing.volces.com and your region to cn-beijing.​
endpoint = 'Provide your endpoint'​
region = 'Provide your region'​
account_id = os.getenv('TOS_ACCOUNT_ID')​
vector_bucket_name = 'Provide your bucket name'​
​
try:​
# Create a VectorClient object; all vector operations are handled through VectorClient.​
client = tos.VectorClient(ak, sk, endpoint, region)​
​
# Specify the name of the vector index to be retrieved.​
index_name = 'examplevectorindex'​
​
# Get vector index information.​
result = client.get_index(​
vector_bucket_name=vector_bucket_name,​
account_id=account_id,​
index_name=index_name​
)​
​
# Print the request result.​
print('Obtained vector index information successfully')​
print('Request ID:', result.request_id)​
print('Status Code:', result.status_code)​
​
# Print index details.​
if result.index:​
print('\n Index details:')​
print('Index name:', result.index.index_name)​
print('Data type:', result.index.data_type)​
print('Vector dimension:', result.index.dimension)​
print('Distance measurement method:', result.index.distance_metric)​
print('Creation time:', result.index.creation_time)​
print('Index TRN:', result.index.index_trn)​
​
# Print metadata configuration information​
if result.index.metadata_configuration:​
print('Non-filterable metadata key:', result.index.metadata_configuration.non_filterable_metadata_keys)​
​
except tos.exceptions.TosClientError as e:​
# The operation failed and a client exception was caught. This is usually due to invalid request parameters or a network exception.​
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))​
except tos.exceptions.TosServerError as e:​
# The operation failed and a server exception occurred. See the response for the error details.​
print('fail with server error, code: {}'.format(e.code))​
# Use the request ID for troubleshooting purposes. We strongly recommend including the request ID in the logs.​
print('error with request id: {}'.format(e.request_id))​
print('error with message: {}'.format(e.message))​
print('error with http code: {}'.format(e.status_code))​
print('error with ec: {}'.format(e.ec))​
print('error with request url: {}'.format(e.request_url))​
except Exception as e:​
print('fail with unknown error: {}'.format(e))​
​
Related documentation​
For the API documentation of GetIndex, see GetIndex.​
Last updated: 2026.02.06 18:01:46