mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

add response to m.add() call

Open femto opened this issue 1 year ago • 1 comments

Description

Added useful return information for m.add() call, discussed in https://github.com/mem0ai/mem0/issues/1499, where original implementation doesn't have useful information returned after calling m.add(), which is not good.

Fixes https://github.com/mem0ai/mem0/issues/1499

Type of change

Please delete options that are not relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

use the following script, change password to suitable value

from mem0 import Memory
import os

from dotenv import load_dotenv
load_dotenv()

config = {
    "version": "v1.1",
    "llm": {
        "provider": "openai",
        "config": {
            #"model": "deepseek-coder",
            "model": "gpt-4o-mini",
            "temperature": 0.2,
            "max_tokens": 1500,
            "top_p" : 1.0
        }
    },
"embedder": {
        "provider": "ollama",
        "config": {
            "model": "nomic-embed-text:latest",
            "ollama_base_url": "http://localhost:11434",
        },
    },
"vector_store": {
        "provider": "qdrant",
        "config": {
            "collection_name": "mem0",
            "host": "localhost",
            "port": 6333,
            "on_disk": True,
            "embedding_model_dims": 768

        }
    },
"graph_store": {
        "provider": "neo4j",
        "config": {
            "url": "neo4j+s://4f9f66c6.databases.neo4j.io:7687",
            "username": "neo4j",
            "password": "xxx"
        }
    },
}
m = Memory.from_config(config)
result = m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
print(result)
result = m.add("doesn't like to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
print(result)
#print(all_memories)
# Store a memory from any unstructured text
#m.delete_all(user_id="alice")
result = m.add("I am working on improving my tennis skills. Suggest some online courses.", user_id="alice", metadata={"category": "hobbies"})
print(result)

outputs:

{'memories': defaultdict(<class 'list'>, {'delete': [{'id': '0f5579d1-03ea-4037-ac61-f0ccfffca6ca', 'data': None}]}), 'graph': defaultdict(<class 'list'>, {'update': [{'source': 'alice', 'destination': 'cricket', 'relationship': 'LIKES_TO_PLAY'}, {'source': 'alice', 'destination': 'weekends', 'relationship': 'PLAYS_ON'}]})}
{'memories': defaultdict(<class 'list'>, {'add': [{'id': '761826cb-1f46-4bda-9de6-7fbee9a1a86d', 'data': "Doesn't like to play cricket on weekends."}]}), 'graph': defaultdict(<class 'list'>, {'update': [{'source': 'alice', 'destination': 'cricket', 'relationship': 'dislikes playing cricket on weekends'}, {'source': 'alice', 'destination': 'weekends', 'relationship': 'dislikes playing cricket on weekends'}]})}
{'memories': defaultdict(<class 'list'>, {'update': [{'id': '761826cb-1f46-4bda-9de6-7fbee9a1a86d', 'data': "Doesn't like to play cricket on weekends. Working on improving tennis skills and interested in online courses for tennis."}], 'add': [{'id': '1bcc6290-0be9-4c1d-8a52-858554be0b4c', 'data': 'Working on improving tennis skills. Interested in online courses for tennis.'}]}), 'graph': defaultdict(<class 'list'>, {'update': [{'source': 'alice', 'destination': 'tennis', 'relationship': 'IMPROVING_SKILLS_IN'}]})}

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] My changes generate no new warnings
  • [x] I have checked my code and corrected any misspellings

Maintainer Checklist

  • [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
  • [ ] Made sure Checks passed

femto avatar Aug 22 '24 07:08 femto