---
title: "POST /QueryVectors"
method: POST
path: "/QueryVectors"
---

# POST /QueryVectors

`POST /QueryVectors`

Performs an approximate nearest neighbor search query in a vector index using a query vector. By default, it returns the keys of approximate nearest neighbors. You can optionally include the computed distance (between the query vector and each vector in the response) and metadata of each vector in the response.

To specify the vector index, you can either use both the vector bucket name and the vector index name, or use the vector index Amazon Resource Name (ARN).

Permissions

You must have the `s3vectors:QueryVectors` permission to use this operation. Additional permissions are required based on the request parameters you specify:

*   With only `s3vectors:QueryVectors` permission, you can retrieve vector keys of approximate nearest neighbors and computed distances between these vectors. This permission is sufficient only when you don't set any metadata filters and don't request metadata (by keeping the `returnMetadata` parameter set to `false` or not specified).
    
*   If you specify a metadata filter or set `returnMetadata` to true, you must have both `s3vectors:QueryVectors` and `s3vectors:GetVectors` permissions. The request fails with a `403 Forbidden error` if you request metadata filtering or metadata without the `s3vectors:GetVectors` permission.

## Request body

- object
  - `vectorBucketName` string — The name of the vector bucket that contains the vector index.
  - `indexName` string — The name of the vector index that you want to query.
  - `indexArn` string — The ARN of the vector index that you want to query.
  - `topK` integer, required — The number of results to return for each query.
  - `queryVector` object, required — The vector data in different formats.
    - `float32` Float[] — The vector data as 32-bit floating point numbers. The number of elements in this array must exactly match the dimension of the vector index where the operation is being performed.
  - `filter` object — Metadata filter to apply during the query. For more information about metadata keys, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-metadata-filtering.html">Metadata filtering</a> in the <i>Amazon S3 User Guide</i>.
  - `returnMetadata` boolean — Indicates whether to include metadata in the response. The default value is <code>false</code>.
  - `returnDistance` boolean — Indicates whether to include the computed distance in the response. The default value is <code>false</code>.
  - `nextToken` string — Pagination token from a previous request. The value of this field is empty for an initial request.

## Response `200`

Success

- QueryVectorsOutput
  - `vectors` QueryOutputVector[], required — The vectors in the approximate nearest neighbor search.
    - `distance` number, float — The measure of similarity between the vector in the response and the query vector.
    - `key` string, required — The key of the vector in the approximate nearest neighbor search.
    - `metadata` object — The metadata associated with the vector, if requested.
  - `distanceMetric` 'euclidean' | 'cosine', required — The distance metric that was used for the similarity search calculation. This is the same distance metric that was configured for the vector index when it was created.
  - `nextToken` string — Pagination token to be used in the subsequent page request. The field is empty if no further pagination is required.

## Other responses

- `480` — ValidationException
- `481` — ServiceUnavailableException
- `482` — TooManyRequestsException
- `483` — KmsInvalidKeyUsageException
- `484` — InternalServerException
- `485` — KmsInvalidStateException
- `486` — AccessDeniedException
- `487` — KmsNotFoundException
- `488` — RequestTimeoutException
- `489` — NotFoundException
- `490` — KmsDisabledException

---

[API](https://skmtc.net/aws/apis/s3vectors.md) · [All operations](https://skmtc.net/aws/apis/s3vectors/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/aws/s3vectors/versions/dc31037cd75b/schema)
