Skip to content

Schema Configuration

GraphSchema

Bases: BaseConfig

Schema for a graph, including nodes and edges.

graph_name = Field(description='The name of the graph.') class-attribute instance-attribute

nodes = Field(description='A dictionary of node type names to their schemas.') class-attribute instance-attribute

edges = Field(description='A dictionary of edge type names to their schemas.') class-attribute instance-attribute

validate_edge_references()

Ensure all edges reference existing nodes in the graph schema.

Returns:

Raises:

  • ValueError

    If any edge references undefined node types.

NodeSchema

Bases: BaseConfig

Schema for a graph node type.

primary_key = Field(description='The primary key for the node type.') class-attribute instance-attribute

attributes = Field(default_factory=dict, description='A dictionary of attribute names to their schemas.') class-attribute instance-attribute

vector_attributes = Field(default_factory=dict, description='A dictionary of vector attribute names to their schemas.') class-attribute instance-attribute

parse_attributes(values)

Parse shorthand attributes into full AttributeSchema.

Parameters:

  • values (Dict[str, Any]) –

    Input values.

Returns:

  • Dict[str, Any]

    Parsed values with attributes as AttributeSchema.

validate_primary_key_and_attributes()

Validate that the primary key is present in attributes.

Returns:

Raises:

  • ValueError

    If the primary key is not defined in attributes.

EdgeSchema

Bases: BaseConfig

Schema for a graph edge type.

is_directed_edge = Field(default=False, description='Whether the edge is directed.') class-attribute instance-attribute

from_node_type = Field(description='The type of the source node.') class-attribute instance-attribute

to_node_type = Field(description='The type of the target node.') class-attribute instance-attribute

discriminator = Field(default_factory=set, description='An attribute or set of attributes that uniquely identifies an edge in a graph, distinguishing it from other edges with the same source and target.') class-attribute instance-attribute

attributes = Field(default_factory=dict, description='A dictionary of attribute names to their schemas.') class-attribute instance-attribute

parse_attributes(values)

Parse shorthand attributes into full AttributeSchema.

Parameters:

  • values (Dict[str, Any]) –

    Input values.

Returns:

  • Dict[str, Any]

    Parsed values with attributes as AttributeSchema.

validate_discriminator_and_attributes()

Validate that every discriminator is present in attributes.

Returns:

Raises:

  • ValueError

    If any discriminator is not defined in attributes.

AttributeSchema

Bases: BaseConfig

Schema for a graph attribute.

data_type = Field(description='The data type of the attribute.') class-attribute instance-attribute

default_value = Field(default=None, description='The default value for the attribute.') class-attribute instance-attribute

PYTHON_TYPES = {DataType.INT: int, DataType.UINT: int, DataType.FLOAT: (float, int), DataType.DOUBLE: (float, int), DataType.BOOL: bool, DataType.STRING: str, DataType.DATETIME: str} class-attribute

validate_default_value()

Validate that the default value matches the expected data type.

Returns:

Raises:

  • TypeError

    If the default value does not match the expected data type.

VectorAttributeSchema

Bases: BaseConfig

Schema for a vector attribute.

dimension = Field(ge=1, default=1536, description='The dimension of the vector attribute. Must be at least 1.') class-attribute instance-attribute

index_type = Field(default='HNSW', description='The index type for the vector attribute. Currently only "HNSW" is supported.') class-attribute instance-attribute

data_type = Field(default='FLOAT', description='The data type of the attribute. Currently only "FLOAT" is supported. Future types may include "DOUBLE", "HALF", or "BYTE".') class-attribute instance-attribute

metric = Field(default='COSINE', description='The metric used for distance calculations. Can be "COSINE", "IP" (inner product), or "L2".') class-attribute instance-attribute

DataType

Bases: Enum

Enumeration of supported data types.

INT = 'INT' class-attribute instance-attribute

Represents an integer type.

UINT = 'UINT' class-attribute instance-attribute

Represents an unsigned integer type.

FLOAT = 'FLOAT' class-attribute instance-attribute

Represents a floating-point type.

DOUBLE = 'DOUBLE' class-attribute instance-attribute

Represents a double-precision floating-point type.

BOOL = 'BOOL' class-attribute instance-attribute

Represents a boolean type.

STRING = 'STRING' class-attribute instance-attribute

Represents a string type.

DATETIME = 'DATETIME' class-attribute instance-attribute

Represents a datetime type.