Skip to content

Commit 5ac9791

Browse files
added redis-flat
1 parent 4140f42 commit 5ac9791

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

engine/clients/redis/search.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,26 @@ def search_one(cls, vector, meta_conditions, top) -> List[Tuple[int, float]]:
8787
.dialect(4)
8888
.timeout(REDIS_QUERY_TIMEOUT)
8989
)
90+
# Handle vector conversion properly - vector might come as bytes
91+
try:
92+
if isinstance(vector, bytes):
93+
# If vector is bytes, try to convert back to numpy array
94+
try:
95+
import struct
96+
num_floats = len(vector) // 4 # 4 bytes per float32
97+
vector_array = np.array(struct.unpack(f'{num_floats}f', vector), dtype=cls.np_data_type)
98+
except struct.error:
99+
# If that fails, try to decode as numpy array
100+
vector_array = np.frombuffer(vector, dtype=cls.np_data_type)
101+
elif isinstance(vector, np.ndarray):
102+
vector_array = vector.astype(cls.np_data_type)
103+
else:
104+
# Convert list to numpy array
105+
vector_array = np.array(vector, dtype=cls.np_data_type)
106+
except Exception as e:
107+
raise ValueError(f"Failed to convert vector to proper format. Vector type: {type(vector)}, Error: {e}")
90108
params_dict = {
91-
"vec_param": np.array(vector).astype(cls.np_data_type).tobytes(),
109+
"vec_param": vector_array.tobytes(),
92110
"K": top,
93111
**params,
94112
}

0 commit comments

Comments
 (0)