Skip to content

Schema

Module for representing graph documents and their components.

Authors

Douglas Raevan Faisal (douglas.r.faisal@gdplabs.id)

References

[1] https://github.com/langchain-ai/langchain-community/blob/490057c052f00f4ef47ad843df294e473fcfb4c8/libs/community/langchain_community/graphs/graph_document.py

GraphDocument

Bases: BaseModel

Represents a graph document consisting of nodes and relationships.

Attributes:

Name Type Description
nodes list[Node]

A list of nodes in the graph.

relationships list[Relationship]

A list of relationships in the graph.

source Chunk | None

The document from which the graph information is derived.

GraphResponse

Bases: BaseModel

Represents a graph response generated by LM Invoker containing nodes and relationships.

Attributes:

Name Type Description
nodes list[SimpleNode] | None

A list of nodes generated by LM Invoker.

relationships list[SimpleRelationship] | None

A list of relationships generated by LM Invoker.

InputType

Bases: StrEnum

Enum for input types used in graph element descriptions.

Node

Bases: BaseModel

Represents a node in a graph with associated properties.

Attributes:

Name Type Description
id str

A unique identifier for the node.

type str

The type or label of the node. Defaults to "Node".

properties dict

Additional properties and metadata associated with the node.

Relationship

Bases: BaseModel

Represents a directed relationship between two nodes in a graph.

Attributes:

Name Type Description
source Node

The source node of the relationship.

target Node

The target node of the relationship.

type str

The type of the relationship. Defaults to "Relationship".

properties dict

Additional properties associated with the relationship.

RelationshipTypeFormat

Bases: StrEnum

Enum for relationship type formats.

This enum defines the valid formats for specifying relationship types: - STRING: Relationship types are specified as simple strings (e.g., "WORKS_AT") - TUPLE: Relationship types are specified as 3-tuples in the format (source_type, relationship_type, target_type)

SimpleNode

Bases: BaseModel

Represents a node in a graph with associated properties.

This class is to be used as the schema for the LMInvoker's structured output.

Attributes:

Name Type Description
id str

A unique identifier for the node.

type str

The type or label of the node. Defaults to "Node".

SimpleRelationship

Bases: BaseModel

Represents a simple directed relationship between two nodes in a graph.

This class is to be used as the schema for the LMInvoker's structured output.

Attributes:

Name Type Description
source_node_id str

The ID of the source node.

source_node_type str

The type of the source node.

target_node_id str

The ID of the target node.

target_node_type str

The type of the target node.

type str

The type of the relationship.