Query ranked knowledge¶
query_subgraph() performs a role-aware ranked query over the compiled graph.
Despite its historical name, it returns a ranked list of node records rather
than a NetworkX subgraph.
Python API¶
from akms.graph.build_graph import load_graph
from akms.graph.query_subgraph import query_subgraph
G = load_graph("knowledge/graph/graph.json")
ranked = query_subgraph(
G,
domain_tags=["plasticity", "return-mapping"],
agent_role="physics_reviewer",
config=None,
max_depth=2,
)
for node_id, data in ranked:
print(node_id, data["domain"], data["confidence"])
Selection algorithm¶
The query:
- Loads the role profile from propagation configuration.
- Finds nodes whose tags intersect the seed tags.
- Builds a bounded undirected ego union around those seeds.
- Retains tentative and established nodes.
- Traverses only edge types allowed by the role profile.
- Applies preferred/excluded domain and confidence rules.
- Ranks candidates according to the role profile.
- Caps ordinary results and injects relevant pitfall nodes.
CLI¶
Output is stable JSON containing count, graph_path, and nodes.
When not to use a tag query¶
A tag match is advisory. Use exact task resolution when a source path or symbol imposes a mandatory contract that must bypass ranking, thresholds, or caps.