@@ -92,8 +92,7 @@ def test_add_memories(self, sample_messages, memory_store):
9292 """Test adding memories successfully."""
9393 store , user_id = memory_store
9494 result = store .add_memories (messages = sample_messages , user_id = user_id )
95- # with infer=True (default), two messages are converted to a single memory
96- assert len (result ) == 1
95+ assert result == []
9796
9897 @pytest .mark .skipif (
9998 not os .environ .get ("MEM0_API_KEY" , None ),
@@ -115,9 +114,7 @@ def test_add_memories_with_metadata(self, memory_store):
115114 """Test adding memories with metadata."""
116115 store , user_id = memory_store
117116 messages = [ChatMessage .from_user ("User likes to work with python on NLP projects" )]
118- result = store .add_memories (
119- messages = messages , user_id = user_id , metadata = {"key" : "value" }, async_mode = False
120- )
117+ result = store .add_memories (messages = messages , infer = False , user_id = user_id , metadata = {"key" : "value" })
121118 assert len (result ) == 1
122119
123120 @pytest .mark .skipif (
@@ -201,20 +198,30 @@ def test_delete_memory(self, sample_messages, memory_store):
201198 def test_role_based_memories (self , memory_store ):
202199 store , user_id = memory_store
203200 unique_agent_id = _get_unique_user_id ()
204- messages = [
201+ # in Mem0 v3, to keep user and assistant turns searchable by their own entity id,
202+ # they must be added in separate calls
203+ user_messages = [
205204 ChatMessage .from_user ("I'm planning to watch a movie tonight. Any recommendations?" ),
206- ChatMessage .from_assistant ("How about thriller movies? They can be quite engaging." ),
207205 ChatMessage .from_user ("I'm not a big fan of thriller movies but I love sci-fi movies." ),
206+ ]
207+ assistant_messages = [
208+ ChatMessage .from_assistant ("How about thriller movies? They can be quite engaging." ),
208209 ChatMessage .from_assistant (
209210 "Got it! Then I would recommend Interstellar or Inception? I would also recommend watching some "
210211 "Japanese anime movies."
211212 ),
212213 ]
213- store .add_memories (messages = messages , infer = False , user_id = user_id , agent_id = unique_agent_id )
214- assistant_mem = store .search_memories (filters = {"field" : "agent_id" , "operator" : "==" , "value" : unique_agent_id })
215- user_mem = store .search_memories (filters = {"field" : "user_id" , "operator" : "==" , "value" : user_id })
216- assert len (assistant_mem ) == 2
217- assert len (user_mem ) == 2
214+ store .add_memories (messages = user_messages , infer = False , user_id = user_id )
215+ store .add_memories (messages = assistant_messages , infer = False , agent_id = unique_agent_id )
216+ try :
217+ assistant_mem = store .search_memories (
218+ filters = {"field" : "agent_id" , "operator" : "==" , "value" : unique_agent_id }
219+ )
220+ user_mem = store .search_memories (filters = {"field" : "user_id" , "operator" : "==" , "value" : user_id })
221+ assert len (assistant_mem ) == 2
222+ assert len (user_mem ) == 2
223+ finally :
224+ store .delete_all_memories (agent_id = unique_agent_id )
218225
219226 @pytest .mark .skipif (
220227 not (os .environ .get ("MEM0_API_KEY" , None ) and os .environ .get ("OPENAI_API_KEY" , None )),
0 commit comments