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.The
HASHandINLINE_FILTERattributes support only the equality operator (=). You can reference only top-level attributes from the search schema. -
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
3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 | |