Node¶
A Node is a single vertex in a Graph. It is an immutable, frozen dataclass — you cannot mutate it in place. Instead, use Node.evolve() to produce an updated copy.
Immutability and Versioning¶
Every time you call evolve(), the version counter increments and updated_at is refreshed. This makes change history traceable.
from knowledge_platform.core.node import Node
from knowledge_platform.core.identifiers import new_graph_id
graph_id = new_graph_id()
# Create a fresh node
node = Node.create(graph_id, "OutlineItem", {"title": "Introduction"})
print(node.version) # 1
# Produce an updated copy — the original is unchanged
updated = node.evolve(title="Chapter 1: Introduction", content="Body text here")
print(updated.version) # 2
print(updated.attributes) # {"title": "Chapter 1: Introduction", "content": "Body text here"}
print(node.attributes["title"]) # "Introduction" (original unchanged)
Attribute Payload¶
The attributes dict can hold any JSON-serialisable values. The semantic meaning and allowed keys are defined by the NodeSchema registered on the graph's GraphType. It is the responsibility of GraphService.add_node() to validate attributes before they reach the core.
Identity and Ownership¶
| Field | Type | Meaning |
|---|---|---|
id |
NodeId |
Globally unique identifier (UUID v4) |
graph_id |
GraphId |
The owning graph |
type_name |
str |
Semantic type (e.g. "OutlineItem") |
version |
int |
Incremented on every evolve() call |
API Reference¶
knowledge_platform.core.node.Node
dataclass
¶
A single vertex in a :class:~knowledge_platform.core.graph.Graph.
Nodes are immutable value-objects. Mutations produce new instances via
:meth:evolve, which increments the version counter.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
NodeId
|
Unique identifier for this node. |
graph_id |
GraphId
|
Owning graph identifier. |
type_name |
str
|
Semantic type string, resolved by the active
:class: |
attributes |
dict[str, object]
|
Arbitrary key-value payload; must be JSON-serialisable. |
version |
int
|
Monotonically increasing change counter (starts at 1). |
created_at |
datetime
|
Timestamp of initial creation (UTC). |
updated_at |
datetime
|
Timestamp of the most recent update (UTC). |
Source code in src/knowledge_platform/core/node.py
Functions¶
create
classmethod
¶
Factory method that generates a fresh node with a new identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
The owning graph. |
required |
type_name
|
str
|
Semantic type registered on the graph's
:class: |
required |
attributes
|
dict[str, object] | None
|
Optional initial attribute payload. |
None
|
Returns:
| Type | Description |
|---|---|
'Node'
|
A new :class: |
Source code in src/knowledge_platform/core/node.py
evolve ¶
Return a new :class:Node with merged attribute_updates.
The version is incremented and updated_at is refreshed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**attribute_updates
|
object
|
Attribute keys/values to merge. |
{}
|
Returns:
| Type | Description |
|---|---|
'Node'
|
Updated immutable :class: |