1010
1111from tqdm import tqdm
1212
13+
1314sys .path .append (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
1415
1516
@@ -171,7 +172,9 @@ def ingest_conv(row_data, context, version, conv_idx, frame, success_records, f)
171172 client = MemosApiOnlineClient ()
172173
173174 try :
174- ingest_session (session = context , user_id = user_id , session_id = conv_idx , frame = frame , client = client )
175+ ingest_session (
176+ session = context , user_id = user_id , session_id = conv_idx , frame = frame , client = client
177+ )
175178 print (f"✅ Ingestion of conversation { conv_idx } completed" )
176179 print ("=" * 80 )
177180
@@ -187,10 +190,9 @@ def main(frame, version, num_workers=2, clear=False):
187190 os .makedirs (f"results/pm/{ frame } -{ version } /" , exist_ok = True )
188191 record_file = f"results/pm/{ frame } -{ version } /success_records.txt"
189192
190- if clear :
191- if os .path .exists (record_file ):
192- os .remove (record_file )
193- print ("🧹 Cleared progress records" )
193+ if clear and os .path .exists (record_file ):
194+ os .remove (record_file )
195+ print ("🧹 Cleared progress records" )
194196
195197 print ("\n " + "=" * 80 )
196198 print (f"🚀 PERSONAMEM INGESTION - { frame .upper ()} v{ version } " .center (80 ))
@@ -205,15 +207,20 @@ def main(frame, version, num_workers=2, clear=False):
205207
206208 success_records = set ()
207209 if os .path .exists (record_file ):
208- with open (record_file , "r" ) as f :
209- success_records = set (line .strip () for line in f )
210- print (f"📊 Found { len (success_records )} completed conversations, { total_rows - len (success_records )} remaining" )
210+ with open (record_file ) as f :
211+ success_records = {line .strip () for line in f }
212+ print (
213+ f"📊 Found { len (success_records )} completed conversations, { total_rows - len (success_records )} remaining"
214+ )
211215
212216 start_time = datetime .now ()
213217 all_data = list (load_rows_with_context (question_csv_path , context_jsonl_path ))
214218
215- pending_data = [(idx , row_data , context ) for idx , (row_data , context ) in enumerate (all_data )
216- if str (idx ) not in success_records ]
219+ pending_data = [
220+ (idx , row_data , context )
221+ for idx , (row_data , context ) in enumerate (all_data )
222+ if str (idx ) not in success_records
223+ ]
217224
218225 if not pending_data :
219226 print ("✅ All conversations have been processed!" )
@@ -232,16 +239,16 @@ def main(frame, version, num_workers=2, clear=False):
232239 conv_idx = idx ,
233240 frame = frame ,
234241 success_records = success_records ,
235- f = f
242+ f = f ,
236243 )
237244 futures .append (future )
238245
239246 completed_count = 0
240247 for future in tqdm (
241- as_completed (futures ), total = len (futures ), desc = "Processing conversations"
248+ as_completed (futures ), total = len (futures ), desc = "Processing conversations"
242249 ):
243250 try :
244- result = future .result ()
251+ future .result ()
245252 completed_count += 1
246253 except Exception as exc :
247254 print (f"\n ❌ Conversation generated an exception: { exc } " )
@@ -261,13 +268,28 @@ def main(frame, version, num_workers=2, clear=False):
261268
262269if __name__ == "__main__" :
263270 parser = argparse .ArgumentParser (description = "PersonaMem Ingestion Script" )
264- parser .add_argument ("--lib" , type = str ,
265- choices = ["memos-api-online" , "mem0" , "mem0_graph" , "memos-api" , "memobase" , "memu" ,
266- "supermemory" , "zep" ],
267- default = 'memos-api' )
268- parser .add_argument ("--version" , type = str , default = "default" , help = "Version of the evaluation framework." )
269- parser .add_argument ("--workers" , type = int , default = 3 , help = "Number of parallel workers for processing users." )
271+ parser .add_argument (
272+ "--lib" ,
273+ type = str ,
274+ choices = [
275+ "memos-api-online" ,
276+ "mem0" ,
277+ "mem0_graph" ,
278+ "memos-api" ,
279+ "memobase" ,
280+ "memu" ,
281+ "supermemory" ,
282+ "zep" ,
283+ ],
284+ default = "memos-api" ,
285+ )
286+ parser .add_argument (
287+ "--version" , type = str , default = "default" , help = "Version of the evaluation framework."
288+ )
289+ parser .add_argument (
290+ "--workers" , type = int , default = 3 , help = "Number of parallel workers for processing users."
291+ )
270292 parser .add_argument ("--clear" , action = "store_true" , help = "Clear progress and start fresh" )
271293 args = parser .parse_args ()
272294
273- main (frame = args .lib , version = args .version , num_workers = args .workers , clear = args .clear )
295+ main (frame = args .lib , version = args .version , num_workers = args .workers , clear = args .clear )
0 commit comments