Call the ListVectors operation using the Python SDK V2 to list all vectors in a specified vector index. Paging is supported to traverse large amounts of vector data.
Permissions
By default, an Alibaba Cloud account has all permissions, while its associated RAM users and RAM roles have none. The Alibaba Cloud account or an administrator must grant them permissions by using a RAM policy or a bucket policy.
|
API |
Actions |
Description |
|
ListVectors |
|
Lists vector data. |
Method definition
The Python SDK V2 provides two methods to list vector data:
-
list_vectors(): Directly calls the operation. You must handle paging manually. -
list_vectors_paginator(): Uses a paginator. The SDK automatically handles the paging logic. This method is recommended.
list_vectors(request: ListVectorsRequest, **kwargs) → ListVectorsResult[source]
Request parameters
|
Parameter |
Type |
Description |
|
request |
ListVectorsRequest |
Sets the request parameters. For more information, see ListVectorsRequest. |
Return values
|
Type |
Description |
|
ListVectorsResult |
The return value. For more information, see ListVectorsResult. |
For the complete definition of the method to list vectors, see list_vectors.
# Use a paginator
list_vectors_paginator(**kwargs) → ListVectorsPaginator[source]
Return values
|
Type |
Description |
|
ListVectorsPaginator |
The return value. For more information, see ListVectorsPaginator. |
For the complete definition of the method to list vectors using a paginator, see list_vectors_paginator.
Sample code
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
parser = argparse.ArgumentParser(description="list vectors 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)
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
def main():
args = parser.parse_args()
# Loading credentials 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
cfg.use_internal_endpoint = True # Set this to False or remove this line to access the service over the public network.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss_vectors.Client(cfg)
# Create a paginator for the ListVectors operation
paginator = client.list_vectors_paginator()
# Create a request with the bucket and index name
request = oss_vectors.models.ListVectorsRequest(
bucket=args.bucket,
index_name=args.index_name
)
# Iterate through the pages of vectors
for page in paginator.iter_page(request):
for o in page.vectors:
print(f'Vector: {o}')
if __name__ == "__main__":
main()
References
For the complete sample code for listing vectors, see list_vectors.py.