// Code generated by smithy-go-codegen DO NOT EDIT.

package dynamodb

import (
	"context"
	"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
	"github.com/aws/smithy-go/middleware"
	"github.com/aws/smithy-go/ptr"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

// Performs a vector similarity search on a vector index associated with an Amazon
// DynamoDB table, and returns the most similar items sorted by similarity score
// based on the distance function configured for the index.
//
// Score interpretation depends on the distance function:
//
//   - COSINE - Returns the items with the k smallest scores. Scores range from 0
//     (identical) to 2 (opposite). Lower scores indicate higher similarity.
//
//   - EUCLIDEAN - Returns the items with the k smallest scores. Scores represent
//     the Euclidean distance between vectors. Lower scores indicate higher similarity.
//
//   - DOT_PRODUCT - Returns the items with the k highest scores. Higher scores
//     indicate higher similarity.
func (c *Client) SearchVectors(ctx context.Context, params *SearchVectorsInput, optFns ...func(*Options)) (*SearchVectorsOutput, error) {
	if params == nil {
		params = &SearchVectorsInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "SearchVectors", params, optFns, c.addOperationSearchVectorsMiddlewares)
	if err != nil {
		return nil, err
	}

	out := result.(*SearchVectorsOutput)
	out.ResultMetadata = metadata
	return out, nil
}

type SearchVectorsInput struct {

	// The name of the vector index to search. The index must be in the ACTIVE state.
	//
	// This member is required.
	IndexName *string

	// The search vector to compare against the indexed vectors. Each element is a
	// 32-bit IEEE-754 floating point number, provided in DynamoDB list format.
	//
	// The number of dimensions must match the number of dimensions configured for the
	// vector index.
	//
	// This member is required.
	SearchVector []types.AttributeValue

	// The name or Amazon Resource Name (ARN) of the table containing the vector index.
	//
	// This member is required.
	TableName *string

	// The number of most similar results to return.
	//
	// This member is required.
	TopK *int32

	// One or more substitution tokens for attribute names in an expression. Use the #
	// character in an expression to dereference an attribute name.
	ExpressionAttributeNames map[string]string

	// One or more values that can be substituted in an expression. Use the :
	// character in an expression to dereference an attribute value.
	ExpressionAttributeValues map[string]types.AttributeValue

	// A string that identifies one or more attributes to retrieve from the index.
	// Separate attribute names with commas. If not specified, the operation returns
	// all attributes projected into the vector index.
	//
	// Only attributes projected into the vector index can be retrieved.
	ProjectionExpression *string

	// Determines the level of detail about either provisioned or on-demand throughput
	// consumption that is returned in the response:
	//
	//   - INDEXES - The response includes the aggregate ConsumedCapacity for the
	//   operation, together with ConsumedCapacity for each table and secondary index
	//   that was accessed.
	//
	// Note that some operations, such as GetItem and BatchGetItem , do not access any
	//   indexes at all. In these cases, specifying INDEXES will only return
	//   ConsumedCapacity information for table(s).
	//
	//   - TOTAL - The response includes only the aggregate ConsumedCapacity for the
	//   operation.
	//
	//   - NONE - No ConsumedCapacity details are included in the response.
	ReturnConsumedCapacity types.ReturnConsumedCapacity

	// A condition expression used to filter the vector search results. The expression
	// can reference attributes defined in the vector index search schema, including
	// HASH and INLINE_FILTER key elements.
	//
	// Only the equality operator ( = ) is supported for HASH attributes. Comparison
	// and range operators are supported for INLINE_FILTER attributes. Only top-level
	// attributes from the search schema can be referenced.
	SearchConditionExpression *string

	noSmithyDocumentSerde
}

func (in *SearchVectorsInput) bindEndpointParams(p *EndpointParameters) {

	p.ResourceArn = in.TableName
	p.IsSearchOperation = ptr.Bool(true)
}

type SearchVectorsOutput struct {

	// The capacity units consumed by the SearchVectors operation. Contains
	// VectorSearchRequestBytes , which represents the vector search capacity consumed.
	ConsumedCapacity *types.VectorCapacity

	// A list of items returned by the vector similarity search, sorted by similarity
	// with the most similar item first. Each item contains the projected attributes
	// and a similarity score.
	SearchResults []types.SearchResultItem

	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationSearchVectorsMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson10_serializeOpSearchVectors{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpSearchVectors{}, middleware.After)
	if err != nil {
		return err
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addComputeContentLength(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = addComputePayloadSHA256(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack, options); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addUserAgentAccountIDEndpointMode(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpSearchVectorsValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "SearchVectors"), middleware.Before); err != nil {
		return err
	}
	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = addValidateResponseChecksum(stack, options); err != nil {
		return err
	}
	if err = addAcceptEncodingGzip(stack, options); err != nil {
		return err
	}
	if err = addRequestResponseLogging(stack, options); err != nil {
		return err
	}
	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}
