Zep enables the use of rich, domain-specific data structures in graphs through Entity Types and Edge Types, replacing generic graph nodes and edges with detailed models.
Zep classifies newly created nodes/edges as one of the default or custom types or leaves them unclassified. For example, a node representing a preference is classified as a Preference node, and attributes specific to that type are automatically populated. You may restrict graph queries to nodes/edges of a specific type, such as Preference.
The default entity and edge types are applied to user graphs (not all graphs) by default, but you may define additional custom types as needed.
Each node/edge is classified as a single type only. Multiple classifications are not supported.
Custom entity and edge types improve graph construction by focusing extraction on the most important entities and relationships for your domain. When a custom ontology is defined, Zep’s extraction process prioritizes these types, resulting in more relevant and structured data for your use case.
Even if Zep’s default types cover your basic needs, defining a custom ontology tailored to your domain often produces better results because:
Zep provides default entity and edge types that are automatically applied to user graphs (not all graphs). These types help classify and structure the information extracted from conversations.
You can view the exact definition for the default ontology here.
The default entity types are:
The default edge types are:
Default entity and edge types apply to user graphs. All nodes and edges in any user graph will be classified into one of these types or none.
When we add data to the graph, default entity and edge types are automatically created:
When searching nodes in the graph, you may provide a list of types to filter the search by. The provided types are ORed together. Search results will only include nodes that satisfy one of the provided types:
In some cases, you may want to disable the default entity and edge types for specific users and only use custom types you define. You can do this by setting the disable_default_ontology flag when creating or updating a user.
When disable_default_ontology is set to true:
This is useful when you need precise control over your graph structure and want to ensure only domain-specific types are used.
Start with fewer, more generic custom types with minimal fields and simple definitions, then incrementally add complexity as needed. This functionality requires prompt engineering and iterative optimization of the class and field descriptions, so it’s best to start simple.
In addition to the default entity and edge types, you may specify your own custom entity and custom edge types. You need to provide a description of the type and a description for each of the fields. The syntax for this is different for each language.
You may not create more than 10 custom entity types and 10 custom edge types when setting ontology for a specific graph. The same limit of 10 custom entity types and 10 custom edge types also applies when setting ontology project-wide. The limit of 10 custom entity types does not include the default types. Each model may have up to 10 fields.
When creating custom entity or edge types, you may not use the following attribute names (including in Go struct tags), as they conflict with default node attributes: uuid, name, graph_id, name_embedding, summary, and created_at.
Including attributes on custom entity and edge types is an advanced feature designed for precision context engineering where you only want to utilize specific field values when constructing your context block. See here for an example. Many agent memory use cases can be solved with node summaries and facts alone. Custom attributes should only be added when you need structured field values for precise context retrieval rather than general conversational context.
You can set these custom entity and edge types as the graph ontology for your current Zep project. The ontology can be applied either project-wide to all users and graphs, or targeted to specific users and graphs only.
When no user IDs or graph IDs are provided, the ontology is set for the entire project. All users and graphs within the project will use this ontology. Note that for custom edge types, you can require the source and destination nodes to be a certain type, or allow them to be any type:
You can also set the ontology for specific users and/or graphs by providing user IDs and graph IDs. When these parameters are provided, the ontology will only apply to the specified users and graphs, while other users and graphs in the project will continue using the previously set ontology (whether that was due to a project-wide setting of ontology or due to a graph-specific setting of ontology):
Now, when you add data to the graph, new nodes and edges are classified into exactly one of the overall set of entity or edge types respectively, or no type:
Once you’ve created custom entity and edge types in your graph, you’ll typically want to retrieve information filtered by these specific types. There are two primary approaches:
Context templates provide a convenient way to create context blocks that filter by your custom entity and edge types. You define a template once and Zep automatically retrieves and formats the relevant information.
Context templates support the types parameter on %{entities} and %{edges} variables to filter by your custom types:
The resulting context block will automatically include only the specified types, formatted according to your template:
Learn more about context templates in the Context Templates documentation.
For more granular control or dynamic queries, you can use graph search to filter by entity or edge types. Graph search is ideal when you need to specify custom search queries, want direct access to individual nodes or edges, or are building dynamic filtering based on runtime conditions.
Search for entities (nodes) by filtering on custom entity types using the node_labels parameter:
You can provide multiple types in search filters, and the types will be ORed together. For example, searching with edge_types: ["DIETARY_PREFERENCE", "RESTAURANT_VISIT"] will return edges matching either type.
Some notes regarding custom entity and edge types:
set_ontology method overwrites any previously defined custom entity and edge types, so the set of custom entity and edge types is always the list of types provided in the last set_ontology method calluuid, name, graph_id, name_embedding, summary, and created_at