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

JsonDict

LOGGER

Classes

KGContextBuilderConfig

Neo4jKGContextBuilder

Functions

utcnow_iso()

Module Contents

src.dackar.RCA.orchestrators.kg_context_builder.JsonDict[source]
src.dackar.RCA.orchestrators.kg_context_builder.LOGGER[source]
src.dackar.RCA.orchestrators.kg_context_builder.utcnow_iso()[source]
Return type:

str

class src.dackar.RCA.orchestrators.kg_context_builder.KGContextBuilderConfig[source]
max_hops: int = 2[source]
max_past_events: int = 10[source]
max_documents: int = 20[source]
include_documents: bool = True[source]
include_past_events: bool = True[source]
include_safety_functions: bool = True[source]
include_oe_documents: bool = True[source]
max_oe_documents: int = 10[source]
doc_window_days_before: int = 90[source]
doc_window_days_after: int = 7[source]
past_event_window_days: int = 3650[source]
class src.dackar.RCA.orchestrators.kg_context_builder.Neo4jKGContextBuilder(client, database=None, config=None)[source]
Parameters:
client[source]
database = None[source]
config[source]
build(event, telemetry_summary, operational_context, pm_compliance, run_context, focus_component_ids=None)[source]
Parameters:
Return type:

JsonDict

_record_truncation(*, family, total_matched, cap, dropped_ids, retained=None)[source]

Record per-family truncation stats into self._truncation_stats (P-1).

total_matched is None when the pre-truncation total is unknown (e.g. a DB-side LIMIT); in that case truncation is inferred from an at-cap retained count. Otherwise a family is truncated when 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

_basic_input_checks(event, telemetry_summary)[source]
Parameters:
Return type:

None

_resolve_seed_nodes(event, telemetry_summary)[source]
Parameters:
Return type:

JsonDict

_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:

JsonDict

_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. Combined

with the highest last_modified timestamp across all nodes this gives a reproducible snapshot key tied to both the software and data state.

  1. Highest node last_modified timestamp alone (if dbms.components fails).

  2. Synthetic ISO timestamp fallback — used when the graph has no last_modified properties and the procedure call is unavailable.

The returned string is recorded in kg_context.kg_snapshot_version so 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):

  1. Direct FM linkage: (oe_document)-[:APPLICABLE_TO]->(failure_mode)

  2. 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]

_fetch_documents(asset_ids, component_ids, event, operational_context)[source]
Parameters:
  • asset_ids (List[str])

  • component_ids (List[str])

  • event (JsonDict)

  • operational_context (Optional[JsonDict])

Return type:

List[JsonDict]

_fetch_past_events(target_event_id, asset_ids, component_ids, failure_mode_ids, event)[source]
Parameters:
  • target_event_id (str)

  • asset_ids (List[str])

  • component_ids (List[str])

  • failure_mode_ids (List[str])

  • event (JsonDict)

Return type:

List[JsonDict]

_parse_event_time(event)[source]
Parameters:

event (JsonDict)

Return type:

Optional[datetime.datetime]

_compute_time_distance_days(created_at, event_time)[source]
Parameters:
  • created_at (Optional[str])

  • event_time (Optional[datetime.datetime])

Return type:

Optional[int]