Skip to navigation

Create a Context Graph

Create shared or domain context that is not owned by one Zep user

Overview

Create a shared Context Graph when the context belongs to a customer account, project, product, organization, or business domain instead of one application user. The API addresses this graph with graph_id.

When to create a Context Graph

Create a graph when you need to:

  • Create shared knowledge bases across multiple users
  • Build domain-specific knowledge graphs independent of user context
  • Maintain separate graphs for testing or experimentation
  • Implement custom graph architectures for specialized use cases

Use a user graph when the context belongs to one application user and the application needs Zep users, threads, user summaries, or thread.get_user_context.

Create the graph

from zep_cloud.client import Zep
client = Zep(
api_key=API_KEY,
)
# Create a Context Graph with a custom ID
result = client.graph.create(
graph_id="support-emea",
name="EMEA Support",
description="Customer support cases and escalation history for EMEA.",
)
print(f"Created graph with ID: {result.graph_id}")

Bind a content policy

A new graph copies the current project content policy when you create it. The optional content_policy field of the create body adds categories and rules to that policy, and content_policy.project_revision rejects the create with 409 content_policy_revision_stale when the project policy changed after you read it. The bound policy is read-only after creation. When a graph needs a different policy, create a new graph.

Describe graphs for routing

Set a distinct name and description when agents can access more than one Context Graph. The graph directory searches graph_id, name, and description, so the description should state what an agent should query the graph for and what the graph does not contain.

Seed the graph

A shared Context Graph created with graph_id starts empty. A user graph starts with a user node that represents its subject. A shared Context Graph has no node until you add data. Before you add ongoing data, seed the graph with facts about its subject. Later data can then attach to a well-formed subject.

For example, give a new company graph the company’s name, industry, and key people. Seed it by adding episodes with graph.add, by asserting known relationships with add_fact_triple, or both.

Work with the graph

After creation, you can use the same graph methods that apply to user graphs:

Customizing Graph Structure

You can customize these Context Graphs with entity and edge types. See Customizing Graph Structure for details.

Next Steps