graphcast.architecture.actor_util
¶
Edge creation and weight management utilities for graph actors.
This module provides core functionality for creating and managing edges in the graph database system. It handles edge rendering, weight management, and blank collection creation. The module is central to the graph construction process, implementing the logic for connecting vertices and managing their relationships.
Key Components
- add_blank_collections: Creates blank collections for vertices
- render_edge: Core edge creation logic, handling different edge types and weights
- render_weights: Manages edge weights and their relationships
Edge Creation Process
- Edge rendering (render_edge):
- Handles both PAIR_LIKE and PRODUCT_LIKE edge types
- Manages source and target vertex relationships
- Processes edge weights and relation fields
-
Creates edge documents with proper source/target mappings
-
Weight management (render_weights):
- Processes vertex-based weights
- Handles direct field mappings
- Manages weight filtering and transformation
- Applies weights to edge documents
Example
edge = Edge(source="user", target="post") edges = render_edge(edge, vertex_config, acc_vertex) edges = render_weights(edge, vertex_config, acc_vertex, cdoc, edges)
add_blank_collections(ctx, vertex_conf)
¶
Add blank collections for vertices that require them.
This function creates blank collections for vertices marked as blank in the vertex configuration. It copies relevant fields from the current document to create the blank vertex documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ctx
|
ActionContext
|
Current action context containing document and accumulator |
required |
vertex_conf
|
VertexConfig
|
Vertex configuration containing blank vertex definitions |
required |
Returns:
Name | Type | Description |
---|---|---|
ActionContext |
ActionContext
|
Updated context with new blank collections |
Example
ctx = add_blank_collections(ctx, vertex_config) print(ctx.acc_global['blank_vertex']) [{'field1': 'value1', 'field2': 'value2'}]
Source code in graphcast/architecture/actor_util.py
render_edge(edge, vertex_config, acc_vertex)
¶
Create edges between source and target vertices.
This is the core edge creation function that handles different edge types (PAIR_LIKE and PRODUCT_LIKE) and manages edge weights. It processes source and target vertices, their discriminants, and creates appropriate edge documents with proper source/target mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge
|
Edge
|
Edge configuration defining the relationship |
required |
vertex_config
|
VertexConfig
|
Vertex configuration for source and target |
required |
acc_vertex
|
defaultdict[str, defaultdict[Optional[str], list]]
|
Accumulated vertex documents organized by vertex name and discriminant |
required |
Returns:
Type | Description |
---|---|
defaultdict[Optional[str], list]
|
defaultdict[Optional[str], list]: Created edges organized by relation type |
Note
- PAIR_LIKE edges create one-to-one relationships
- PRODUCT_LIKE edges create cartesian product relationships
- Edge weights are extracted from source and target vertices
- Relation fields can be specified in either source or target
Source code in graphcast/architecture/actor_util.py
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 |
|
render_weights(edge, vertex_config, acc_vertex, cdoc, edges)
¶
Process and apply weights to edge documents.
This function handles the complex weight management system, including: - Vertex-based weights from related vertices - Direct field mappings from the current document - Weight filtering and transformation - Application of weights to edge documents
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge
|
Edge
|
Edge configuration containing weight definitions |
required |
vertex_config
|
VertexConfig
|
Vertex configuration for weight processing |
required |
acc_vertex
|
defaultdict[str, defaultdict[Optional[str], list]]
|
Accumulated vertex documents |
required |
cdoc
|
dict
|
Current document being processed |
required |
edges
|
defaultdict[Optional[str], list]
|
Edge documents to apply weights to |
required |
Returns:
Type | Description |
---|---|
defaultdict[Optional[str], list]: Updated edge documents with applied weights |
Note
Weights can come from: 1. Related vertices (vertex_classes) 2. Direct field mappings (direct) 3. Field transformations (map) 4. Default index fields
Source code in graphcast/architecture/actor_util.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|