Use the ListVectors operation to retrieve all vectors stored in a vector index. This is useful for data auditing, incremental synchronization, and bulk export of vector data. Paging is supported to traverse large datasets.
The Python SDK V2 provides two methods:
list_vectors_paginator()— the SDK handles paging automatically. Use this method in most cases.list_vectors()— returns one page at a time; you manage paging manually.
Permissions
Alibaba Cloud accounts have full permissions by default. Resource Access Management (RAM) users and RAM roles have no permissions by default. An Alibaba Cloud account owner or administrator must grant the required permissions through a RAM policy or a bucket policy.
| API | Action | Description |
|---|---|---|
| ListVectors | oss:ListVectors | Lists vector data. |
Method definitions
list_vectors_paginator() — recommended
list_vectors_paginator(**kwargs) → ListVectorsPaginatorReturns a ListVectorsPaginator object. Call iter_page(request) on it to iterate through all pages — the SDK handles continuation tokens automatically.
For the complete method definition, see list_vectors_paginator.
list_vectors() — manual paging
list_vectors(request: ListVectorsRequest, **kwargs) → ListVectorsResult| Parameter | Type | Description |
|---|---|---|
| request | ListVectorsRequest | Request parameters. See ListVectorsRequest. |
Returns a ListVectorsResult object containing the current page of vectors. For more information, see list_vectors.
Sample code
Use list_vectors_paginator() to iterate through all vectors without managing pagination tokens.
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()
# Load credentials from environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use 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 — the SDK handles continuation tokens automatically
paginator = client.list_vectors_paginator()
request = oss_vectors.models.ListVectorsRequest(
bucket=args.bucket,
index_name=args.index_name
)
# Iterate through all pages; the loop ends when no more vectors remain
for page in paginator.iter_page(request):
for vector in page.vectors:
print(f'Vector: {vector}')
if __name__ == "__main__":
main()References
For the complete sample code, see list_vectors.py.