graflo.architecture.graph_types¶
Graph runtime types and data structures (extraction, assembly, containers).
This module 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 module 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.
Key Components
- EdgeMapping: Defines how edges are mapped between vertices
- IndexType: Supported database index types
- EdgeType: Types of edge handling in the graph database
- GraphContainer: Main container for graph data
- ActionContext: Context for graph transformation operations
Example
container = GraphContainer(vertices={}, edges={}, linear=[]) index = Index(fields=["name", "age"], type=IndexType.PERSISTENT) context = 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.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.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.py
AssemblyContext
¶
Bases: ConfigBaseModel
Assembly-phase context built from extraction outputs.
Source code in graflo/architecture/graph_types.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.py
EdgeIntent
¶
Bases: ConfigBaseModel
Typed edge assembly request emitted during extraction.
Source code in graflo/architecture/graph_types.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.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.py
EncodingType
¶
ExtractionContext
¶
Bases: ConfigBaseModel
Extraction-phase context.
Attributes:
| Name | Type | Description |
|---|---|---|
acc_vertex |
Any
|
Local accumulation of extracted vertices |
buffer_transforms |
Any
|
Buffer for transform payloads (defaultdict[LocationIndex, list]) |
edge_requests |
Any
|
Explicit edge assembly requests collected during extraction |
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.py
GraphAssemblyResult
¶
Bases: ConfigBaseModel
Result of graph assembly phase.
Source code in graflo/architecture/graph_types.py
GraphContainer
¶
Bases: ConfigBaseModel
Container for graph data including vertices and edges.
Attributes:
| Name | Type | Description |
|---|---|---|
vertices |
dict[str, 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.py
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 |
|---|---|
AssertionError
|
If edge IDs are not properly formatted |
Source code in graflo/architecture/graph_types.py
items()
¶
loop_over_relations(edge_def)
¶
Iterate over edges matching the given edge definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_def
|
tuple[str, str, str | None]
|
Tuple of (source, target, optional_relation) |
required |
Returns:
| Type | Description |
|---|---|
|
Generator yielding matching edge IDs |
Source code in graflo/architecture/graph_types.py
pick_unique()
¶
Remove duplicate entries from vertices and edges.
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.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.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.py
ItemsView
¶
View class for iterating over vertices and edges in a GraphContainer.
Source code in graflo/architecture/graph_types.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.py
ProvenancePath
¶
Bases: ConfigBaseModel
Explicit provenance path for extracted observations.
Source code in graflo/architecture/graph_types.py
TransformObservation
¶
Bases: ConfigBaseModel
Typed transform observation emitted during extraction.
Source code in graflo/architecture/graph_types.py
TransformPayload
¶
Bases: ConfigBaseModel
Typed transform output shared between extraction and assembly phases.
Source code in graflo/architecture/graph_types.py
VertexObservation
¶
Bases: ConfigBaseModel
Typed vertex observation emitted during extraction.
Source code in graflo/architecture/graph_types.py
VertexRep
¶
Bases: ConfigBaseModel
Context for graph transformation actions.
Attributes:
| Name | Type | Description |
|---|---|---|
vertex |
dict
|
doc representing a vertex |
ctx |
dict
|
context (for edge definition upstream |
Source code in graflo/architecture/graph_types.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 |