1717from locomo .locomo_rag import RAGManager
1818from openai import OpenAI
1919from tqdm import tqdm
20- from utils .client import mem0_client , memos_client , zep_client
21- from utils .memos_filters import filter_memory_data
2220from utils .prompts import (
23- MEM0_CONTEXT_TEMPLATE ,
24- MEM0_GRAPH_CONTEXT_TEMPLATE ,
2521 MEMOS_CONTEXT_TEMPLATE ,
26- ZEP_CONTEXT_TEMPLATE ,
2722)
2823
2924
@@ -100,109 +95,6 @@ def split_chunks2(self, message_content, chunk_size):
10095 return chunks , embeddings
10196
10297
103- def zep_search (client , user_id , query , top_k = 20 ):
104- start = time ()
105- nodes_result = client .graph .search (
106- query = query ,
107- user_id = user_id ,
108- scope = "nodes" ,
109- reranker = "rrf" ,
110- limit = top_k ,
111- )
112- edges_result = client .graph .search (
113- query = query ,
114- user_id = user_id ,
115- scope = "edges" ,
116- reranker = "cross_encoder" ,
117- limit = top_k ,
118- )
119-
120- nodes = nodes_result .nodes
121- edges = edges_result .edges
122-
123- facts = [f" - { edge .fact } (event_time: { edge .valid_at } )" for edge in edges ]
124- entities = [f" - { node .name } : { node .summary } " for node in nodes ]
125- context = ZEP_CONTEXT_TEMPLATE .format (facts = "\n " .join (facts ), entities = "\n " .join (entities ))
126-
127- duration_ms = (time () - start ) * 1000
128-
129- return context , duration_ms
130-
131-
132- def mem0_search (client , user_id , query , top_k = 20 , enable_graph = False , frame = "mem0-api" ):
133- start = time ()
134-
135- if frame == "mem0-local" :
136- results = client .search (
137- query = query ,
138- user_id = user_id ,
139- top_k = top_k ,
140- )
141- search_memories = "\n " .join (
142- [
143- f" - { item ['memory' ]} (date: { item ['metadata' ]['timestamp' ]} )"
144- for item in results ["results" ]
145- ]
146- )
147- search_graph = (
148- "\n " .join (
149- [
150- f" - 'source': { item .get ('source' , '?' )} -> 'target': { item .get ('destination' , '?' )} (relationship: { item .get ('relationship' , '?' )} )"
151- for item in results .get ("relations" , [])
152- ]
153- )
154- if enable_graph
155- else ""
156- )
157-
158- elif frame == "mem0-api" :
159- results = client .search (
160- query = query ,
161- user_id = user_id ,
162- top_k = top_k ,
163- version = "v2" ,
164- output_format = "v1.1" ,
165- enable_graph = enable_graph ,
166- filters = {"AND" : [{"user_id" : user_id }, {"run_id" : "*" }]},
167- )
168- search_memories = "\n " .join (
169- [f" - { item ['memory' ]} (date: { item ['created_at' ]} )" for item in results ["results" ]]
170- )
171- search_graph = (
172- "\n " .join (
173- [
174- f" - 'source': { item .get ('source' , '?' )} -> 'target': { item .get ('target' , '?' )} (relationship: { item .get ('relationship' , '?' )} )"
175- for item in results .get ("relations" , [])
176- ]
177- )
178- if enable_graph
179- else ""
180- )
181- if enable_graph :
182- context = MEM0_GRAPH_CONTEXT_TEMPLATE .format (
183- user_id = user_id , memories = search_memories , relations = search_graph
184- )
185- else :
186- context = MEM0_CONTEXT_TEMPLATE .format (user_id = user_id , memories = search_memories )
187- duration_ms = (time () - start ) * 1000
188- return context , duration_ms
189-
190-
191- def memos_search (client , user_id , query , frame = "memos-local" ):
192- start = time ()
193-
194- results = client .search (
195- query = query ,
196- user_id = user_id ,
197- )
198-
199- search_memories = filter_memory_data (results )["text_mem" ][0 ]["memories" ]
200- context = MEMOS_CONTEXT_TEMPLATE .format (user_id = user_id , memories = search_memories )
201-
202- duration_ms = (time () - start ) * 1000
203- return context , duration_ms
204-
205-
20698def rag_search (client , user_id , query , top_k , frame ):
20799 print (f"The number_chunks is:{ client .k } " )
208100 start = time ()
@@ -216,7 +108,7 @@ def rag_search(client, user_id, query, top_k, frame):
216108 question_id = item .get ("question_id" )
217109 question = item .get ("question" )
218110 answer = item .get ("answer" )
219- print (f"The question_id : { question_id } --> question: { question } <----> answer is:{ answer } " )
111+ print (f"Question_id : { question_id } --> question: { question } <----> answer is:{ answer } " )
220112 haystack_sessions = item .get ("haystack_sessions" , [])
221113
222114 for session in haystack_sessions :
@@ -285,33 +177,7 @@ def process_user(lme_df, conv_idx, frame, version, chunk_size, num_chunks, top_k
285177 print (f"♻️ \033 [93mUsing existing results for conversation { conv_idx } \033 [0m" )
286178 return existing_results
287179
288- if frame == "zep" :
289- client = zep_client ()
290- print ("🔌 \033 [1mUsing \033 [94mZep client\033 [0m \033 [1mfor search...\033 [0m" )
291- context , duration_ms = zep_search (client , user_id , question )
292-
293- elif frame == "mem0-local" :
294- client = mem0_client (mode = "local" )
295- print ("🔌 \033 [1mUsing \033 [94mMem0 Local client\033 [0m \033 [1mfor search...\033 [0m" )
296- context , duration_ms = mem0_search (client , user_id , question , top_k = top_k , frame = frame )
297- elif frame == "mem0-api" :
298- client = mem0_client (mode = "api" )
299- print ("🔌 \033 [1mUsing \033 [94mMem0 API client\033 [0m \033 [1mfor search...\033 [0m" )
300- context , duration_ms = mem0_search (client , user_id , question , top_k = top_k , frame = frame )
301- elif frame == "memos-local" :
302- client = memos_client (
303- mode = "local" ,
304- db_name = f"lme_{ frame } -{ version } -{ user_id .replace ('_' , '' )} " ,
305- user_id = user_id ,
306- top_k = 20 ,
307- mem_cube_path = f"results/lme/{ frame } -{ version } /storages/{ user_id } " ,
308- mem_cube_config_path = "configs/mem_cube_config.json" ,
309- mem_os_config_path = "configs/mos_memos_config.json" ,
310- addorsearch = "search" ,
311- )
312- print ("🔌 \033 [1mUsing \033 [94mMemos Local client\033 [0m \033 [1mfor search...\033 [0m" )
313- context , duration_ms = memos_search (client , user_id , question , frame = frame )
314- elif frame == "rag" :
180+ if frame == "rag" :
315181 rag_fullcontext_obj = RAGFullContext (chunk_size = chunk_size , k = num_chunks )
316182 print ("🔌 \033 [1mUsing \033 [94mRAG API client\033 [0m \033 [1mfor search...\033 [0m" )
317183 context , duration_ms = rag_search (rag_fullcontext_obj , user_id , question , top_k , frame )
@@ -414,7 +280,7 @@ def main(frame, version, chunk_size, num_chunks, top_k=20, num_workers=2):
414280
415281if __name__ == "__main__" :
416282 parser = argparse .ArgumentParser (description = "LongMemeval Search Script" )
417- parser .add_argument ("--lib" , type = str , choices = ["mem0-local" , "mem0-api" , "memos-local" , " rag" ])
283+ parser .add_argument ("--lib" , type = str , choices = ["rag" ])
418284 parser .add_argument (
419285 "--version" , type = str , default = "v1" , help = "Version of the evaluation framework."
420286 )
0 commit comments