获取向量 Index 信息(Python SDK V2)

使用Python SDK V2调用GetVectorIndex接口获取指定向量索引的信息。

权限说明

阿里云账号默认拥有全部权限。阿里云账号下的RAM用户或RAM角色默认没有任何权限,需要阿里云账号或账号管理员通过RAM PolicyBucket Policy授予操作权限。

API

Action

说明

GetVectorIndex

oss:GetVectorIndex

获取向量索引信息。

方法定义

get_vector_index(request: GetVectorIndexRequest, **kwargs) → GetVectorIndexResult

请求参数列表

参数名

类型

说明

request

GetVectorIndexRequest

设置请求参数,包括要查询的存储桶名称和索引名称等,具体请参见GetVectorIndexRequest

返回值列表

类型

说明

GetVectorIndexResult

返回值,包含向量索引的详细信息,具体请参见GetVectorIndexResult

关于获取向量Index方法的完整定义,请参见get_vector_index

示例代码

import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors

parser = argparse.ArgumentParser(description="vector get vector index sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
parser.add_argument('--account_id', help='The account id.', 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

    vector_client = oss_vectors.Client(cfg)

    result = vector_client.get_vector_index(oss_vectors.models.GetVectorIndexRequest(
        bucket=args.bucket,
        index_name=args.index_name,
    ))

    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          )

    if result.index:
        print(f'index name: {result.index}')

if __name__ == "__main__":
    main()

相关文档

关于获取向量索引信息的完整示例代码,请参见get_vector_index.py