queryVectors method

Future<QueryVectorsOutput> queryVectors({
  1. required VectorData queryVector,
  2. required int topK,
  3. Document? filter,
  4. String? indexArn,
  5. String? indexName,
  6. bool? returnDistance,
  7. bool? returnMetadata,
  8. String? vectorBucketName,
})

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.

May throw KmsDisabledException. May throw KmsInvalidKeyUsageException. May throw KmsInvalidStateException. May throw KmsNotFoundException. May throw NotFoundException. May throw ServiceUnavailableException.

Parameter queryVector : 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.

Parameter topK : The number of results to return for each query.

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

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

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

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

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

Parameter vectorBucketName : The name of the vector bucket that contains the vector index.

Implementation

Future<QueryVectorsOutput> queryVectors({
  required VectorData queryVector,
  required int topK,
  Document? filter,
  String? indexArn,
  String? indexName,
  bool? returnDistance,
  bool? returnMetadata,
  String? vectorBucketName,
}) async {
  _s.validateNumRange(
    'topK',
    topK,
    1,
    1152921504606846976,
    isRequired: true,
  );
  final $payload = <String, dynamic>{
    'queryVector': queryVector,
    'topK': topK,
    if (filter != null) 'filter': filter,
    if (indexArn != null) 'indexArn': indexArn,
    if (indexName != null) 'indexName': indexName,
    if (returnDistance != null) 'returnDistance': returnDistance,
    if (returnMetadata != null) 'returnMetadata': returnMetadata,
    if (vectorBucketName != null) 'vectorBucketName': vectorBucketName,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/QueryVectors',
    exceptionFnMap: _exceptionFns,
  );
  return QueryVectorsOutput.fromJson(response);
}