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, EdgeCastingTypeindex_config— ABCFields, Weight, Indexcontainer— GraphContainerlocation— LocationIndex, ProvenancePathtransform— TransformPayload, VertexRep, merge helperscontext— ExtractionContext, AssemblyContext, observations, ActionContext
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
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
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
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
¶
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 | |
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
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 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 | |
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
__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
__iter__()
¶
Iterate over vertices and edges in the container.
LocationIndex
¶
Bases: ConfigBaseModel
Immutable location index for nested graph traversal.
Source code in graflo/architecture/graph_types/location.py
__init__(*args, **kwargs)
¶
Allow LocationIndex((0,)) or LocationIndex(path=(0,)).
Source code in graflo/architecture/graph_types/location.py
accept_tuple(data)
classmethod
¶
Accept a single tuple as positional path (e.g. LocationIndex((0,))).
Source code in graflo/architecture/graph_types/location.py
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
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
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
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
merge_row_doc_with_transform_buffer(doc, buffer_items)
¶
Backward-compatible alias for :func:merge_observation_with_transform_buffer.
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.