Skip to navigation

Add User Specific Business Data to User Graphs

Add business records that belong to one application user

This guide demonstrates how to add user-specific business data to a user’s knowledge graph. We’ll create a user, fetch their business data, and add it to their graph.

Create a user

First, we will initialize our client and create a new user. Zep generates the user uuid and the graph_uuid of the user graph. Store both values in your application database next to your own user ID:

from zep_cloud.client import Zep
# Initialize the Zep client
zep_client = Zep(api_key=API_KEY)
# Create one example user. Zep generates the user UUID and the user graph UUID.
user = zep_client.user.create(
metadata={"app_user_id": "placeholder_user_id"},
)
# Store these values next to your application user ID.
zep_user_uuid = user.uuid_
zep_graph_uuid = user.graph_uuid

Fetch and format the business data

Then, we will fetch and format the user’s business data. Note that the functionality to fetch a users business data will depend on your codebase.

Zep does not accept your internal user IDs as Zep identifiers. Keep your internal user ID in your database next to zep_user_uuid and zep_graph_uuid, and use your internal ID to fetch the business data.

# Define the function to fetch user business data
def get_user_business_data(user_id_business):
# This function returns JSON data for the given user
# This would vary based on your codebase
return {}
# Placeholder for business user id
user_id_business = "placeholder_user_id" # This would vary based on your codebase
# Retrieve the user-specific business data
user_data_json = get_user_business_data(user_id_business)
# Convert the business data to a string
json_string = json.dumps(user_data_json)

Add the data to the user’s graph

Finally, add the formatted data to the user graph with the graph API. Pass the graph_uuid of the user graph:

# Add the JSON data to the user's graph
result = zep_client.graph.episode.add(
zep_graph_uuid,
type="json",
data=json_string,
)

This example uses type="json". The graph API also supports type="text" and type="message".

Use type="text" for unstructured text, such as internal documents. Use type="message" for messages outside a user’s chat history, such as email.

Read Adding business data for details.

Check the payload limits before you add data to a graph.

Summary

You have now successfully added user-specific business data to a user’s knowledge graph, which can be used alongside chat history to create user context.