From 24499a25e9fc13547bacb311ad6c8bab33560e3b Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Wed, 24 Jun 2026 11:21:59 +0200 Subject: [PATCH] fix(ai-sdk): make interpretation-intent override reliably win MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #34's fixed +0.25 guidance gain was too small live: for "Was empfiehlt der EDPB zum DSB?" the binding Art. 37 (1.381) still edged out the boosted EDPB guidance (1.348), because the live authority score gives the binding article a topic/domain bonus the (partly English) guidance chunk does not match. Replace the fixed gain with a deterministic lift: a semantically competitive guideline (raw semantic >= best_binding_semantic - 0.05) is lifted just ABOVE the best binding FINAL score (ordered by semantic), so authority/topic/domain bonuses can no longer edge it out. Obligation questions (no intent signal) are untouched — binding stays Top-1; off-topic guidance stays demoted. Co-Authored-By: Claude Opus 4.7 --- .../internal/ucca/authority_rerank.go | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/ai-compliance-sdk/internal/ucca/authority_rerank.go b/ai-compliance-sdk/internal/ucca/authority_rerank.go index a4b7d3d6..84932f5f 100644 --- a/ai-compliance-sdk/internal/ucca/authority_rerank.go +++ b/ai-compliance-sdk/internal/ucca/authority_rerank.go @@ -16,7 +16,7 @@ const ( scopePenalty = 0.25 // BDSG Teil 3 (law enforcement) on a general DP question topicGain = 0.18 // amplifier only supersededPenalty = 0.50 // superseded Alt-Quelle (pre-eu-v1): demoted, nicht versteckt - guidanceIntentGain = 0.25 // controlled guidance override on explicit interpretation intent + guidanceIntentGain = 0.10 // epsilon a qualifying guideline is lifted ABOVE the best binding hit guidanceIntentMargin = 0.05 // ...only if the guideline is semantically competitive with binding ) @@ -110,17 +110,36 @@ func rerankByAuthority(query string, results []LegalSearchResult) []LegalSearchR copy(out, results) for i := range out { out[i].Score = authorityScore(query, out[i], qDomain, qForeign) - // Interpretations-Intent (eng begrenzt): NUR wenn die Query explizit nach - // Guidance/Auslegung fragt UND die Leitlinie semantisch konkurrenzfaehig ist - // (>= bester binding-Treffer - margin), darf supervisory_guidance die bindende - // Norm ueberholen. Sonst bleibt binding > guidance (Normfrage unveraendert). - if wantsGuidance && out[i].SourceClass == "supervisory_guidance" && - results[i].Score >= bestBindingSem-guidanceIntentMargin { - out[i].Score += guidanceIntentGain - } + } + if wantsGuidance { + applyGuidanceIntent(out, results, bestBindingSem) } sort.SliceStable(out, func(a, b int) bool { return out[a].Score > out[b].Score }) return out } + +// applyGuidanceIntent lifts semantically-competitive guidance just ABOVE the best +// binding hit (ordered by semantic), so an EXPLICIT interpretation question can +// return guidance Top-1. Obligation questions (no intent → not called) keep +// binding on top. Guidance below the semantic margin is left untouched, so an +// off-topic guideline can never ride the override — and the lift is computed from +// the binding FINAL score, so authority/topic/domain bonuses cannot edge it out. +func applyGuidanceIntent(out, raw []LegalSearchResult, bestBindingSem float64) { + bestBindingFinal := 0.0 + for i := range out { + if out[i].SourceClass == "binding_law" && out[i].Score > bestBindingFinal { + bestBindingFinal = out[i].Score + } + } + for i := range out { + if out[i].SourceClass != "supervisory_guidance" || raw[i].Score < bestBindingSem-guidanceIntentMargin { + continue + } + lifted := bestBindingFinal + guidanceIntentGain + (raw[i].Score - bestBindingSem) + if lifted > out[i].Score { + out[i].Score = lifted + } + } +} -- 2.52.0