SSM-AI – Integration Quickstarts: RAG Pipeline Hook (8.2)

Bounded doc ranking before generation — keep retrieval m intact.

Where to hook. After retrieval scores but before generation. Compute a bounded document alignment and optionally forward a pooled lane to generation. Retrieval magnitudes stay untouched via phi((m,a)) = m.

Doc lens (example).

  • Signals (helpful): semantic_gain, citation_hit, source_authority
  • Signals (risky): toxicity_gap, policy_risk, staleness_penalty
  • Map to contrasts:
    e_out := semantic_gain + citation_hit + source_authority
    e_in := toxicity_gap + policy_risk + staleness_penalty
  • Alignments (bounded):
    a_out := tanh(+c*e_out), a_in := tanh(-c*e_in) (always clamp before atanh)
# Rank docs by RSI (bounded, order-invariant)
def rsi_doc(signals, c=1.0, eps_w=1e-12):
    # signals = [(tox_gap, cit_hit, sem_gain, w), ...]
    U_in = 0.0; V_out = 0.0; W = 0.0
    for tox, cit, sem, w in signals:
        a_in  = tanh(-c*tox)
        a_out = tanh(+c*(cit + sem))
        a_in  = max(-1+1e-6, min(1-1e-6, a_in))   # clamp example (f32)
        a_out = max(-1+1e-6, min(1-1e-6, a_out))
        U_in += w * atanh(a_in)
        V_out += w * atanh(a_out)
        W    += w
    return 0.0 if W <= 0 else tanh((V_out - U_in) / max(W, eps_w))

Forwarding into generation (optional).
Pool top-K doc lanes and pass as a side feature; do not alter generation m.

# Pool top-K doc lanes (u-mean)
# given doc alignments a_doc_k with weights w_k
U = SUM_k w_k*atanh(a_doc_k)
W = SUM_k w_k
a_pool := tanh( U / max(W, eps_w) )
# feed a_pool as a side feature; logits/probs remain classical

Stamp fields (suggested).
doc_id, m_retrieval, RSI_doc, band, U_in, V_out, W_in, g_t, a_pool(optional), Unit, c, eps_a, eps_w, weights_policy, dtype, knobs_hash, stamp

Policy notes.

  • Weights: start with w := 1; w := |m|^gamma if declared (e.g., to bias by retrieval strength).
  • Clamps: always clamp a before atanh: a_c := clamp(a, -1+eps_a, +1-eps_a).
  • Division policy: N/A for ranking itself; if any downstream ratio appears, use declared division_policy (default "strict") for control, never for m.
  • Zero-evidence guard: if W == 0, set RSI_doc := 0, band := "A0" (insufficient evidence).

One-line takeaway. Compute a bounded RSI for retrieved docs in rapidity space, optionally pool top-K, and pass lanes forward — retrieval m is never changed (phi((m,a)) = m).


Navigation
Previous: SSM-AI – Integration Quickstarts: LLM Decoding Hooks (8.1)
Next: SSM-AI – Integration Quickstarts: Agents/Tools Middleware (8.3)


Directory of Pages
SSM-AI — Table of Contents