벡터 목록 조회하기
벡터 목록 조회하기 (Listing vectors)
ListVectors API 작업으로 벡터 인덱스 안의 벡터를 나열할 수 있어요. 페이지당 반환되는 최대 벡터 수에 대한 자세한 내용은 제한 사항을 참고하세요. 결과가 잘리면 응답에 페이지네이션 토큰(pagination token)이 포함돼요. ListVectors의 응답 요소에 대한 자세한 내용은 Amazon S3 API Reference의 ListVectors를 참고하세요. ListVectors로 지정된 벡터 인덱스에서 벡터 데이터를 내보낼 수도 있어요.
ListVectors는 강력한 일관성(strongly consistent)을 제공해요. 쓰기(WRITE) 작업 후에는 모든 변경 사항이 반영된 상태로 벡터를 즉시 나열할 수 있어요.
벡터를 나열하려면 다음 예시 명령을 사용하세요. user input placeholders를 여러분의 정보로 바꿔주세요.
segment-count와 segment-index 파라미터는 목록 조회 작업을 여러 병렬 요청으로 나눌 수 있게 해줘요. segment-count 값(예: 2)을 지정하면 인덱스를 그만큼의 세그먼트로 나눠요. segment-index 파라미터(0부터 시작)는 어느 세그먼트를 나열할지 결정해요. 이 방식은 큰 벡터 인덱스를 나열할 때 병렬 처리를 가능하게 해 성능을 높여줘요. segment-count와 segment-index에 대한 자세한 내용은 Amazon S3 API Reference의 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"
}
}
]
}
Python SDK (Boto3)
예시: 벡터 인덱스의 벡터 나열하기
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)