Skip to content

Commit 71e275e

Browse files
authored
test: add VectorField RERANK serialization tests for sync and async search (#4202)
1 parent 459234e commit 71e275e

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

tests/test_asyncio/test_search.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,40 @@ async def test_hybrid_search_query_with_pipeline(self, decoded_r: redis.Redis):
26212621

26222622
class TestSearchWithVamana(AsyncSearchTestsBase):
26232623
# SVS-VAMANA Async Tests
2624+
@pytest.mark.fixed_client
2625+
def test_vector_field_rerank(self):
2626+
# Pure serialization check: VectorField builds the FT.CREATE args with
2627+
# no server round-trip, so this test needs no Redis and is not gated.
2628+
# RERANK is a boolean key-value attribute for HNSW vector fields on
2629+
# disk-backed (Flex / Auto-Tiering) deployments, where it is mandatory.
2630+
# It toggles the exact FP32 rerank pass over the approximate candidates
2631+
# returned by the on-disk graph traversal. It flows through the generic
2632+
# ``attributes`` dict as the string "TRUE"/"FALSE" (a bare flag is
2633+
# rejected by the server, and Python bools are rejected by the client
2634+
# encoder), and the attribute-count token accounts for the extra pair.
2635+
# Field construction has no I/O, so this mirrors the sync serialization
2636+
# test and is not an async test.
2637+
field = VectorField(
2638+
"v",
2639+
"HNSW",
2640+
{"TYPE": "FLOAT32", "DIM": 128, "DISTANCE_METRIC": "L2", "RERANK": "TRUE"},
2641+
)
2642+
assert field.args[0] == "VECTOR"
2643+
assert field.args[1] == "HNSW"
2644+
assert field.args[2] == 8 # 4 attribute pairs -> 8 tokens
2645+
assert "RERANK" in field.args
2646+
assert "TRUE" in field.args
2647+
2648+
# MS2 also accepts RERANK FALSE (opt out of the rerank pass).
2649+
field = VectorField(
2650+
"v",
2651+
"HNSW",
2652+
{"TYPE": "FLOAT32", "DIM": 128, "DISTANCE_METRIC": "L2", "RERANK": "FALSE"},
2653+
)
2654+
assert field.args[2] == 8
2655+
assert "RERANK" in field.args
2656+
assert "FALSE" in field.args
2657+
26242658
@pytest.mark.redismod
26252659
@skip_if_server_version_lt("8.1.224")
26262660
async def test_async_svs_vamana_basic_functionality(self, decoded_r: redis.Redis):

tests/test_search.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,38 @@ def test_vector_field_error(self, r):
34293429
with pytest.raises(Exception):
34303430
r.ft().create_index((VectorField("v", "SORT", {}),))
34313431

3432+
@pytest.mark.fixed_client
3433+
def test_vector_field_rerank(self):
3434+
# Pure serialization check: VectorField builds the FT.CREATE args with
3435+
# no server round-trip, so this test needs no Redis and is not gated.
3436+
# RERANK is a boolean key-value attribute for HNSW vector fields on
3437+
# disk-backed (Flex / Auto-Tiering) deployments, where it is mandatory.
3438+
# It toggles the exact FP32 rerank pass over the approximate candidates
3439+
# returned by the on-disk graph traversal. It flows through the generic
3440+
# ``attributes`` dict as the string "TRUE"/"FALSE" (a bare flag is
3441+
# rejected by the server, and Python bools are rejected by the client
3442+
# encoder), and the attribute-count token accounts for the extra pair.
3443+
field = VectorField(
3444+
"v",
3445+
"HNSW",
3446+
{"TYPE": "FLOAT32", "DIM": 128, "DISTANCE_METRIC": "L2", "RERANK": "TRUE"},
3447+
)
3448+
assert field.args[0] == "VECTOR"
3449+
assert field.args[1] == "HNSW"
3450+
assert field.args[2] == 8 # 4 attribute pairs -> 8 tokens
3451+
assert "RERANK" in field.args
3452+
assert "TRUE" in field.args
3453+
3454+
# MS2 also accepts RERANK FALSE (opt out of the rerank pass).
3455+
field = VectorField(
3456+
"v",
3457+
"HNSW",
3458+
{"TYPE": "FLOAT32", "DIM": 128, "DISTANCE_METRIC": "L2", "RERANK": "FALSE"},
3459+
)
3460+
assert field.args[2] == 8
3461+
assert "RERANK" in field.args
3462+
assert "FALSE" in field.args
3463+
34323464
@pytest.mark.redismod
34333465
@skip_ifmodversion_lt("2.4.3", "search")
34343466
def test_text_params(self, client):

0 commit comments

Comments
 (0)