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 session doesn't store metadata in postgres #176

Closed
ankitgupta0110 opened this issue Sep 4, 2023 · 3 comments
Closed

Add session doesn't store metadata in postgres #176

ankitgupta0110 opened this issue Sep 4, 2023 · 3 comments

Comments

@ankitgupta0110
Copy link

ankitgupta0110 commented Sep 4, 2023

Hi,
I am using the below snippet to add a session corresponding to a user, but it is not saving the metadata in database. Next time I retrieve it, it gives error that metadata cannot be null. I have checked it in the database as well, session table doesn't have metadata.

zep_session = Session(
                session_id=str(session.id), user_id=str(user_id), metadata={'title': str(session.title), 'is_deleted': False}
            )
print("printing the session to store", zep_session)
try:
    result = self.zep_client.memory.add_session(zep_session)
    print(f"Created session {session} with result: {result}")
except APIError as e:
    print(f"Failed to create session {session}: {e}")
    return saved
@danielchalef
Copy link
Member

Would you please share your log files, the code you're using to retrieve the session, and Zep server and zep-python package versions?

@ankitgupta0110
Copy link
Author

ankitgupta0110 commented Sep 5, 2023

Here are my findings:
When messages are added to a session, the existing metadata of that session gets updated to null.
You can replicate the issue using below code snippet:

from zep_python import APIError, ZepClient
from zep_python.memory.models import Message, Memory, Session
from zep_python.user import CreateUserRequest
from zep_python.exceptions import  NotFoundError

user_id = "1234567890"
session_id = "difjidjfah12cic"
base_url = "http://localhost:8001"
user_request = CreateUserRequest(
            user_id=user_id,
            email="",
            first_name="",
            last_name="",
            metadata={"foo": "1234", "bar": "Test persona"},
        )
base_url = "http://localhost:8001"
client = ZepClient(base_url)
user = client.user.add(user_request)

zep_session = Session(
                session_id=session_id, user_id=user_id, metadata={'title': session.title, 'is_deleted': False}
            )

result = client.memory.add_session(zep_session) # adds the session with metadata

message = Message(role='Human', content='Test message') # type: ignore
memory = Memory(messages=[message])
result = client.memory.add_memory(session_id, memory) # adds memory for session_id = 'difjidjfah12cic' and updates the metadata of the session to null

I looked at the Zep Go code, and found that in the PostMemoryHandler -> PutMemory -> putMessages
, sessionStore.Update is being called with metadata as null. This Update method then updates the existing session with null metadata.
This code snippet within update method:

if session.Metadata == nil {
		return dao.updateSession(ctx, session)
	}

Currently we are using the work around of updating the session metadata ourselves after adding memory to the session. Please look into this bug.

@danielchalef
Copy link
Member

Thanks for helping identify this issue! Fixed in #180 and merged. v0.11.1, to be released shortly, includes the bug fix.

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