Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions redis/commands/vectorset/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def vsim(
filter_ef: Optional[str] = None,
truth: Optional[bool] = False,
no_thread: Optional[bool] = False,
epsilon: Optional[Number] = None,
) -> Union[
Awaitable[Optional[List[Union[List[EncodableT], Dict[EncodableT, Number]]]]],
Optional[List[Union[List[EncodableT], Dict[EncodableT, Number]]]],
Expand All @@ -152,6 +153,9 @@ def vsim(
``no_thread`` when enabled forces the command to execute the search
on the data structure in the main thread.

``epsilon`` floating point between 0 and 1, if specified will return
only elements with distance no further than the specified one.

For more information see https://redis.io/commands/vsim
"""

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

if epsilon:
pieces.extend(["EPSILON", epsilon])

if ef:
pieces.extend(["EF", ef])

Expand Down
15 changes: 15 additions & 0 deletions tests/test_asyncio/test_vsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,21 @@ async def test_vsim_truth_no_thread_enabled(d_client):
assert isinstance(sim_no_thread, dict)


@skip_if_server_version_lt("8.2.0")
async def test_vsim_epsilon(d_client):
await d_client.vset().vadd("myset", [2, 1, 1], "a")
await d_client.vset().vadd("myset", [2, 0, 1], "b")
await d_client.vset().vadd("myset", [2, 0, 0], "c")
await d_client.vset().vadd("myset", [2, 0, -1], "d")
await d_client.vset().vadd("myset", [2, -1, -1], "e")

res1 = await d_client.vset().vsim("myset", [2, 1, 1])
assert 5 == len(res1)

res2 = await d_client.vset().vsim("myset", [2, 1, 1], epsilon=0.5)
assert 3 == len(res2)


@skip_if_server_version_lt("7.9.0")
async def test_vdim(d_client):
float_array = [1, 4.32, 0.11, 0.5, 0.9, 0.1, 0.2]
Expand Down
15 changes: 15 additions & 0 deletions tests/test_vsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ def test_vsim_truth_no_thread_enabled(d_client):
assert isinstance(sim_no_thread, dict)


@skip_if_server_version_lt("8.2.0")
def test_vsim_epsilon(d_client):
d_client.vset().vadd("myset", [2, 1, 1], "a")
d_client.vset().vadd("myset", [2, 0, 1], "b")
d_client.vset().vadd("myset", [2, 0, 0], "c")
d_client.vset().vadd("myset", [2, 0, -1], "d")
d_client.vset().vadd("myset", [2, -1, -1], "e")

res1 = d_client.vset().vsim("myset", [2, 1, 1])
assert 5 == len(res1)

res2 = d_client.vset().vsim("myset", [2, 1, 1], epsilon=0.5)
assert 3 == len(res2)


@skip_if_server_version_lt("7.9.0")
def test_vdim(d_client):
float_array = [1, 4.32, 0.11, 0.5, 0.9, 0.1, 0.2]
Expand Down