add tests for the limit of EFSearch

This commit is contained in:
Joan Fontanals Martinez
2025-09-18 15:37:34 +02:00
parent 7b011df251
commit 4fc10475b1
2 changed files with 32 additions and 1 deletions

View 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}"

View File

@@ -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,