@@ -102,28 +102,19 @@ def search_one(cls, vector, meta_conditions, top) -> List[Tuple[int, float]]:
102102
103103 return [(int (result .id ), float (result .vector_score )) for result in results .docs ]
104104
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" )
105+ @classmethod
106+ def insert_one (cls , doc_id : int , vector , meta_conditions ):
107+ if cls .client is None :
108+ raise RuntimeError ("Redis client not initialized" )
113109
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 ()
110+ if not isinstance (vector , bytes ):
111+ vec_param = np .array (vector , dtype = cls .np_data_type ).tobytes ()
112+ else :
113+ vec_param = vector
119114
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 )
115+ doc = {"vector" : vec_param }
116+ if meta_conditions :
117+ for k , v in meta_conditions .items ():
118+ doc [k ] = str (v )
126119
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 )
120+ cls .client .hset (f"doc:{ doc_id } " , mapping = doc )
0 commit comments