@@ -188,7 +188,7 @@ def __init__(
188188 dialect : int = 2 ,
189189 sort_by : Optional [str ] = None ,
190190 in_order : bool = False ,
191- normalize_cosine_distance : bool = False ,
191+ normalize_vector_distance : bool = False ,
192192 ):
193193 """A query for running a vector search along with an optional filter
194194 expression.
@@ -214,9 +214,12 @@ def __init__(
214214 in_order (bool): Requires the terms in the field to have
215215 the same order as the terms in the query filter, regardless of
216216 the offsets between them. Defaults to False.
217- normalize_cosine_distance (bool): by default Redis returns cosine distance as a value
218- between 0 and 2 where 0 is the best match. If set to True, the cosine distance will be
219- converted to cosine similarity with a value between 0 and 1 where 1 is the best match.
217+ normalize_vector_distance (bool): Redis supports 3 distance metrics: L2 (euclidean),
218+ IP (inner product), and COSINE. By default, L2 distance returns an unbounded value.
219+ COSINE distance returns a value between 0 and 2. IP returns a value determined by
220+ the magnitude of the vector. Setting this flag to true converts COSINE and L2 distance
221+ to a similarity score between 0 and 1. Note: setting this flag to true for IP will
222+ throw a warning since by definition COSINE similarity is normalized IP.
220223
221224 Raises:
222225 TypeError: If filter_expression is not of type redisvl.query.FilterExpression
@@ -228,7 +231,7 @@ def __init__(
228231 self ._vector_field_name = vector_field_name
229232 self ._dtype = dtype
230233 self ._num_results = num_results
231- self ._normalize_cosine_distance = normalize_cosine_distance
234+ self ._normalize_vector_distance = normalize_vector_distance
232235 self .set_filter (filter_expression )
233236 query_string = self ._build_query_string ()
234237
@@ -289,7 +292,7 @@ def __init__(
289292 dialect : int = 2 ,
290293 sort_by : Optional [str ] = None ,
291294 in_order : bool = False ,
292- normalize_cosine_distance : bool = False ,
295+ normalize_vector_distance : bool = False ,
293296 ):
294297 """A query for running a filtered vector search based on semantic
295298 distance threshold.
@@ -318,9 +321,12 @@ def __init__(
318321 in_order (bool): Requires the terms in the field to have
319322 the same order as the terms in the query filter, regardless of
320323 the offsets between them. Defaults to False.
321- normalize_cosine_distance (bool): by default Redis returns cosine distance as a value
322- between 0 and 2 where 0 is the best match. If set to True, the cosine distance will be
323- converted to cosine similarity with a value between 0 and 1 where 1 is the best match.
324+ normalize_vector_distance (bool): Redis supports 3 distance metrics: L2 (euclidean),
325+ IP (inner product), and COSINE. By default, L2 distance returns an unbounded value.
326+ COSINE distance returns a value between 0 and 2. IP returns a value determined by
327+ the magnitude of the vector. Setting this flag to true converts COSINE and L2 distance
328+ to a similarity score between 0 and 1. Note: setting this flag to true for IP will
329+ throw a warning since by definition COSINE similarity is normalized IP.
324330
325331 Raises:
326332 TypeError: If filter_expression is not of type redisvl.query.FilterExpression
@@ -333,7 +339,7 @@ def __init__(
333339 self ._vector_field_name = vector_field_name
334340 self ._dtype = dtype
335341 self ._num_results = num_results
336- self ._normalize_cosine_distance = normalize_cosine_distance
342+ self ._normalize_vector_distance = normalize_vector_distance
337343 self .set_distance_threshold (distance_threshold )
338344 self .set_filter (filter_expression )
339345 query_string = self ._build_query_string ()
0 commit comments