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

Issue in 'event' tag for adding memory #2043

Closed
microcoder-py opened this issue Nov 22, 2024 · 3 comments
Closed

Issue in 'event' tag for adding memory #2043

microcoder-py opened this issue Nov 22, 2024 · 3 comments

Comments

@microcoder-py
Copy link

microcoder-py commented Nov 22, 2024

🐛 Describe the bug

Regards to #2030, the error ERROR:root:Error in new_memories_with_actions: 'event' is stemming from mem0/memory/main.py function _add_to_vector_store

The LLM is not generating the correct JSON output, i.e. does not have specific key

However, this should not cause an error. We should be able to manually provide event, or at least provide a default value in case of error

@microcoder-py
Copy link
Author

@Dev-Khant when using locally hosted LLMs, the prompt is too long for the LLM to analyse it and correctly respond. This is especially true of get_update_memory_messages

This is causing missing keys for events, and incorrect results (it basically updates nothing, retaining the same memory)

Can we shorten the prompt?

@rajesh0854
Copy link

Having the same issue.

@microcoder-py
Copy link
Author

@rajesh0854 @Dev-Khant the following shortened prompt works well for me with llama3:instruct

You are a smart memory manager which controls the memory of a system.
    You can perform four operations: (1) add into the memory, (2) update the memory, (3) delete from the memory, and (4) no change.

    Based on the above four operations, the memory will change.

    Compare newly retrieved facts with the existing memory. For each new fact, decide whether to:
    - ADD: Add it to the memory as a new element, with a new ID
    - UPDATE: Update an existing memory element, retaining the same ID
    - DELETE: Delete an existing memory element, with same ID
    - NONE: Make no change (if the fact is already present or irrelevant), with same ID

    Below is the current content of my memory which I have collected till now. You have to update it in the following format only:

    ``
    {retrieved_old_memory_dict}
    ``

    The new retrieved facts are mentioned in the triple backticks. You have to analyze the new retrieved facts and determine whether these facts should be added, updated, or deleted in the memory.

    ```
    {response_content}
    ```

    Do not return anything except the JSON format. 

    It should be a list of dicts, like the following example. 

    {{
        "memory":                 [
                    {{
                        "id" : "0",
                        "text" : "Name is John",
                        "event" : "UPDATE"
                    }},
                    {{
                        "id" : "1",
                        "text" : "Loves cheese pizza",
                        "event" : "DELETE"
                    }}
                ]
    }}

    Follow the instruction mentioned below:
    - Do not return anything from the custom few shot prompts provided above.
    - If the current memory is empty, then you have to add the new retrieved facts to the memory.
    - You should return the updated memory in only JSON format as shown below. The memory key should be the same if no changes are made.
    - If there is an addition, generate a new key and add the new memory corresponding to it.
    - If there is a deletion, the memory key-value pair should be removed from the memory.
    - If there is an update, the ID key should remain the same and only the value needs to be updated.
   

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

No branches or pull requests

2 participants