Fundamental part of the Zep Memory Store

You are viewing the Zep Open Source v0.x documentation. This version is no longer supported, and documentation is provided as a reference only.

The current documentation for Zep Community Edition is available here.

Just like Sessions, Users are a fundamental part of the Zep Memory Store. A User represents an individual interacting with your application. Each User can have multiple Sessions associated with them, allowing you to track and manage the interactions of a user over time.

The UserID is a unique identifier for each user. This can be any string value - for example, it could be a username, an email address, or a UUID. You can also store additional data related to the user in the metadata field.

The User object and its associated Sessions provide a powerful way to manage and understand the behavior of individuals using your application. By associating Sessions with Users, you can track the progression of conversations and interactions over time, providing valuable context and history.

In the following sections, you will learn how to manage Users and their associated Sessions.

The User model

You can associate rich business context with a User:

  • user_id: A unique identifier of the user that maps to your internal User ID.
  • email: The user’s email.
  • first_name: The user’s first name.
  • last_name: The user’s last name.
  • metadata: Any additional data associated with the user.

Adding a User

You can add a new user by providing the user details.

Python

1user_request = CreateUserRequest(
2 user_id=user_id,
3 email="[email protected]",
4 first_name="Jane",
5 last_name="Smith",
6 metadata={"foo": "bar"},
7)
8new_user = client.user.add(user_request)

TypeScript

1const user: ICreateUserRequest = {
2 user_id: "user123",
3 metadata: { foo: "bar" },
4};
5const newUser = await client.user.add(user);

Learn how to associate Sessions with Users

Getting a User

You can retrieve a user by their ID.

Python

1user = client.user.get("user123")

TypeScript

1const user = await client.user.get("user123");

Updating a User

You can update a user’s details by providing the updated user details.

Python

1user_request = UpdateUserRequest(
2 user_id=user_id,
3 email="[email protected]",
4 first_name="Jane",
5 last_name="Smith",
6 metadata={"foo": "updated_bar"},
7)
8updated_user = client.user.update(user_request)

TypeScript

1const user: IUpdateUserRequest = {
2 user_id: "user123",
3 metadata: { foo: "baz" },
4};
5const updatedUser = await client.user.update(user);

Deleting a User

You can delete a user by their ID.

Python

1client.user.delete("user123")

TypeScript

1await client.user.delete("user123");

Getting a User’s Sessions

You can retrieve all Sessions for a user by their ID.

Python

1# Get all sessions for user123
2sessions = client.user.get_sessions("user123")

TypeScript

1// Get all sessions for user123
2const sessions = await client.user.getSessions("user123");

Listing Users

You can list all users, with optional limit and cursor parameters for pagination.

Python

1# List the first 10 users
2users = client.user.list(limit=10, cursor=0)

TypeScript

1// List the first 10 users
2const users = await client.user.list(10, 0);

Listing Users in Chunks

You can retrieve users in chunks of a specified size. This is a generator function that yields each chunk of users as they are retrieved.

Python

1for users in client.user.list_chunked(chunkSize=100):
2 process(users)

TypeScript

1for await (const users of client.user.listChunked(100)) {
2 process(users);
3}