graflo.architecture.schema.context¶
Bounded schema context: the schema graph as a navigable, budgetable object.
Answers "what can I ask?" about a schema without touching a database. Every
export here is layer 2 — pure logical model, no db, no data_source, no
embeddings, no tokenizer.
Eager re-exports (this is a package boundary, not a lazy façade).
Budget
¶
Bases: ConfigBaseModel
Caller-requested ceilings on a schema context payload.
Source code in graflo/architecture/schema/context/budget.py
BudgetAccounting
¶
Bases: ConfigBaseModel
What the budget actually cost, measured rather than assumed.
Source code in graflo/architecture/schema/context/budget.py
ElidedEdge
¶
Bases: ConfigBaseModel
An edge left out of the slice.
Source code in graflo/architecture/schema/context/elision.py
ElidedVertex
¶
Bases: ConfigBaseModel
A vertex type left out of the slice.
Source code in graflo/architecture/schema/context/elision.py
ElisionReport
¶
Bases: ConfigBaseModel
Everything the slice does not contain, plus the budget that caused it.
Source code in graflo/architecture/schema/context/elision.py
truncated
property
¶
Whether anything at all was left out.
EntryPoint
¶
Bases: ConfigBaseModel
A vertex type an agent can look up directly.
The single most useful fact about an unfamiliar graph: a type with a natural identity and a secondary index is one you can filter on cheaply, which is where a query should start.
Source code in graflo/architecture/schema/context/card.py
RankingWeights
¶
Bases: ConfigBaseModel
Relative weight of each local signal. Weights need not sum to 1.
Source code in graflo/architecture/schema/context/rank.py
SchemaCard
¶
Bases: ConfigBaseModel
Bounded orientation summary of a whole schema.
Source code in graflo/architecture/schema/context/card.py
SchemaGraph
¶
Read-only adjacency index over a :class:Schema's vertex types.
Built once per schema and never mutates it. Plain dicts throughout — no networkx, because this is layer 2 and the whole point is to stay free of heavyweight dependencies.
Source code in graflo/architecture/schema/context/graph.py
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 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 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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
edge_ids
property
¶
Every declared edge id, in deterministic order.
schema
property
¶
The indexed schema. Treat as read-only.
vertex_types
property
¶
Every declared vertex type name.
degree(vertex_type)
¶
Total incident edge count (out + in), counting self-loops twice.
edge(edge_id)
¶
from_schema(schema)
classmethod
¶
in_edges(vertex_type)
¶
isolated_types()
¶
out_edges(vertex_type)
¶
relation_vocabulary()
¶
Distinct non-null relation names across all edges.
relations_between(a, b, *, max_len=3, max_paths=20, direction=EdgeDirection.ANY)
¶
Simple paths from vertex type a to b, shortest first.
Bounded breadth-first enumeration: no vertex repeats within a path, so
cycles terminate. Results are ordered by (length, edge ids) and are
therefore reproducible run to run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
str
|
Source vertex type. |
required |
b
|
str
|
Target vertex type. |
required |
max_len
|
int
|
Maximum hops per path. |
3
|
max_paths
|
int
|
Maximum number of paths returned. |
20
|
direction
|
EdgeDirection
|
Orientation followed from each frontier vertex. |
ANY
|
Returns:
| Type | Description |
|---|---|
list[SchemaPath]
|
list[SchemaPath]: paths found, possibly empty. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if either endpoint is not declared in the schema. |
Source code in graflo/architecture/schema/context/graph.py
schema_neighbors(vertex_type, *, hops=1, direction=EdgeDirection.ANY, edge_relations=None)
¶
Vertex types adjacent to vertex_type within hops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_type
|
str
|
Seed vertex type. Must be declared. |
required |
hops
|
int
|
Maximum hop distance. |
1
|
direction
|
EdgeDirection
|
Orientation followed from each frontier vertex. Defaults to
:attr: |
ANY
|
edge_relations
|
set[str | None] | None
|
Restrict traversal to these relation names ( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SchemaNeighborhood |
SchemaNeighborhood
|
distances per reachable type and the edges used. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if vertex_type is not declared in the schema. |
Source code in graflo/architecture/schema/context/graph.py
SchemaNeighborhood
¶
Bases: ConfigBaseModel
Vertex types reachable from a seed within a hop bound.
Source code in graflo/architecture/schema/context/graph.py
vertex_types
property
¶
Reachable vertex types, nearest first then alphabetical.
SchemaPath
¶
Bases: ConfigBaseModel
One path between two vertex types, as an alternating vertex/edge walk.
Source code in graflo/architecture/schema/context/graph.py
length
property
¶
Number of hops (edges) in this path.
VertexSignals
¶
Bases: ConfigBaseModel
Per-vertex-type ranking inputs and the score derived from them.
Source code in graflo/architecture/schema/context/rank.py
build_card(schema, *, top_n=10, max_names=25, graph=None)
¶
Summarize schema for an agent's first contact with it.
Every list on the card is bounded, with a count reported alongside. A card whose size grows with the schema is not a card — it is the problem this wave exists to solve, wearing a summary's clothes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Schema to summarize. Never mutated. |
required |
top_n
|
int
|
How many hub types and entry points to list. |
10
|
max_names
|
int
|
How many isolated types and relation names to list. |
25
|
graph
|
SchemaGraph | None
|
Prebuilt index, if the caller already has one. |
None
|
Source code in graflo/architecture/schema/context/card.py
estimate_tokens(payload)
¶
Estimate token count for payload.
Runs over the compact serialization — estimating over a pretty-printed or defaults-included dump overcounts by a factor of two or more, which would make every budget silently pessimistic.
Source code in graflo/architecture/schema/context/budget.py
score_vertices(graph, seeds=(), *, weights=None, max_hops=3, direction=EdgeDirection.ANY)
¶
Rank every vertex type in graph, highest score first.
With no seeds, ranking is seed-independent (structure only) and answers "what are the important types here" — which is what the orientation card needs. With seeds, hop distance dominates and answers "what is near what I asked about".
Ties break by vertex name ascending. This is not cosmetic: without a total order the elision report is not reproducible across runs, and the budget tests become flaky.