Skip to content

Commit df89e51

Browse files
added epsilon property to the vsim command
1 parent 67ab74d commit df89e51

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

redis/commands/vectorset/commands.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def vsim(
129129
filter_ef: Optional[str] = None,
130130
truth: Optional[bool] = False,
131131
no_thread: Optional[bool] = False,
132+
epsilon: Optional[Number] = None,
132133
) -> Union[
133134
Awaitable[Optional[List[Union[List[EncodableT], Dict[EncodableT, Number]]]]],
134135
Optional[List[Union[List[EncodableT], Dict[EncodableT, Number]]]],
@@ -152,6 +153,9 @@ def vsim(
152153
``no_thread`` when enabled forces the command to execute the search
153154
on the data structure in the main thread.
154155
156+
``epsilon`` floating point between 0 and 1, if specified will return
157+
only elements with distance no further than the specified one.
158+
155159
For more information see https://redis.io/commands/vsim
156160
"""
157161

@@ -176,6 +180,9 @@ def vsim(
176180
if count:
177181
pieces.extend(["COUNT", count])
178182

183+
if epsilon:
184+
pieces.extend(["EPSILON", epsilon])
185+
179186
if ef:
180187
pieces.extend(["EF", ef])
181188

tests/test_vsets.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,19 @@ def test_vsim_truth_no_thread_enabled(d_client):
424424
assert len(sim_no_thread) == 10
425425
assert isinstance(sim_no_thread, dict)
426426

427+
@skip_if_server_version_lt("8.2.0")
428+
def test_vsim_epsilon(d_client):
429+
d_client.vset().vadd("myset", [2, 1, 1], "a")
430+
d_client.vset().vadd("myset", [2, 0, 1], "b")
431+
d_client.vset().vadd("myset", [2, 0, 0], "c")
432+
d_client.vset().vadd("myset", [2, 0, -1], "d")
433+
d_client.vset().vadd("myset", [2, -1, -1], "e")
434+
435+
res1 = d_client.vset().vsim("myset", [2, 1, 1])
436+
assert 5 == len(res1)
437+
438+
res2 = d_client.vset().vsim("myset", [2, 1, 1], epsilon=0.5)
439+
assert 3 == len(res2)
427440

428441
@skip_if_server_version_lt("7.9.0")
429442
def test_vdim(d_client):

0 commit comments

Comments
 (0)