You can use Python SDK V2 to call the ListVectorIndexes operation to list all vector indexes in a specified vector bucket.
Permissions
An Alibaba Cloud account has full permissions to access all API operations. By default, RAM users and RAM roles cannot call this operation. You must create and attach a RAM policy or a bucket policy to grant the required permissions.
|
API |
Action |
Description |
|
ListVectorIndexes |
|
Lists vector indexes. |
Method definition
Python SDK V2 provides two methods to list vector indexes:
-
list_vector_indexes(): Calls the operation directly. You must manually handle paging. -
list_vector_indexes_paginator(): Uses a paginator. The software development kit (SDK) automatically handles the paging logic. This method is recommended.
# Call directly
list_vector_indexes(request: ListVectorIndexesRequest, **kwargs) → ListVectorIndexesResult
Request parameters
|
Parameter |
Type |
Description |
|
request |
ListVectorIndexesRequest |
The request parameters. For more information, see ListVectorIndexesRequest |
Return values
|
Type |
Description |
|
ListVectorIndexesResult |
The return value. For more information, see ListVectorIndexesResult |
For the complete definition of the list_vector_indexes method, see list_vector_indexes.
# Use a paginator
list_vector_indexes_paginator(**kwargs) → ListVectorIndexesPaginator[source]
Return values
|
Type |
Description |
|
ListVectorIndexesPaginator |
The return value. For more information, see ListVectorIndexesPaginator |
For the complete definition of the list_vector_indexes_paginator method, see list_vector_indexes_paginator.
Sample code
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
parser = argparse.ArgumentParser(description="list vector indexes sample")
parser.add_argument('--region', help='The region where the bucket is located.', required=True)
parser.add_argument('--endpoint', help='The OSS access endpoint.')
parser.add_argument('--account_id', help='The account ID.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
def main():
args = parser.parse_args()
# Load credential values from environment variables.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use the SDK's default configuration.
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
cfg.account_id = args.account_id
cfg.use_internal_endpoint = True # To connect over the public network, set this to False or remove this line.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_vectors.Client(cfg)
# Create the paginator for the ListVectorIndexes operation.
paginator = client.list_vector_indexes_paginator()
# Iterate through the pages of vector indexes.
for page in paginator.iter_page(oss_vectors.models.ListVectorIndexesRequest(
bucket=args.bucket
)
):
for o in page.indexes:
print(f'Index: {o.get("indexName")}, {o.get("dataType")}, {o.get("dimension")}, {o.get("status")}')
if __name__ == "__main__":
main()
References
For the complete sample code for listing vector indexes, see list_vector_indexes.py.