src.dackar.RCA.orchestrators.kg_context_builder¶
kg_context_builder — KGContextBuilderConfig and Neo4jKGContextBuilder.
Extracted from rca_reasoning_orchestrator.py. The parent module re-exports both names for backward-compatible imports.
Attributes¶
Classes¶
Functions¶
Module Contents¶
- class src.dackar.RCA.orchestrators.kg_context_builder.Neo4jKGContextBuilder(client, database=None, config=None)[source]¶
- Parameters:
client (dackar.knowledge_graph.py2neo.Py2Neo)
database (Optional[str])
config (Optional[KGContextBuilderConfig])
- build(event, telemetry_summary, operational_context, pm_compliance, run_context, focus_component_ids=None)[source]¶
- _record_truncation(*, family, total_matched, cap, dropped_ids, retained=None)[source]¶
Record per-family truncation stats into
self._truncation_stats(P-1).total_matchedis None when the pre-truncation total is unknown (e.g. a DB-sideLIMIT); in that case truncation is inferred from an at-cap retained count. Otherwise a family istruncatedwhen more items matched than the cap allows.- Parameters:
family (str)
total_matched (Optional[int])
cap (int)
dropped_ids (List[str])
retained (Optional[int])
- Return type:
None
- _resolve_monitored_variable(sensor_id, monitored_variable_id)[source]¶
- Parameters:
sensor_id (Optional[str])
monitored_variable_id (Optional[str])
- Return type:
List[JsonDict]
- _expand_neighborhood(seed_component_ids)[source]¶
- Parameters:
seed_component_ids (Set[str])
- Return type:
- _estimate_path_strength(hop_count, rel_types)[source]¶
- Parameters:
hop_count (int)
rel_types (List[str])
- Return type:
float
- _fetch_failure_modes(component_ids)[source]¶
- Parameters:
component_ids (List[str])
- Return type:
List[JsonDict]
- _fetch_safety_functions(component_ids)[source]¶
Fetch safety function nodes in the KG that are linked to any component in component_ids via standard nuclear-plant relation types.
The query is intentionally permissive on relation direction: different KG schemas place the directed arrow in either direction between a component and its associated safety function. Both directions are matched.
Returns a list of dicts conforming to
kg_context.json#/safety_functions.- Parameters:
component_ids (List[str])
- Return type:
List[JsonDict]
- _fetch_kg_snapshot_version()[source]¶
Return a stable version string that identifies the current state of the Neo4j KG.
Strategy (in priority order): 1.
CALL dbms.components()— returns the Neo4j server version. Combinedwith the highest
last_modifiedtimestamp across all nodes this gives a reproducible snapshot key tied to both the software and data state.Highest node
last_modifiedtimestamp alone (if dbms.components fails).Synthetic ISO timestamp fallback — used when the graph has no
last_modifiedproperties and the procedure call is unavailable.
The returned string is recorded in
kg_context.kg_snapshot_versionso that every RCA run can be replayed against the exact KG state that existed at query time (§6 Model Governance).- Return type:
str
- _fetch_oe_documents(failure_mode_ids, component_types)[source]¶
Return OE report nodes from the KG relevant to this event’s failure modes and component types.
OE documents are fleet-wide and timeless — no date window is applied. Retrieval is via two soft-match paths (ordered by specificity):
Direct FM linkage: (oe_document)-[:APPLICABLE_TO]->(failure_mode)
Component-type soft match: oe_document.applicable_component_types overlaps with the subgraph component types.
plant_scope(pwr_only / bwr_only) is surfaced as metadata but is NOT used as a hard filter — many components are shared across reactor types.- Parameters:
failure_mode_ids (List[str])
component_types (List[str])
- Return type:
List[JsonDict]