02.3 Universal Fallback Logic for Kor.ai Nodes - ravkorsurv/kor-ai-core GitHub Wiki

๐Ÿ” 02.3 Universal Fallback Logic for Kor.ai Nodes

๐Ÿ“Œ Purpose

As Kor.ai scales across typologies and asset classes, we introduce modular fallback logic to improve:

  • ๐Ÿง  Explainability โ€” consistent scoring rules, even under data sparsity
  • ๐Ÿงช Debugging โ€” structured node diagnostics and triage
  • ๐Ÿ“ˆ Scalability โ€” avoids CPT explosion across high-cardinality inputs
  • ๐Ÿ›ก๏ธ Resilience โ€” supports partial evidence and degraded inputs

Fallback logic transforms nodes from fixed CPTs to data-aware, inference-friendly modules.


๐Ÿงฉ Fallback Logic: Core Principles

  • Every complex node in the Bayesian model has a fallback function
  • The function replaces or supplements CPTs when data is incomplete or unenumerated
  • Logic is typically driven by risk scoring, thresholds, or ordinal mappings
  • Optionally outputs rationale for the fallback path taken (supporting explainability)

๐Ÿงฑ Modular Fallback Categories

Communication Intent

  • Node: Q75_CommsIntentInfluence
  • Fallback: Weighted score โ†’ probability map
  • States: High / Medium / Low / None

PnL / Trade Pattern Risk

  • Node: Q20_PnLDeviation
  • Fallback: Z-score bucket
  • States: High / Medium / Low / Normal

Counterparty / KYC Risk

  • Node: Q44_EntityRiskScore
  • Fallback: Label โ†’ ordinal map
  • States: High / Medium / Low

Trade Clustering

  • Node: Q35_TradeClustering
  • Fallback: Count buckets
  • States: Clustered / Neutral / Dispersed

Price/Volatility Abuse

  • Node: Q21_PriceSensitivityAbuse
  • Fallback: Direction + timing logic
  • States: High / Medium / Low

News Sentiment Impact

  • Node: Q51_NewsSentimentImpact
  • Fallback: Sentiment + source matrix
  • States: Reinforcing / Neutral / Conflicting

HR / Bonus Incentive

  • Node: Q19_HRIncentiveAlignment
  • Fallback: Bonus delta logic
  • States: Motivated / Neutral / Low Signal

Platform KDE Health

  • Node: Q99_KDEIntegrityFlag
  • Fallback: Recency / error-code mapping
  • States: OK / Partial / Broken

โš™๏ธ Generic Fallback Function Template (Python)

def fallback_score_router(node_name, input_values):
    fallback_registry = {
        'Q75_CommsIntentInfluence': compute_comms_intent_probabilities,
        'Q20_PnLDeviation': compute_pnl_score_bucket,
        'Q44_EntityRiskScore': map_kyc_label_to_risk,
        'Q35_TradeClustering': cluster_trade_count_bucket,
        'Q21_PriceSensitivityAbuse': price_flag_logic,
        'Q51_NewsSentimentImpact': news_sentiment_mapping,
        'Q19_HRIncentiveAlignment': bonus_delta_bucket,
        'Q99_KDEIntegrityFlag': kde_status_flag
    }
    return fallback_registry[node_name](input_values)

๐Ÿง  Example: Q20_PnLDeviation Fallback

Inputs:

  • z-score = +2.8
  • holding_time = <1h
def compute_pnl_score_bucket(zscore, holding_time):
    if zscore >= 3:
        return [0.8, 0.15, 0.05, 0.00]  # High
    elif zscore >= 2:
        return [0.3, 0.5, 0.15, 0.05]   # Medium
    elif zscore >= 1:
        return [0.1, 0.3, 0.4, 0.2]     # Low
    else:
        return [0.0, 0.1, 0.2, 0.7]     # Normal

๐Ÿ” Optional: Explainability Tagging

{
  "result": [0.8, 0.15, 0.05, 0.00],
  "explanation": "Z-score of +3.1 triggered High signal; short-term hold"
}

๐Ÿงช Debugging Support: Metadata Flags

{
  "Q75_CommsIntentInfluence": {
    "used_fallback": true,
    "risk_score": 9.0,
    "source": "fallback_score_router"
  }
}

Supports:

  • Alert explainability
  • Diagnostic analysis
  • Missing-data root cause tracing

๐Ÿ“Œ Next Steps

  1. Implement fallback_score_router() in inference layer
  2. Log fallback usage per alert/case ID
  3. Add rationale output for all fallback logic nodes
  4. Build unit test coverage for missing data scenarios
  5. Update wiki (e.g. 12.5 Node Library) to link fallback mappings

๐Ÿงฉ Node Coverage Progress

Node Fallback Defined Logic Confirmed Notes
Q75_CommsIntentInfluence โœ… โœ… Fully defined in 12.6
Q20_PnLDeviation โœ… โœ… Logic in this section
Q44_EntityRiskScore โš ๏ธ Partial Needs label-to-risk mapping
Q35_TradeClustering โš ๏ธ Partial Needs N-count thresholds
Q21_PriceSensitivityAbuse โฌœ No Direction/time window logic
Q51_NewsSentimentImpact โฌœ No Define source/sentiment grid
Q19_HRIncentiveAlignment โฌœ No Bonus delta model
Q99_KDEIntegrityFlag โฌœ No Recency/error flag to status

Kor.aiโ€™s fallback logic layer ensures robustness in real-world surv