@@ -198,7 +198,7 @@ def __init__(
198198 in_order : bool = False ,
199199 hybrid_policy : Optional [str ] = None ,
200200 batch_size : Optional [int ] = None ,
201- normalize_cosine_distance : bool = False ,
201+ normalize_vector_distance : bool = False ,
202202 ):
203203 """A query for running a vector search along with an optional filter
204204 expression.
@@ -234,9 +234,12 @@ def __init__(
234234 of vectors to fetch in each batch. Larger values may improve performance
235235 at the cost of memory usage. Only applies when hybrid_policy="BATCHES".
236236 Defaults to None, which lets Redis auto-select an appropriate batch size.
237- normalize_cosine_distance (bool): by default Redis returns cosine distance as a value
238- between 0 and 2 where 0 is the best match. If set to True, the cosine distance will be
239- converted to cosine similarity with a value between 0 and 1 where 1 is the best match.
237+ normalize_vector_distance (bool): Redis supports 3 distance metrics: L2 (euclidean),
238+ IP (inner product), and COSINE. By default, L2 distance returns an unbounded value.
239+ COSINE distance returns a value between 0 and 2. IP returns a value determined by
240+ the magnitude of the vector. Setting this flag to true converts COSINE and L2 distance
241+ to a similarity score between 0 and 1. Note: setting this flag to true for IP will
242+ throw a warning since by definition COSINE similarity is normalized IP.
240243
241244 Raises:
242245 TypeError: If filter_expression is not of type redisvl.query.FilterExpression
@@ -250,7 +253,7 @@ def __init__(
250253 self ._num_results = num_results
251254 self ._hybrid_policy : Optional [HybridPolicy ] = None
252255 self ._batch_size : Optional [int ] = None
253- self ._normalize_cosine_distance = normalize_cosine_distance
256+ self ._normalize_vector_distance = normalize_vector_distance
254257 self .set_filter (filter_expression )
255258 query_string = self ._build_query_string ()
256259
@@ -399,7 +402,7 @@ def __init__(
399402 in_order : bool = False ,
400403 hybrid_policy : Optional [str ] = None ,
401404 batch_size : Optional [int ] = None ,
402- normalize_cosine_distance : bool = False ,
405+ normalize_vector_distance : bool = False ,
403406 ):
404407 """A query for running a filtered vector search based on semantic
405408 distance threshold.
@@ -443,9 +446,12 @@ def __init__(
443446 of vectors to fetch in each batch. Larger values may improve performance
444447 at the cost of memory usage. Only applies when hybrid_policy="BATCHES".
445448 Defaults to None, which lets Redis auto-select an appropriate batch size.
446- normalize_cosine_distance (bool): by default Redis returns cosine distance as a value
447- between 0 and 2 where 0 is the best match. If set to True, the cosine distance will be
448- converted to cosine similarity with a value between 0 and 1 where 1 is the best match.
449+ normalize_vector_distance (bool): Redis supports 3 distance metrics: L2 (euclidean),
450+ IP (inner product), and COSINE. By default, L2 distance returns an unbounded value.
451+ COSINE distance returns a value between 0 and 2. IP returns a value determined by
452+ the magnitude of the vector. Setting this flag to true converts COSINE and L2 distance
453+ to a similarity score between 0 and 1. Note: setting this flag to true for IP will
454+ throw a warning since by definition COSINE similarity is normalized IP.
449455
450456 Raises:
451457 TypeError: If filter_expression is not of type redisvl.query.FilterExpression
@@ -472,7 +478,7 @@ def __init__(
472478 if batch_size is not None :
473479 self .set_batch_size (batch_size )
474480
475- self ._normalize_cosine_distance = normalize_cosine_distance
481+ self ._normalize_vector_distance = normalize_vector_distance
476482 self .set_distance_threshold (distance_threshold )
477483 self .set_filter (filter_expression )
478484 query_string = self ._build_query_string ()
0 commit comments