列示向量 - Amazon Simple Storage Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

列示向量

您可以使用 ListVectors API 操作列出向量索引中的向量。如需每一頁面可傳回之向量數上限的詳細資訊,請參閱 限制。當結果遭到截斷時,回應會包含分頁字符。如需 ListVectors 的回應元素的詳細資訊,請參閱《Amazon S3 API 參考》中的 ListVectors。您也可以使用 ListVectors 從指定的向量索引匯出向量資料。ListVectors 非常一致。WRITE 操作之後,您可以立即列出反映所有變更的向量。

若要列出向量,可使用下列範例命令。以您自己的資訊取代使用者輸入預留位置

segment-countsegment-index 參數可讓您將列示操作分割為多個平行請求。當您指定 segment-count 值 (例如 2) 時,可以將索引分割成多個區段。segment-index 參數 (從 0 開始) 決定要列出的區段。此方法可啟用平行處理,藉以協助改善列出大型向量索引的效能。如需 segment-countsegment-index 的詳細資訊,請參閱《Amazon S3 API 參考》中的 ListVectors

列出索引中的所有向量

範例請求:

aws s3vectors list-vectors \ --vector-bucket-name "amzn-s3-demo-vector-bucket" \ --index-name "idx" \ --segment-count 2 \ --segment-index 0 \ --return-data \ --return-metadata

回應範例:

{ "vectors": [ { "key": "vec3", "data": { "float32": [0.4000000059604645] }, "metadata": { "nonFilterableKey": "val4", "filterableKey": "val2" } } ] }

列出具有分頁的向量

範例請求:

aws s3vectors list-vectors \ --vector-bucket-name "amzn-s3-demo-vector-bucket" \ --index-name "idx" \ --segment-count 2 \ --segment-index 0 \ --return-data \ --return-metadata \ --next-token "zWfh7e57H2jBfBtRRmC7OfMwl209G9dg3j2qM6kM4t0rps6ClYzJykgMOil9eGqU5nhf_gTq53IfoUdTnsg"

回應範例:

{ "vectors": [ { "key": "vec1", "data": { "float32": [0.5] }, "metadata": { "nonFilterableKey": "val2", "filterableKey": "val1" } } ] }
SDK for Python

範例:列出向量索引中的向量

import boto3 # Create a S3 Vectors client in the AWS Region of your choice. s3vectors = boto3.client("s3vectors", region_name="us-west-2") #List vectors in your vector index response = s3vectors.list_vectors( vectorBucketName="media-embeddings", indexName="movies", maxResults = 600, returnData = True, returnMetadata = True ) vectors = response["vectors"] print(vectors)

範例:平行列出向量索引中的所有向量

import boto3 # Create a S3 Vectors client in the AWS Region of your choice. s3vectors = boto3.client("s3vectors", region_name="us-west-2") #List vectors in the 1st half of vectors in the index. response = s3vectors.list_vectors( vectorBucketName="media-embeddings", indexName="movies", segmentCount=2, segmentIndex=1, maxResults = 600, returnData = True, returnMetadata = True ) vectors = response["vectors"] #List vectors starting from the 2nd half of vectors in the index. # This can be ran in parallel with the first `list_vectors` call. response = s3vectors.list_vectors( vectorBucketName="media-embeddings", indexName="movies", segmentCount=2, segmentIndex=1, maxResults = 600, returnData = True, returnMetadata = True ) vectors = response["vectors"] print(vectors)