Subgraph Query¶
akms.graph.query_subgraph
¶
query_subgraph.py — Subgraph Query Engine (§2.4 of system design).
Given a task description, seed tags, and agent role, extracts a ranked subgraph for loadout construction. Operates on the compiled graph.json — unaware of the global/local split.
Algorithm (12 steps): 1. Load query profile for agent_role from config 2. Find seed nodes matching any tag in domain_tags 3. Compute ego_graph of radius max_depth from each seed 4. Union all ego_graphs 5. Filter to LOADABLE_STATUSES (tentative, established) 6. Keep seeds + strict seed-anchored traversal via profile edge_types only 7. Apply prefer_domains boost (×1.5) 8. Apply exclude_domains filter 9. Exclude nodes below confidence threshold 10. Rank nodes by profile's rank_formula 11. Cap at MAX_NODES_PER_LOADOUT 12. Inject pitfall nodes (always included up to MAX_PITFALL_NODES)
query_subgraph
¶
query_subgraph(
G: DiGraph,
domain_tags: list[str],
agent_role: AgentRole | str,
config: PropagationConfig | None = None,
max_depth: int = 2,
) -> list[tuple[str, dict[str, Any]]]
Extract a ranked subgraph for loadout construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
DiGraph
|
The compiled knowledge graph (from load_graph or build_graph). |
required |
domain_tags
|
list[str]
|
Tags to seed the search (e.g., ["taichi", "gpu"]). |
required |
agent_role
|
AgentRole | str
|
The agent role selecting a query profile. |
required |
config
|
PropagationConfig | None
|
PropagationConfig (uses defaults if None). |
None
|
max_depth
|
int
|
Maximum graph traversal depth from seeds. |
2
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, dict[str, Any]]]
|
Ranked list of (node_id, node_data) tuples. |
list[tuple[str, dict[str, Any]]]
|
Pitfall nodes are always included regardless of rank. |
Source code in packages/akms/src/akms/graph/query_subgraph.py
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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
compute_query_hash
¶
Compute a deterministic hash for a query, used for caching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_tags
|
list[str]
|
Sorted list of tags. |
required |
agent_role
|
str
|
Role string. |
required |
max_depth
|
int
|
Traversal depth. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SHA256 hex digest of the query parameters. |