search_vectors
async
¶
search_vectors(
table_name: TableArn,
index_name: IndexName,
search_vector: SearchVectorList,
top_k: TopKInteger,
*,
config_overrides: Optional[AsyncDynamoDBClientConfig] = None,
return_consumed_capacity: Optional[ReturnConsumedCapacity] = None,
expression_attribute_names: Optional[ExpressionAttributeNameMap] = None,
expression_attribute_values: Optional[ExpressionAttributeValueMap] = None,
projection_expression: Optional[ProjectionExpression] = None,
search_condition_expression: Optional[String] = None,
) -> SearchVectorsOutput
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.
Parameters:
-
table_name(TableArn) –The name or Amazon Resource Name (ARN) of the table containing the vector index.
-
index_name(IndexName) –The name of the vector index to search. The index must be in the
ACTIVEstate. -
expression_attribute_names(Optional[ExpressionAttributeNameMap], default:None) –One or more substitution tokens for attribute names in an expression. Use the
#character in an expression to dereference an attribute name. -
expression_attribute_values(Optional[ExpressionAttributeValueMap], default:None) –One or more values that can be substituted in an expression. Use the
:character in an expression to dereference an attribute value. -
projection_expression(Optional[ProjectionExpression], default:None) –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.
-
search_vector(SearchVectorList) –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.
-
search_condition_expression(Optional[String], default:None) –A condition expression used to filter the vector search results. The expression can reference attributes defined in the vector index search schema, including
HASHandINLINE_FILTERkey elements.Only the equality operator (
=) is supported forHASHattributes. Comparison and range operators are supported forINLINE_FILTERattributes. Only top-level attributes from the search schema can be referenced. -
top_k(TopKInteger) –The number of most similar results to return.
Raises:
-
InternalServerError–An error occurred on the server side.
-
RequestLimitExceeded–Throughput exceeds the current throughput quota for your account. For detailed information about why the request was throttled and the ARN of the impacted resource, find the ThrottlingReason field in the returned exception. Contact Amazon Web Services Support to request a quota increase.
-
ResourceNotFoundException–The operation tried to access a nonexistent table or index. The resource might not be specified correctly, or its status might not be
ACTIVE. -
ThrottlingException–The request was denied due to request throttling. For detailed information about why the request was throttled and the ARN of the impacted resource, find the ThrottlingReason field in the returned exception.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To search for similar vectors 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.
>>> await client.search_vectors(table_name='Products', index_name='cosine-product-idx', search_vector=[{'N': '0.12'}, {'N': '0.85'}, {'N': '0.44'}, {'N': '0.67'}], top_k=3, search_condition_expression='Category = :cat', projection_expression='ProductName, Price', expression_attribute_values={':cat': {'S': 'Electronics'}}, return_consumed_capacity='INDEXES')
Source code in docs_src/capo_dynamodb/_services/async_dynamo_db.py
3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 | |