experimental[patch]: Flatten relationships in LLM graph transformer (#19642)

pull/19531/head^2
Tomaz Bratanic 2 months ago committed by GitHub
parent 36abb5dd41
commit b04e663426
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -112,8 +112,18 @@ def create_simple_model(
class SimpleRelationship(BaseModel):
"""Represents a directed relationship between two nodes in a graph."""
source: SimpleNode = Field(description="The source node of the relationship.")
target: SimpleNode = Field(description="The target node of the relationship.")
source_node_id: str = Field(
description="Name or human-readable unique identifier of source node"
)
source_node_type: str = optional_enum_field(
node_labels, description="The type or label of the source node."
)
target_node_id: str = Field(
description="Name or human-readable unique identifier of target node"
)
target_node_type: str = optional_enum_field(
node_labels, description="The type or label of the target node."
)
type: str = optional_enum_field(
rel_types, description="The type of the relationship.", is_rel=True
)
@ -136,8 +146,8 @@ def map_to_base_node(node: Any) -> Node:
def map_to_base_relationship(rel: Any) -> Relationship:
"""Map the SimpleRelationship to the base Relationship."""
source = map_to_base_node(rel.source)
target = map_to_base_node(rel.target)
source = Node(id=rel.source_node_id.title(), type=rel.source_node_type.capitalize())
target = Node(id=rel.target_node_id.title(), type=rel.target_node_type.capitalize())
return Relationship(
source=source, target=target, type=rel.type.replace(" ", "_").upper()
)

Loading…
Cancel
Save