> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs-beta.getzep.com/v4/how-to-add-user-specific-business-data-to-user-graphs/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs-beta.getzep.com/_mcp/server. # 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. 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: **`Python`** ```python Python 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( email="cookbook@example.com", 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 ``` **`TypeScript`** ```typescript TypeScript import { ZepClient } from "@getzep/zep-cloud"; // Initialize the Zep client const client = new ZepClient({ apiKey: API_KEY }); // Create one example user. Zep generates the user UUID and the user graph UUID. const user = await client.user.create({ email: "cookbook@example.com", metadata: { app_user_id: "placeholder_user_id" }, }); // Store these values next to your application user ID. const zepUserUuid = user.uuid; const zepGraphUuid = user.graphUuid; ``` **`Go`** ```go Go import ( "context" "log" zep "github.com/getzep/zep-go/v4" "github.com/getzep/zep-go/v4/client" "github.com/getzep/zep-go/v4/graph" "github.com/getzep/zep-go/v4/option" ) // Initialize the Zep client zepClient := client.NewClient(option.WithAPIKey(API_KEY)) // Create one example user. Zep generates the user UUID and the user graph UUID. user, err := zepClient.User.Create( context.TODO(), &zep.CreateUserRequest{ Email: zep.String("cookbook@example.com"), Metadata: map[string]any{"app_user_id": "placeholder_user_id"}, }, ) if err != nil { log.Fatalf("Error: %v", err) } // Store these values next to your application user ID. zepUserUUID := *user.UUID zepGraphUUID := *user.GraphUUID ``` ## 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. **`Python`** ```python Python # 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) ``` **`TypeScript`** ```typescript TypeScript // Define the function to fetch user business data function getUserBusinessData(userIdBusiness: string): Record { // This function returns JSON data for the given user // This would vary based on your codebase return {}; } // Placeholder for business user id const userIdBusiness = "placeholder_user_id"; // This would vary based on your codebase // Retrieve the user-specific business data const userDataJson = getUserBusinessData(userIdBusiness); // Convert the business data to a string const jsonString = JSON.stringify(userDataJson); ``` **`Go`** ```go Go import ( "encoding/json" ) // Define the function to fetch user business data func getUserBusinessData(userIDBusiness string) map[string]interface{} { // This function returns JSON data for the given user // This would vary based on your codebase return map[string]interface{}{} } // Placeholder for business user id userIDBusiness := "placeholder_user_id" // This would vary based on your codebase // Retrieve the user-specific business data userDataJSON := getUserBusinessData(userIDBusiness) // Convert the business data to a string jsonBytes, err := json.Marshal(userDataJSON) if err != nil { log.Fatalf("Error: %v", err) } jsonString := string(jsonBytes) ``` ## Add the data to the user's graph Finally, add the formatted data to the user graph with the [graph API](/adding-business-data). Pass the `graph_uuid` of the user graph: **`Python`** ```python Python # Add the JSON data to the user's graph result = zep_client.graph.episode.add( zep_graph_uuid, type="json", data=json_string, ) ``` **`TypeScript`** ```typescript TypeScript // Add the JSON data to the user's graph const result = await client.graph.episode.add(zepGraphUuid, { type: "json", data: jsonString, }); ``` **`Go`** ```go Go // Add the JSON data to the user's graph episodeType := graph.V4AddEpisodeRequestTypeJSON result, err := zepClient.Graph.Episode.Add( context.TODO(), zepGraphUUID, &graph.AddEpisodeRequest{ Type: &episodeType, Data: jsonString, }, ) if err != nil { log.Fatalf("Error: %v", err) } ``` 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](/adding-business-data) for details. Check the [payload limits](/performance#optimizing-context-operations) 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. > Add business records that belong to one application user