Skip to content

Commit 398b64e

Browse files
committed
started changes to redis search.py
1 parent 999f8a2 commit 398b64e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

engine/clients/redis/search.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,29 @@ def search_one(cls, vector, meta_conditions, top) -> List[Tuple[int, float]]:
101101
results = cls._ft.search(q, query_params=params_dict)
102102

103103
return [(int(result.id), float(result.vector_score)) for result in results.docs]
104+
105+
@classmethod
106+
def insert_one(cls, doc_id: int, vector, metadata: dict = None):
107+
"""
108+
Insert a single vector and optional metadata into Redis.
109+
Designed for mixed workload support.
110+
"""
111+
if cls.client is None:
112+
raise RuntimeError("Redis client not initialized")
113+
114+
# Convert vector to correct binary format
115+
if isinstance(vector, bytes):
116+
vec_param = vector
117+
else:
118+
vec_param = np.array(vector, dtype=cls.np_data_type).tobytes()
119+
120+
# Prepare the document for Redis
121+
doc = {"vector": vec_param}
122+
if metadata:
123+
# Flatten metadata into string fields Redis can store
124+
for k, v in metadata.items():
125+
doc[k] = str(v)
126+
127+
# Use Redis hash to store the document
128+
# You might use JSON.SET if your index expects JSON
129+
cls.client.hset(f"doc:{doc_id}", mapping=doc)

0 commit comments

Comments
 (0)