Python SDK V2 を使用して ListVectorIndexes 操作を呼び出し、指定されたベクターバケット内のすべてのベクターインデックスをリストできます。
権限
デフォルトでは、Alibaba Cloud アカウントはすべての権限を持っています。デフォルトでは、Alibaba Cloud アカウント下の Resource Access Management (RAM) ユーザーまたは RAM ロールには権限がありません。Alibaba Cloud アカウントの所有者または管理者は、RAM ポリシーまたはバケットポリシーを使用して権限を付与する必要があります。
API | アクション | 説明 |
ListVectorIndexes |
| ベクターインデックスをリストします。 |
メソッド定義
Python SDK V2 は、ベクターインデックスをリストするための 2 つのメソッドを提供します:
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」をご参照ください。
# ページネーターを使用
list_vector_indexes_paginator(**kwargs) → ListVectorIndexesPaginator[source]戻り値
タイプ | 説明 |
ListVectorIndexesPaginator | 戻り値。詳細については、「ListVectorIndexesPaginator」をご参照ください。 |
list_vector_indexes_paginator メソッドの完全な定義については、「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()
# 環境変数から認証情報値を読み込みます
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# SDK のデフォルト設定を使用します
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)
# ListVectorIndex 操作の Paginator を作成します
paginator = client.list_vector_indexes_paginator()
# ベクターインデックスページを反復処理します
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」をご参照ください。