searchVectors
inline suspend fun DynamoDbClient.searchVectors(crossinline block: SearchVectorsRequest.Builder.() -> Unit): SearchVectorsResponse
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.
Samples
// This example searches the Products table for the top 3 items most similar to a provided vector,
// using the cosine product idx vector index. The SearchConditionExpression filters results to the
// Electronics category. The operation returns only the ProductName and Price attributes.
val resp = dynamoDbClient.searchVectors {
tableName = "Products"
indexName = "cosine-product-idx"
searchVector = listOf<AttributeValue>(
AttributeValue.N("0.12"),
AttributeValue.N("0.85"),
AttributeValue.N("0.44"),
AttributeValue.N("0.67")
)
topK = 3
searchConditionExpression = "Category = :cat"
projectionExpression = "ProductName, Price"
expressionAttributeValues = mapOf<String, AttributeValue>(
":cat" to AttributeValue.S("Electronics")
)
returnConsumedCapacity = ReturnConsumedCapacity.fromValue("INDEXES")
}Content copied to clipboard