Skip to content

/AWS1/CL_S3V=>QUERYVECTORS()

About QueryVectors

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.

Method Signature

IMPORTING

Required arguments:

iv_topk TYPE /AWS1/S3VTOPK /AWS1/S3VTOPK

The number of results to return for each query.

io_queryvector TYPE REF TO /AWS1/CL_S3VVECTORDATA /AWS1/CL_S3VVECTORDATA

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.

Optional arguments:

iv_vectorbucketname TYPE /AWS1/S3VVECTORBUCKETNAME /AWS1/S3VVECTORBUCKETNAME

The name of the vector bucket that contains the vector index.

iv_indexname TYPE /AWS1/S3VINDEXNAME /AWS1/S3VINDEXNAME

The name of the vector index that you want to query.

iv_indexarn TYPE /AWS1/S3VINDEXARN /AWS1/S3VINDEXARN

The ARN of the vector index that you want to query.

io_filter TYPE REF TO /AWS1/CL_RT_DOCUMENT /AWS1/CL_RT_DOCUMENT

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

iv_returnmetadata TYPE /AWS1/S3VBOOLEAN /AWS1/S3VBOOLEAN

Indicates whether to include metadata in the response. The default value is false.

iv_returndistance TYPE /AWS1/S3VBOOLEAN /AWS1/S3VBOOLEAN

Indicates whether to include the computed distance in the response. The default value is false.

RETURNING

oo_output TYPE REF TO /aws1/cl_s3vqueryvectorsoutput /AWS1/CL_S3VQUERYVECTORSOUTPUT

Domain /AWS1/RT_ACCOUNT_ID
Primitive Type NUMC

Examples

Syntax Example

This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.

DATA(lo_result) = lo_client->/aws1/if_s3v~queryvectors(
  io_filter = /AWS1/CL_RT_DOCUMENT=>FROM_JSON_STR( |\{"foo":"this is a JSON object..."\}| )
  io_queryvector = new /aws1/cl_s3vvectordata(
    it_float32 = VALUE /aws1/cl_s3vfloat32vectordat00=>tt_float32vectordata(
      ( new /aws1/cl_s3vfloat32vectordat00( |0.1| ) )
    )
  )
  iv_indexarn = |string|
  iv_indexname = |string|
  iv_returndistance = ABAP_TRUE
  iv_returnmetadata = ABAP_TRUE
  iv_topk = 123
  iv_vectorbucketname = |string|
).

This is an example of reading all possible response values

lo_result = lo_result.
IF lo_result IS NOT INITIAL.
  LOOP AT lo_result->get_vectors( ) into lo_row.
    lo_row_1 = lo_row.
    IF lo_row_1 IS NOT INITIAL.
      lv_vectorkey = lo_row_1->get_key( ).
      lo_vectordata = lo_row_1->get_data( ).
      IF lo_vectordata IS NOT INITIAL.
        LOOP AT lo_vectordata->get_float32( ) into lo_row_2.
          lo_row_3 = lo_row_2.
          IF lo_row_3 IS NOT INITIAL.
            lv_float = lo_row_3->get_value( ).
          ENDIF.
        ENDLOOP.
      ENDIF.
      lo_value = lo_row_1->get_metadata( ).
      IF lo_value IS NOT INITIAL.
      ENDIF.
      lv_float = lo_row_1->get_distance( ).
    ENDIF.
  ENDLOOP.
ENDIF.