Skip to content

Adding vector search tests for types int8/uint8 #3525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2025
Merged
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
58 changes: 58 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,64 @@ def test_vector_search_with_default_dialect(client):
assert res["total_results"] == 2


@pytest.mark.redismod
@skip_if_server_version_lt("7.9.0")
def test_vector_search_with_int8_type(client):
client.ft().create_index(
(VectorField("v", "FLAT", {"TYPE": "INT8", "DIM": 2, "DISTANCE_METRIC": "L2"}),)
)

a = [1.5, 10]
b = [123, 100]
c = [1, 1]

client.hset("a", "v", np.array(a, dtype=np.int8).tobytes())
client.hset("b", "v", np.array(b, dtype=np.int8).tobytes())
client.hset("c", "v", np.array(c, dtype=np.int8).tobytes())

query = Query("*=>[KNN 2 @v $vec as score]")
query_params = {"vec": np.array(a, dtype=np.int8).tobytes()}

assert 2 in query.get_args()

res = client.ft().search(query, query_params=query_params)
if is_resp2_connection(client):
assert res.total == 2
else:
assert res["total_results"] == 2


@pytest.mark.redismod
@skip_if_server_version_lt("7.9.0")
def test_vector_search_with_uint8_type(client):
client.ft().create_index(
(
VectorField(
"v", "FLAT", {"TYPE": "UINT8", "DIM": 2, "DISTANCE_METRIC": "L2"}
),
)
)

a = [1.5, 10]
b = [123, 100]
c = [1, 1]

client.hset("a", "v", np.array(a, dtype=np.uint8).tobytes())
client.hset("b", "v", np.array(b, dtype=np.uint8).tobytes())
client.hset("c", "v", np.array(c, dtype=np.uint8).tobytes())

query = Query("*=>[KNN 2 @v $vec as score]")
query_params = {"vec": np.array(a, dtype=np.uint8).tobytes()}

assert 2 in query.get_args()

res = client.ft().search(query, query_params=query_params)
if is_resp2_connection(client):
assert res.total == 2
else:
assert res["total_results"] == 2


@pytest.mark.redismod
@skip_ifmodversion_lt("2.4.3", "search")
def test_search_query_with_different_dialects(client):
Expand Down
Loading