Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add response to m.add() call #1732

Merged
merged 7 commits into from
Oct 15, 2024
Merged

Conversation

femto
Copy link
Contributor

@femto femto commented Aug 22, 2024

Description

Added useful return information for m.add() call,
discussed in #1499,
where original implementation doesn't have useful information returned after calling m.add(),
which is not good.

Fixes
#1499

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • 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:

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

Maintainer Checklist

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

@CLAassistant
Copy link

CLAassistant commented Aug 22, 2024

CLA assistant check
All committers have signed the CLA.

@@ -179,7 +182,7 @@ def add(
self.graph.user_id = "USER"
added_entities = self.graph.add(data)

return {"message": "ok"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to consider the graph memory as well in the return statement

Copy link
Contributor Author

@femto femto Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added,also change the script, please check.

@Dev-Khant
Copy link
Member

@femto Can you please resolve the merge conflicts?

@femto
Copy link
Contributor Author

femto commented Oct 8, 2024

@Dev-Khant Hello, doesn't your side says that you have some platform code,
so you want to update from your side?

@prateekchhikara
Copy link
Collaborator

@femto we have already resolved your issue in one of our previous commits.

@femto
Copy link
Contributor Author

femto commented Oct 9, 2024

@prateekchhikara resolved the conflict

@prateekchhikara prateekchhikara merged commit 2cd9f94 into mem0ai:main Oct 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants