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

Torch Object Storage

Copy page
Download PDF
Vector index
ListIndexes(TOS Vectors Python SDK)
Copy page
Download PDF
ListIndexes(TOS Vectors Python SDK)
The list_indexes interface is used to list created vector indexes. This article explains how to obtain the index list through the list_indexes interface of TOS Vectors Python SDK, returning index names, dimensions, and creation times.​
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, you need to configure long-term access credentials. For details, see configure long-term access credentials.​
  • TOS Vectors Python SDK supports using temporary access credentials and configuring timeout and retry policies. You can flexibly set these based on business needs to enhance application security. For details, see common configuration scenarios.​
Permissions required​
The main account has all permissions by default, while IAM users have no permissions by default. If a sub-account needs to perform the list_indexes operation, the main account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:ListIndexes​
Code example​
List basic usage of vector indexes​
​
# List the basic usage of vector indexes​
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)​
​
# List all indexes in the specified vector storage bucket.​
result = client.list_indexes(​
vector_bucket_name=vector_bucket_name, # Vector bucket name​
account_id=account_id # Account ID​
)​
​
# Print basic information of the request​
print(f'Request ID: {result.request_id}')​
print(f'Status Code: {result.status_code}')​
print(f'Indexes Count: {len(result.indexes)}')​
​
# Traverse and print index information.​
if result.indexes:​
print('\nIndex Details:')​
for index in result.indexes:​
print(f' Index Name: {index.index_name}')​
print(f' Index TRN: {index.index_trn}')​
print(f' Vector Bucket: {index.vector_bucket_name}')​
print(f' Creation Time: {index.creation_time}')​
​
# If there is a pagination token, it indicates that there are more indexes.​
if result.next_token:​
print(f'\nNext Token: {result.next_token}')​
print('Note: There are more indexes available. Use next_token for pagination.')​
​
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 ListIndexes, see ListIndexes.​
Last updated: 2026.02.06 18:01:46