Use ListVectorIndexes to retrieve all vector indexes in a vector bucket. The operation returns each index's name, data type, dimension, and status.
Permissions
Alibaba Cloud accounts have full permissions by default. Resource Access Management (RAM) users and RAM roles have no permissions by default and must be granted access via a RAM policy or a bucket policy before calling this operation.
| API | Action | Description |
|---|---|---|
| ListVectorIndexes | oss:ListVectorIndexes | Lists all vector indexes in a vector bucket |
Methods
Python SDK V2 provides two ways to list vector indexes. Use the paginator—it handles paging automatically.
list_vector_indexes_paginator() (recommended)
list_vector_indexes_paginator(**kwargs) → ListVectorIndexesPaginatorReturns a ListVectorIndexesPaginator that iterates through all pages automatically.
For the complete method definition, see list_vector_indexes_paginator.
list_vector_indexes()
list_vector_indexes(request: ListVectorIndexesRequest, **kwargs) → ListVectorIndexesResultCalls the operation directly. You must handle paging manually.
| Parameter | Type | Required | Description |
|---|---|---|---|
request | ListVectorIndexesRequest | Yes | Specifies the target bucket. Set the bucket field to the name of the vector bucket to query. |
For the complete method definition, see list_vector_indexes.
Request type reference: ListVectorIndexesRequest
Return type reference: ListVectorIndexesResult
Sample code
The following example uses list_vector_indexes_paginator() to iterate through all indexes in a bucket and print their key attributes.
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 in which the bucket is located.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
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()
# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using 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
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_vectors.Client(cfg)
# Create the Paginator for the ListVectorIndex operation
paginator = client.list_vector_indexes_paginator()
# Iterate through the vector index pages
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()Each index in page.indexes includes the following fields:
| Field | Description |
|---|---|
indexName | The name of the vector index |
dataType | The data type of the vectors |
dimension | The number of dimensions in each vector |
status | The current status of the index |
To retrieve only index names, use this condensed form:
for page in paginator.iter_page(oss_vectors.models.ListVectorIndexesRequest(bucket=args.bucket)):
for o in page.indexes:
print(o.get("indexName"))References
For the complete sample code, see list_vector_indexes.py.