Skip to content

Commit 967ba00

Browse files
booleanhunternkanu17
authored andcommitted
fix(query)!: Remove epsilon parameter from VectorQuery (#612)
EPSILON is a VECTOR_RANGE-only attribute. So when emitted inside the KNN bracket, Redis responds with: ``` ResponseError: Error parsing vector similarity parameters: range query attributes were sent for a non-range query ``` - Remove epsilon kwarg, set_epsilon() method, and epsilon property - Remove EPSILON emission from _build_query_string and params Does not impact VectorRangeQuery
1 parent 0787571 commit 967ba00

2 files changed

Lines changed: 0 additions & 90 deletions

File tree

redisvl/query/query.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ class BaseVectorQuery:
421421
# HNSW runtime parameters
422422
EF_RUNTIME: str = "EF_RUNTIME"
423423
EF_RUNTIME_PARAM: str = "EF"
424-
EPSILON_PARAM: str = "EPSILON"
425424

426425
# SVS-VAMANA runtime parameters
427426
SEARCH_WINDOW_SIZE: str = "SEARCH_WINDOW_SIZE"
@@ -457,7 +456,6 @@ def __init__(
457456
hybrid_policy: str | None = None,
458457
batch_size: int | None = None,
459458
ef_runtime: int | None = None,
460-
epsilon: float | None = None,
461459
search_window_size: int | None = None,
462460
use_search_history: str | None = None,
463461
search_buffer_capacity: int | None = None,
@@ -505,10 +503,6 @@ def __init__(
505503
ef_runtime (Optional[int]): Controls the size of the dynamic candidate list for HNSW
506504
algorithm at query time. Higher values improve recall at the expense of
507505
slower search performance. Defaults to None, which uses the index-defined value.
508-
epsilon (Optional[float]): The range search approximation factor for HNSW and SVS-VAMANA
509-
indexes. Sets boundaries for candidates within radius * (1 + epsilon). Higher values
510-
allow more extensive search and more accurate results at the expense of run time.
511-
Defaults to None, which uses the index-defined value (typically 0.01).
512506
search_window_size (Optional[int]): The size of the search window for SVS-VAMANA KNN searches.
513507
Increasing this value generally yields more accurate but slower search results.
514508
Defaults to None, which uses the index-defined value (typically 10).
@@ -541,7 +535,6 @@ def __init__(
541535
self._hybrid_policy: HybridPolicy | None = None
542536
self._batch_size: int | None = None
543537
self._ef_runtime: int | None = None
544-
self._epsilon: float | None = None
545538
self._search_window_size: int | None = None
546539
self._use_search_history: str | None = None
547540
self._search_buffer_capacity: int | None = None
@@ -578,9 +571,6 @@ def __init__(
578571
if ef_runtime is not None:
579572
self.set_ef_runtime(ef_runtime)
580573

581-
if epsilon is not None:
582-
self.set_epsilon(epsilon)
583-
584574
if search_window_size is not None:
585575
self.set_search_window_size(search_window_size)
586576

@@ -613,10 +603,6 @@ def _build_query_string(self) -> str:
613603
if self._ef_runtime:
614604
knn_query += f" {self.EF_RUNTIME} ${self.EF_RUNTIME_PARAM}"
615605

616-
# Add EPSILON parameter if specified (HNSW and SVS-VAMANA)
617-
if self._epsilon is not None:
618-
knn_query += f" EPSILON ${self.EPSILON_PARAM}"
619-
620606
# Add SEARCH_WINDOW_SIZE parameter if specified (SVS-VAMANA)
621607
if self._search_window_size is not None:
622608
knn_query += f" {self.SEARCH_WINDOW_SIZE} ${self.SEARCH_WINDOW_SIZE_PARAM}"
@@ -695,28 +681,6 @@ def set_ef_runtime(self, ef_runtime: int):
695681
# Invalidate the query string
696682
self._built_query_string = None
697683

698-
def set_epsilon(self, epsilon: float):
699-
"""Set the epsilon parameter for the query.
700-
701-
Args:
702-
epsilon (float): The range search approximation factor for HNSW and SVS-VAMANA
703-
indexes. Sets boundaries for candidates within radius * (1 + epsilon).
704-
Higher values allow more extensive search and more accurate results at the
705-
expense of run time.
706-
707-
Raises:
708-
TypeError: If epsilon is not a float or int
709-
ValueError: If epsilon is negative
710-
"""
711-
if not isinstance(epsilon, (float, int)):
712-
raise TypeError("epsilon must be of type float or int")
713-
if epsilon < 0:
714-
raise ValueError("epsilon must be non-negative")
715-
self._epsilon = epsilon
716-
717-
# Invalidate the query string
718-
self._built_query_string = None
719-
720684
def set_search_window_size(self, search_window_size: int):
721685
"""Set the SEARCH_WINDOW_SIZE parameter for the query.
722686
@@ -808,15 +772,6 @@ def ef_runtime(self) -> int | None:
808772
"""
809773
return self._ef_runtime
810774

811-
@property
812-
def epsilon(self) -> float | None:
813-
"""Return the epsilon parameter for the query.
814-
815-
Returns:
816-
Optional[float]: The epsilon value for the query.
817-
"""
818-
return self._epsilon
819-
820775
@property
821776
def search_window_size(self) -> int | None:
822777
"""Return the SEARCH_WINDOW_SIZE parameter for the query.
@@ -862,10 +817,6 @@ def params(self) -> dict[str, Any]:
862817
if self._ef_runtime is not None:
863818
params[self.EF_RUNTIME_PARAM] = self._ef_runtime
864819

865-
# Add EPSILON parameter if specified (HNSW and SVS-VAMANA)
866-
if self._epsilon is not None:
867-
params[self.EPSILON_PARAM] = self._epsilon
868-
869820
# Add SEARCH_WINDOW_SIZE parameter if specified (SVS-VAMANA)
870821
if self._search_window_size is not None:
871822
params[self.SEARCH_WINDOW_SIZE_PARAM] = self._search_window_size

tests/unit/test_query_types.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -973,43 +973,6 @@ def test_vector_query_update_ef_runtime():
973973
assert params2.get(VectorQuery.EF_RUNTIME_PARAM) == 200
974974

975975

976-
def test_vector_query_epsilon():
977-
"""Test that VectorQuery correctly handles epsilon parameter."""
978-
# Create a vector query with epsilon
979-
vector_query = VectorQuery([0.1, 0.2, 0.3, 0.4], "vector_field", epsilon=0.05)
980-
981-
# Check properties
982-
assert vector_query.epsilon == 0.05
983-
984-
# Check query string
985-
query_string = str(vector_query)
986-
assert f"EPSILON ${VectorQuery.EPSILON_PARAM}" in query_string
987-
988-
# Check params dictionary
989-
assert vector_query.params.get(VectorQuery.EPSILON_PARAM) == 0.05
990-
991-
992-
def test_vector_query_invalid_epsilon():
993-
"""Test error handling for invalid epsilon values in VectorQuery."""
994-
# Test with invalid epsilon type
995-
with pytest.raises(TypeError, match="epsilon must be of type float or int"):
996-
VectorQuery([0.1, 0.2, 0.3, 0.4], "vector_field", epsilon="0.05")
997-
998-
# Test with negative epsilon
999-
with pytest.raises(ValueError, match="epsilon must be non-negative"):
1000-
VectorQuery([0.1, 0.2, 0.3, 0.4], "vector_field", epsilon=-0.05)
1001-
1002-
# Create a valid vector query
1003-
vector_query = VectorQuery([0.1, 0.2, 0.3, 0.4], "vector_field")
1004-
1005-
# Test with invalid epsilon via setter
1006-
with pytest.raises(TypeError, match="epsilon must be of type float or int"):
1007-
vector_query.set_epsilon("0.05")
1008-
1009-
with pytest.raises(ValueError, match="epsilon must be non-negative"):
1010-
vector_query.set_epsilon(-0.05)
1011-
1012-
1013976
def test_vector_query_search_window_size():
1014977
"""Test that VectorQuery correctly handles search_window_size parameter (SVS-VAMANA)."""
1015978
# Create a vector query with search_window_size
@@ -1153,31 +1116,27 @@ def test_vector_query_all_runtime_params():
11531116
[0.1, 0.2, 0.3, 0.4],
11541117
"vector_field",
11551118
ef_runtime=100,
1156-
epsilon=0.05,
11571119
search_window_size=40,
11581120
use_search_history="ON",
11591121
search_buffer_capacity=50,
11601122
)
11611123

11621124
# Check all properties
11631125
assert vector_query.ef_runtime == 100
1164-
assert vector_query.epsilon == 0.05
11651126
assert vector_query.search_window_size == 40
11661127
assert vector_query.use_search_history == "ON"
11671128
assert vector_query.search_buffer_capacity == 50
11681129

11691130
# Check query string contains all parameters
11701131
query_string = str(vector_query)
11711132
assert "EF_RUNTIME $EF" in query_string
1172-
assert "EPSILON $EPSILON" in query_string
11731133
assert "SEARCH_WINDOW_SIZE $SEARCH_WINDOW_SIZE" in query_string
11741134
assert "USE_SEARCH_HISTORY $USE_SEARCH_HISTORY" in query_string
11751135
assert "SEARCH_BUFFER_CAPACITY $SEARCH_BUFFER_CAPACITY" in query_string
11761136

11771137
# Check params dictionary contains all parameters
11781138
params = vector_query.params
11791139
assert params["EF"] == 100
1180-
assert params["EPSILON"] == 0.05
11811140
assert params["SEARCH_WINDOW_SIZE"] == 40
11821141
assert params["USE_SEARCH_HISTORY"] == "ON"
11831142
assert params["SEARCH_BUFFER_CAPACITY"] == 50

0 commit comments

Comments
 (0)