S3Vectors / Client / query_vectors

query_vectors

S3Vectors.Client.query_vectors(**kwargs)

Note

Amazon S3 Vectors is in preview release for Amazon S3 and is subject to change.

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), the vector data, 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 vector data or 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, vector data, or metadata without the s3vectors:GetVectors permission.

See also: AWS API Documentation

Request Syntax

response = client.query_vectors(
    vectorBucketName='string',
    indexName='string',
    indexArn='string',
    topK=123,
    queryVector={
        'float32': [
            ...,
        ]
    },
    filter={...}|[...]|123|123.4|'string'|True|None,
    returnMetadata=True|False,
    returnDistance=True|False
)
Parameters:
  • 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 (dict) –

    [REQUIRED]

    The query vector. Ensure that the query vector has the same dimension as the dimension of the vector index that’s being queried. For example, if your vector index contains vectors with 384 dimensions, your query vector must also have 384 dimensions.

    Note

    This is a Tagged Union structure. Only one of the following top level keys can be set: float32.

    • float32 (list) –

      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.

      • (float) –

  • filter (document) – Metadata filter to apply during the query. For more information about metadata keys, see Metadata filtering in the Amazon S3 User Guide.

  • returnMetadata (boolean) – Indicates whether to include metadata in the response. The default value is false.

  • returnDistance (boolean) – Indicates whether to include the computed distance in the response. The default value is false.

Return type:

dict

Returns:

Response Syntax

{
    'vectors': [
        {
            'key': 'string',
            'data': {
                'float32': [
                    ...,
                ]
            },
            'metadata': {...}|[...]|123|123.4|'string'|True|None,
            'distance': ...
        },
    ]
}

Response Structure

  • (dict) –

    • vectors (list) –

      The vectors in the approximate nearest neighbor search.

      • (dict) –

        Note

        Amazon S3 Vectors is in preview release for Amazon S3 and is subject to change.

        The attributes of a vector in the approximate nearest neighbor search.

        • key (string) –

          The key of the vector in the approximate nearest neighbor search.

        • data (dict) –

          The vector data associated with the vector, if requested.

          Note

          This is a Tagged Union structure. Only one of the following top level keys will be set: float32. If a client receives an unknown member it will set SDK_UNKNOWN_MEMBER as the top level key, which maps to the name or tag of the unknown member. The structure of SDK_UNKNOWN_MEMBER is as follows:

          'SDK_UNKNOWN_MEMBER': {'name': 'UnknownMemberName'}
          
          • float32 (list) –

            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.

            • (float) –

        • metadata (document) –

          The metadata associated with the vector, if requested.

        • distance (float) –

          The measure of similarity between the vector in the response and the query vector.

Exceptions