Add User Specific Business Data to User Graphs

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:

1# Initialize the Zep client
2zep_client = Zep(api_key=API_KEY)
3
4# Add one example user
5user_id_zep = uuid.uuid4().hex
6zep_client.user.add(
7 user_id=user_id_zep,
8 email="[email protected]"
9)

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.

Also note that you could make your Zep user IDs equal to whatever internal user IDs you use to make things easier to manage. Generally, Zep user IDs, thread IDs, Graph IDs, etc. can be arbitrary strings, and can map to your app’s data schema.

1# Define the function to fetch user business data
2def get_user_business_data(user_id_business):
3 # This function returns JSON data for the given user
4 # This would vary based on your codebase
5 return {}
6
7# Placeholder for business user id
8user_id_business = "placeholder_user_id" # This would vary based on your codebase
9
10# Retrieve the user-specific business data
11user_data_json = get_user_business_data(user_id_business)
12
13# Convert the business data to a string
14json_string = json.dumps(user_data_json)

Add the data to the user’s graph

Finally, add the formatted data to the user’s graph with the graph API:

1# Add the JSON data to the user's graph
2zep_client.graph.add(
3 user_id=user_id_zep,
4 type="json",
5 data=json_string,
6)

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.