Entity nodes, but you can define structured types with specific attributes.
Why Custom Entities?
Custom entity definitions enable:- Structured Extraction - Extract specific attributes (e.g.,
first_name,occupation) - Type Safety - Ensure entities have required fields
- Domain Modeling - Model your specific domain (e.g., Products, Locations, Events)
- Better Search - Filter and query by entity type and attributes
- Schema Enforcement - Validate extracted data against your schema
Defining Entity Types
Entity types are defined using PydanticBaseModel classes:
Entity type names (class names) become labels in the graph. The class docstring helps the LLM understand when to use this type.
Using Custom Entities
Pass your entity types when adding episodes:Entity Type Dictionary
Theentity_types parameter is a dictionary mapping type names to Pydantic models:
Defining Relationship Types
Define custom edge types to model specific relationships:Relationship types can be empty classes. The class name and docstring guide the LLM on when to use each type.
Edge Type Mapping
Define which relationships can exist between entity types using an edge type map:Complete Example
Here’s a full example with custom entities and relationships:Excluding Entity Types
Exclude certain entity types from extraction:Entity type:
Field Descriptions
Provide clear field descriptions to guide extraction:Optional vs Required Fields
All fields should be optional (| None) since the LLM may not always extract every attribute:
Attribute Access
Extracted attributes are stored in theattributes dict:
Bulk Operations with Custom Types
Custom types work with bulk episode ingestion:Best Practices
Clear Docstrings
Write descriptive docstrings to help the LLM identify when to use each type
Specific Descriptions
Provide detailed field descriptions including format and units
Optional Fields
Make all fields optional to handle incomplete extractions
Consistent Naming
Use consistent naming conventions for types and fields
Common Patterns
Temporal Entities
Hierarchical Relationships
Validation
Custom entity types are validated when provided:Next Steps
Adding Episodes
Use custom entities when adding content
Searching
Search for entities by type and attributes
Bulk Operations
Use custom types in bulk ingestion