SSM-AI – Appendix B — Symbolic Search Lens: Code, Examples & Policies (B6–B10)

Drop-in code, worked examples, UI bands, acceptance checks, and stamp keys.

B6) Pseudocode (drop-in)

def ssm_search_score(hit_quality, freshness, semantic_match, risk_penalty,
                     alpha=1.0, beta=0.5, gamma=0.7, delta=0.8,
                     Unit=1.0, c=1.0, eps_w=1e-12, g_t=1.0, w=1.0):
    e_out = (alpha*hit_quality + beta*freshness + gamma*semantic_match) / Unit
    e_in  = (delta*risk_penalty) / Unit
    a_out = tanh(+c * e_out)
    a_in  = tanh(-c * e_in)
    V_out = w * atanh(a_out)
    U_in  = w * atanh(a_in)
    RSI   = tanh( (V_out - U_in) / max(w, eps_w) )
    RSI_env = g_t * RSI  # or: tanh(g_t*atanh(RSI))
    return RSI, RSI_env

def rank_results(results, gate):
    # results: list of dicts with normalized features (and optional 'w')
    scored = []
    for r in results:
        w = r.get("w", 1.0)
        RSI, RSI_env = ssm_search_score(
            r["hit_quality"], r["freshness"], r["semantic_match"], r["risk_penalty"],
            g_t=gate.get("g", 1.0), w=w
        )
        r["RSI"], r["RSI_env"] = RSI, RSI_env
        r["band"] = to_band(RSI_env)
        scored.append(r)
    return sorted(scored, key=lambda x: x["RSI_env"], reverse=True)

def merge_shards(shards):
    # shards: list of {'U_in':..., 'V_out':..., 'W_in':...} from engines
    U_in  = sum(s["U_in"]  for s in shards)
    V_out = sum(s["V_out"] for s in shards)
    W_in  = sum(s["W_in"]  for s in shards)
    RSI = tanh( (V_out - U_in) / max(W_in, 1e-12) )
    return RSI

B7) Worked example (calculator-fast; c=1, Unit=1, w=1)

# Parameters
alpha=1.0, beta=0.5, gamma=0.7, delta=0.8

# Result A
hit_quality=0.9, freshness=0.6, semantic_match=0.7, risk_penalty=0.2
e_out = 0.9 + 0.3 + 0.49 = 1.69
e_in  = 0.8*0.2 = 0.16
Net = 1.53 → RSI = tanh(1.53) ≈ 0.910425 → band A++

# Result B
0.8, 0.2, 0.5, 0.5 → e_out=1.25, e_in=0.40
Net = 0.85 → RSI ≈ 0.691069 → band A+

# Result C
0.4, 0.2, 0.4, 0.6 → e_out=0.78, e_in=0.48
Net = 0.30 → RSI ≈ 0.291313 → band A0

# Ranking (no gate):
A (0.910425, A++) > B (0.691069, A+) > C (0.291313, A0)

# With gate g_t = 0.80:
RSI_env(A)=0.728340 (A+), RSI_env(B)=0.552855 (A0), RSI_env(C)=0.233050 (A0) → same order, more conservative bands.

B8) UI policies (example)

Open directly        if RSI_env >= 0.90 (A++).
Preview with caution if 0.60 <= RSI_env < 0.90 (A+).
Extra click/summarize if -0.60 < RSI_env < 0.60 (A0).
Quarantine           if RSI_env <= -0.60 (A-/A--).
# Classical retrieval m remains untouched everywhere: phi((m,a)) = m

B9) Acceptance vectors (pass/fail)

V1 (values above): reproduce stated RSI within dtype tolerance.
V2 (order/shard): permutations or per-engine shard pooling yield identical RSI via U/W.
V3 (gate): with g_t in {1.0, 0.8, 0.5}, RSI_env stays in (-1,+1) and bands update per thresholds.
V4 (saturation guard): if any feature pushes |c*e| > 3, a := tanh(c*e) remains bounded; outputs deterministic.
V5 (collapse parity): for any downstream classical metric m, phi((m,a)) = m holds.

B10) Stamp fields (add to your one-liner)

"|SSMSEARCH|alpha=1.0|beta=0.5|gamma=0.7|delta=0.8|Unit=1.0|c=1.0"
+"|RSI=0.9104|band=A++|g=0.80|RSI_env=0.7283|"

One-line takeaway. Implement the search lens with a few lines of code, validate with worked examples and acceptance vectors, drive UI by bands, and stamp key fields — rankings stay bounded and shard-proof, while classical retrieval scores remain pristine via phi((m,a)) = m.


Navigation
Previous: SSM-AI – Appendix B — Symbolic Search Lens: Definition & Setup (B1–B5)
Next: SSM-AI – Appendix C — Stamp & Ledger Schema (replay, roll-up, CLI)


Directory of Pages
SSM-AI — Table of Contents