mirror of
https://github.com/redis/redis.git
synced 2026-01-12 00:03:59 +08:00
add tests for the limit of EFSearch
This commit is contained in:
32
modules/vector-sets/tests/vsim_limit_efsearch.py
Normal file
32
modules/vector-sets/tests/vsim_limit_efsearch.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from test import TestCase, generate_random_vector
|
||||
import struct
|
||||
|
||||
class VSIMLimitEFSearch(TestCase):
|
||||
def getname(self):
|
||||
return "VSIM Limit EF Search"
|
||||
|
||||
def estimated_runtime(self):
|
||||
return 0.2
|
||||
|
||||
def test(self):
|
||||
dim = 32
|
||||
vec = generate_random_vector(dim)
|
||||
vec_bytes = struct.pack(f'{dim}f', *vec)
|
||||
|
||||
# Add test vector
|
||||
self.redis.execute_command('VADD', self.test_key, 'FP32', vec_bytes, f'{self.test_key}:item:1')
|
||||
|
||||
query_vec = generate_random_vector(dim)
|
||||
|
||||
# Test EF upper bound (should accept 1000000)
|
||||
result = self.redis.execute_command('VSIM', self.test_key, 'VALUES', dim,
|
||||
*[str(x) for x in query_vec], 'EF', 1000000)
|
||||
assert isinstance(result, list), "EF=1000000 should be accepted"
|
||||
|
||||
# Test EF over limit (should reject > 1000000)
|
||||
try:
|
||||
self.redis.execute_command('VSIM', self.test_key, 'VALUES', dim,
|
||||
*[str(x) for x in query_vec], 'EF', 1000001)
|
||||
assert False, "EF=1000001 should be rejected"
|
||||
except Exception as e:
|
||||
assert "invalid EF" in str(e), f"Expected EF validation error, got: {e}"
|
||||
@@ -826,7 +826,6 @@ void VSIM_execute(RedisModuleCtx *ctx, struct vsetObject *vset,
|
||||
/* Perform search */
|
||||
hnswNode **neighbors = RedisModule_Alloc(sizeof(hnswNode*)*ef);
|
||||
float *distances = RedisModule_Alloc(sizeof(float)*ef);
|
||||
int slot = hnsw_acquire_read_slot(vset->hnsw);
|
||||
unsigned int found;
|
||||
if (ground_truth) {
|
||||
found = hnsw_ground_truth_with_filter(vset->hnsw, vec, ef, neighbors,
|
||||
|
||||
Reference in New Issue
Block a user