使用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。