使用Python SDK V2调用ListVectorIndexes接口列出指定向量存储桶中的所有向量索引。
权限说明
阿里云账号默认拥有全部权限。阿里云账号下的RAM用户或RAM角色默认没有任何权限,需要阿里云账号或账号管理员通过RAM Policy或Bucket Policy授予操作权限。
API | Action | 说明 |
ListVectorIndexes |
| 列举向量索引。 |
方法定义
Python SDK V2提供了两种方式列举向量索引:
list_vector_indexes()
:直接调用接口,需要手动处理分页。list_vector_indexes_paginator()
:使用分页器,SDK会自动处理分页逻辑,推荐使用。
# 直接调用
list_vector_indexes(request: ListVectorIndexesRequest, **kwargs) → ListVectorIndexesResult
请求参数列表
参数名 | 类型 | 说明 |
request | ListVectorIndexesRequest | 设置请求参数,具体请参见ListVectorIndexesRequest |
返回值列表
类型 | 说明 |
ListVectorIndexesResult | 返回值,具体请参见ListVectorIndexesResult |
关于列举向量索引方法的完整定义,请参见list_vector_indexes。
# 使用分页器
list_vector_indexes_paginator(**kwargs) → ListVectorIndexesPaginator[source]
返回值列表
类型 | 说明 |
ListVectorIndexesPaginator | 返回值,具体请参见ListVectorIndexesPaginator |
关于使用分页器列举向量索引方法的完整定义,请参见list_vector_indexes_paginator。
示例代码
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()
相关文档
关于列出向量索引的完整示例代码,请参见list_vector_indexes.py。
该文章对您有帮助吗?