graflo.architecture.graph_types¶
Graph runtime types and data structures (extraction, assembly, containers).
This package defines graph-processing data structures used across the ingestion pipeline and database adapters. It provides:
- Core data types for vertices and edges
- Database index configurations
- Graph container implementations
- Edge mapping and casting utilities
- Action context for graph transformations
The package is designed to be database-agnostic, supporting both ArangoDB and Neo4j through the DBType enum. It provides a unified interface for working with graph data structures while allowing for database-specific optimizations and features.
Submodules (for lighter imports):
identifiers— vertex/edge id aliases and edge-key serializationenums— EdgeMapping, EncodingType, IndexType, EdgeType, EdgeDirection, EdgeCastingTypeindex_config— ABCFields, Weight, Indexcontainer— GraphContainerlocation— LocationIndex, ProvenancePathtransform— TransformPayload, VertexRep, merge helperscontext— ExtractionContext, AssemblyContext, observations, ActionContext
Modules:
| Name | Description |
|---|---|
container |
Graph data container for vertices and edges. |
context |
Extraction and assembly runtime contexts. |
edge_derivation |
Edge-derivation wiring shared by contract (authoring) and pipeline (runtime). |
enums |
Graph runtime enumerations. |
identifiers |
Graph identifier aliases and edge-key serialization. |
index_config |
Index and weight configuration models. |
location |
Location indexing for nested graph traversal. |
merge |
Document fusion: several observations of one entity becoming one document. |
transform |
Transform payloads and observation merging. |
Attributes¶
EdgeId = tuple[str, str, str | None]
module-attribute
¶
EdgePhysicalKey = tuple[str, str, str | None, str | None]
module-attribute
¶
GraphEntity = str | EdgeId
module-attribute
¶
VertexName = str
module-attribute
¶
__all__ = ['ABCFields', 'ActionContext', 'AssemblyContext', 'EdgeCastingType', 'EdgeDirection', 'EdgeId', 'EdgeIntent', 'EdgeMapping', 'EdgePhysicalKey', 'EdgeType', 'EncodingType', 'ExtractionContext', 'GraphAssemblyResult', 'GraphContainer', 'GraphEntity', 'Index', 'IndexType', 'ItemsView', 'LocationIndex', 'ProvenancePath', 'ResourceCastResult', 'TransformCastFailure', 'TransformObservation', 'TransformPayload', 'VertexName', 'VertexObservation', 'VertexRep', 'Weight', 'context_dict_from_transform_buffer_item', 'deserialize_edge_key', 'merge_observation_with_transform_buffer', 'serialize_edge_key']
module-attribute
¶
Classes¶
ABCFields
¶
Bases: ConfigBaseModel
Base model for entities that have fields.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
Optional name of the entity |
fields |
list[str]
|
List of field names |
Source code in graflo/architecture/graph_types/index_config.py
Attributes¶
fields = Field(default_factory=list, description='List of field names for this entity.')
class-attribute
instance-attribute
¶
keep_vertex_name = Field(default=True, description='If True, composite field names use entity@field format; otherwise use field only.')
class-attribute
instance-attribute
¶
name = Field(default=None, description='Optional name of the entity (e.g. vertex name for composite field prefix).')
class-attribute
instance-attribute
¶
Methods:¶
cfield(x)
¶
Creates a composite field name by combining the entity name with a field name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str
|
Field name to combine with entity name |
required |
Returns:
| Type | Description |
|---|---|
str
|
Composite field name in format "entity@field" |
Source code in graflo/architecture/graph_types/index_config.py
ActionContext
¶
Bases: ExtractionContext
Backward-compatible extraction+assembly context.
Kept for existing callers/tests while Wave 5 migrates call surfaces.
Source code in graflo/architecture/graph_types/context.py
AssemblyContext
¶
Bases: ConfigBaseModel
Assembly-phase context built from extraction outputs.
Source code in graflo/architecture/graph_types/context.py
Attributes¶
acc_global = Field(default_factory=dd_factory)
class-attribute
instance-attribute
¶
acc_vertex
property
¶
edge_intents
property
¶
extraction
instance-attribute
¶
model_config = ConfigDict(kw_only=True)
class-attribute
instance-attribute
¶
obs_buffer
property
¶
transform_buffer
property
¶
Methods:¶
EdgeCastingType
¶
Bases: BaseEnum
Types of edge casting supported.
PAIR: Edges are cast as pairs of vertices PRODUCT: Edges are cast as combinations of vertex sets
Source code in graflo/architecture/graph_types/enums.py
EdgeDirection
¶
Bases: BaseEnum
Which orientations a read follows, relative to the anchor vertex.
OUT: anchor is the edge source (the historical, and still default, behaviour) IN: anchor is the edge target ANY: either orientation — the correct reading of a logically undirected edge
Not every backend can answer every value. Reverse reachability is free or
cheap on most targets but is fixed at DDL time on TigerGraph; see
:mod:graflo.db.edge_direction_support.
Source code in graflo/architecture/graph_types/enums.py
EdgeIntent
¶
Bases: ConfigBaseModel
Typed edge assembly request emitted during extraction.
Source code in graflo/architecture/graph_types/context.py
EdgeMapping
¶
Bases: BaseEnum
Defines how edges are mapped between vertices.
ALL: Maps all vertices to all vertices ONE_N: Maps one vertex to many vertices
Source code in graflo/architecture/graph_types/enums.py
EdgeType
¶
Bases: BaseEnum
Defines how edges are handled in the graph database.
INDIRECT: Uses pre-existing DB structures and may be used after data ingestion DIRECT: Generated during ingestion from resource pipelines
Source code in graflo/architecture/graph_types/enums.py
EncodingType
¶
Bases: BaseEnum
Supported character encodings for data input/output.
Source code in graflo/architecture/graph_types/enums.py
ExtractionContext
¶
Bases: ConfigBaseModel
Extraction-phase context.
Attributes:
| Name | Type | Description |
|---|---|---|
acc_vertex |
Any
|
Local accumulation of extracted vertices |
transform_buffer |
Any
|
Buffer for transform payloads (defaultdict[LocationIndex, list]) |
obs_buffer |
Any
|
Merged observation context per location (dict[LocationIndex, dict]) |
vertex_observations |
list[VertexObservation]
|
Explicit extracted vertex observations |
transform_observations |
list[TransformObservation]
|
Explicit extracted transform observations |
edge_intents |
list[EdgeIntent]
|
Explicit edge intents for assembly phase |
Source code in graflo/architecture/graph_types/context.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
Attributes¶
acc_vertex = Field(default_factory=outer_factory)
class-attribute
instance-attribute
¶
edge_intents = Field(default_factory=_default_edge_intents)
class-attribute
instance-attribute
¶
model_config = ConfigDict(kw_only=True)
class-attribute
instance-attribute
¶
obs_buffer = Field(default_factory=_default_dict_observations)
class-attribute
instance-attribute
¶
transform_buffer = Field(default_factory=_default_dict_transforms)
class-attribute
instance-attribute
¶
transform_failures = Field(default_factory=_default_transform_failures)
class-attribute
instance-attribute
¶
transform_observations = Field(default_factory=_default_transform_observations)
class-attribute
instance-attribute
¶
vertex_observations = Field(default_factory=_default_vertex_observations)
class-attribute
instance-attribute
¶
Methods:¶
record_edge_intent(*, edge, location, derivation=None)
¶
Source code in graflo/architecture/graph_types/context.py
record_transform_failure(*, location, transform_label, exc, traceback_text, nulled_fields)
¶
Source code in graflo/architecture/graph_types/context.py
record_transform_observation(*, location, payload)
¶
Source code in graflo/architecture/graph_types/context.py
record_vertex_observation(*, vertex_name, location, vertex, ctx)
¶
Source code in graflo/architecture/graph_types/context.py
GraphAssemblyResult
¶
Bases: ConfigBaseModel
Result of graph assembly phase.
Source code in graflo/architecture/graph_types/context.py
GraphContainer
¶
Bases: ConfigBaseModel
Container for graph data including vertices and edges.
Attributes:
| Name | Type | Description |
|---|---|---|
vertices |
dict[VertexName, list]
|
Dictionary mapping vertex names to lists of vertex data |
edges |
dict[tuple[str, str, str | None], list]
|
Dictionary mapping edge IDs to lists of edge data |
linear |
list[defaultdict[str | tuple[str, str, str | None], list[Any]]]
|
List of default dictionaries containing linear data |
Source code in graflo/architecture/graph_types/container.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
Attributes¶
edges = Field(default_factory=dict)
class-attribute
instance-attribute
¶
linear = Field(default_factory=list)
class-attribute
instance-attribute
¶
vertices = Field(default_factory=dict)
class-attribute
instance-attribute
¶
Methods:¶
from_docs_list(list_default_dicts)
classmethod
¶
Create a GraphContainer from a list of default dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_default_dicts
|
list[defaultdict[GraphEntity, list]]
|
List of default dictionaries containing vertex and edge data |
required |
Returns:
| Type | Description |
|---|---|
GraphContainer
|
New GraphContainer instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If edge IDs are not properly formatted |
Source code in graflo/architecture/graph_types/container.py
items()
¶
pick_unique()
¶
Remove duplicate entries from vertices and edges.
Source code in graflo/architecture/graph_types/container.py
Index
¶
Bases: ConfigBaseModel
Configuration for database indexes.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
Optional name of the index |
fields |
list[str]
|
List of fields to index |
unique |
bool
|
Whether the index enforces uniqueness |
type |
IndexType
|
Type of index to create |
deduplicate |
bool
|
Whether to deduplicate index entries |
sparse |
bool
|
Whether to create a sparse index |
exclude_edge_endpoints |
bool
|
Whether to exclude edge endpoints from index |
Source code in graflo/architecture/graph_types/index_config.py
Attributes¶
deduplicate = Field(default=True, description='Whether to deduplicate index entries (e.g. ArangoDB).')
class-attribute
instance-attribute
¶
exclude_edge_endpoints = Field(default=False, description='If True, do not add _from/_to to edge index (e.g. ArangoDB).')
class-attribute
instance-attribute
¶
fields = Field(default_factory=list, description='List of field names included in this index.')
class-attribute
instance-attribute
¶
name = Field(default=None, description='Optional index name. For edges, can reference a vertex name for composite fields.')
class-attribute
instance-attribute
¶
sparse = Field(default=False, description='If True, create a sparse index (exclude null/missing values).')
class-attribute
instance-attribute
¶
type = Field(default=IndexType.PERSISTENT, description='Index type (PERSISTENT, HASH, SKIPLIST, FULLTEXT).')
class-attribute
instance-attribute
¶
unique = Field(default=True, description='If True, index enforces uniqueness on the field combination.')
class-attribute
instance-attribute
¶
Methods:¶
__iter__()
¶
db_form(db_type)
¶
Convert index configuration to database-specific format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_type
|
DBType
|
Type of database (ARANGO or NEO4J) |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of index configuration in database-specific format |
Raises:
| Type | Description |
|---|---|
ValueError
|
If db_type is not supported |
Source code in graflo/architecture/graph_types/index_config.py
IndexType
¶
Bases: BaseEnum
Types of database indexes supported.
PERSISTENT: Standard persistent index HASH: Hash-based index for fast lookups SKIPLIST: Sorted index using skip list data structure FULLTEXT: Index optimized for text search
Source code in graflo/architecture/graph_types/enums.py
ItemsView
¶
View class for iterating over vertices and edges in a GraphContainer.
Source code in graflo/architecture/graph_types/container.py
LocationIndex
¶
Bases: ConfigBaseModel
Immutable location index for nested graph traversal.
Source code in graflo/architecture/graph_types/location.py
Attributes¶
model_config = ConfigDict(frozen=True)
class-attribute
instance-attribute
¶
path = Field(default_factory=tuple)
class-attribute
instance-attribute
¶
Methods:¶
__contains__(item)
¶
__getitem__(item)
¶
__init__(*args, **kwargs)
¶
Allow LocationIndex((0,)) or LocationIndex(path=(0,)).
Source code in graflo/architecture/graph_types/location.py
__iter__()
¶
__len__()
¶
__lt__(other)
¶
accept_tuple(data)
classmethod
¶
Accept a single tuple as positional path (e.g. LocationIndex((0,))).
Source code in graflo/architecture/graph_types/location.py
congruence_measure(other)
¶
depth()
¶
extend(extension)
¶
filter(lindex_list)
¶
ProvenancePath
¶
Bases: ConfigBaseModel
Explicit provenance path for extracted observations.
Source code in graflo/architecture/graph_types/location.py
ResourceCastResult
¶
Bases: ConfigBaseModel
Outcome of casting one document through a resource pipeline.
Source code in graflo/architecture/graph_types/context.py
TransformCastFailure
¶
Bases: ConfigBaseModel
One transform step that failed during extraction (tolerance mode).
Source code in graflo/architecture/graph_types/context.py
TransformObservation
¶
Bases: ConfigBaseModel
Typed transform observation emitted during extraction.
Source code in graflo/architecture/graph_types/context.py
TransformPayload
¶
Bases: ConfigBaseModel
Typed transform output shared between extraction and assembly phases.
Source code in graflo/architecture/graph_types/transform.py
Attributes¶
named = Field(default_factory=dict)
class-attribute
instance-attribute
¶
positional = Field(default_factory=tuple)
class-attribute
instance-attribute
¶
removed_keys = Field(default_factory=frozenset)
class-attribute
instance-attribute
¶
Methods:¶
context_doc()
¶
from_result(result)
classmethod
¶
Source code in graflo/architecture/graph_types/transform.py
VertexObservation
¶
Bases: ConfigBaseModel
Typed vertex observation emitted during extraction.
Source code in graflo/architecture/graph_types/context.py
VertexRep
¶
Bases: ConfigBaseModel
Context for graph transformation actions.
Attributes:
| Name | Type | Description |
|---|---|---|
vertex |
dict[str, Any]
|
doc representing a vertex |
Source code in graflo/architecture/graph_types/transform.py
Attributes¶
lookup_only = False
class-attribute
instance-attribute
¶
True when this observation exists only to locate an existing vertex.
Such documents take part in edge rendering but are never upserted. Tagging the observation rather than the vertex type keeps it correct when one resource both writes and merely references the same vertex type.
model_config = ConfigDict(kw_only=True)
class-attribute
instance-attribute
¶
vertex
instance-attribute
¶
Weight
¶
Bases: ABCFields
Defines weight configuration for edges.
Attributes:
| Name | Type | Description |
|---|---|---|
map |
dict
|
Dictionary mapping field values to weights |
filter |
dict
|
Dictionary of filter conditions for weights |
Source code in graflo/architecture/graph_types/index_config.py
Attributes¶
filter = Field(default_factory=dict, description='Filter conditions applied when resolving vertex-based weights.')
class-attribute
instance-attribute
¶
map = Field(default_factory=dict, description='Mapping of field values to weight values for vertex-based edge attributes.')
class-attribute
instance-attribute
¶
Functions:¶
context_dict_from_transform_buffer_item(item)
¶
Map one transform_buffer entry to a flat context dict (named keys only).
Source code in graflo/architecture/graph_types/transform.py
deserialize_edge_key(key)
¶
Deserialize a JSON-array edge key back to an edge id tuple.
Source code in graflo/architecture/graph_types/identifiers.py
merge_observation_with_transform_buffer(observation, buffer_items)
¶
Merge a JSON observation slice with transform outputs at the same location.
observation is the current dict-shaped fragment of the nested document
passed into actors (often a child object under a :class:DescendActor).
buffer_items are the entries in ExtractionContext.transform_buffer
for the same :class:LocationIndex.
Starts from a shallow copy of observation; each buffer entry (in pipeline
order) updates the merged view, so later transforms override earlier keys
and transform output overrides the raw JSON on key conflicts.
Source code in graflo/architecture/graph_types/transform.py
serialize_edge_key(edge_id)
¶
Serialize an edge id tuple to a JSON-safe string key.
Uses a JSON array [source, target, relation] so vertex or relation names
may contain | or other special characters without ambiguity.