Graph Models¶
These models define the persisted graph schema used across ingestion, retrieval, memory, and deduplication. Node, Relationship, and KnowledgeGraph are the core durable shapes; DocumentNode, ChunkNode, and MemoryNode are specialized system node types layered on top.
grawiki.graph.models
¶
Pydantic models used to represent the knowledge graph.
GraphModel
¶
Bases: BaseModel
Base class for graph models.
Notes
Graph outputs are kept strict so extractors cannot silently add unsupported fields.
Node
¶
Bases: GraphModel
Graph node representing one concrete entity or concept.
Field-level descriptions document the persisted schema in detail. The
labels field supports multi-label entities, while semantic_key provides
a stable deduplication-oriented identifier derived from the node type and
name.
ChunkNode
¶
Bases: Node
Graph node representing one source chunk.
Chunk nodes are system-owned nodes linked back to a parent
:class:DocumentNode and typically carry both raw chunk text and an
embedding for retrieval.
from_chunk
classmethod
¶
from_chunk(chunk, *, name=None)
Create a chunk node from a source chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk
|
Chunk
|
Source chunk to represent in the graph. |
required |
name
|
str | None
|
Optional human-readable name. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
ChunkNode
|
Chunk represented as a graph node. |
DocumentNode
¶
Bases: Node
Graph node representing one source document.
Document nodes store the source text and metadata for an ingested document and can also carry a document-level embedding.
from_document
classmethod
¶
from_document(document)
Create a document node from a source document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
Document
|
Source document to represent in the graph. |
required |
Returns:
| Type | Description |
|---|---|
DocumentNode
|
Document represented as a graph node. |
MemoryNode
¶
Bases: Node
Graph node representing one stored memory.
Memory nodes capture persisted agent-facing notes or summaries and can be searched and expanded through connected graph context.
Relationship
¶
Bases: GraphModel
Directed relationship between two graph nodes.
Relationships are persisted with explicit source and target node ids plus a short type label and optional factual properties.
KnowledgeGraph
¶
Bases: GraphModel
Knowledge graph consisting of nodes and relationships.
This is the durable in-memory graph container passed between extraction, persistence, and higher-level workflows.