/** * Attention Score — multi-signal re-ranker (Option A: re-rank only top-N). * * Decision (informal ADR): * We do NOT replace RRF. RRF runs first and produces `result.score`, * which is the dominant signal here ("semantic"). AttentionScore folds * five other signals on top and re-ranks the top-N. This keeps the * battle-tested fusion intact while letting Synapse modulate ordering * with context (session, recency, access patterns). * * Final score per candidate: * final = Σ (weight_i × signal_i) for i in active signals * * Signals (each in [0, 1]): * - semantic : the post-RRF normalized score (passed in as result.score) * - recency : exponential time-decay from metadata.createdAt * - accessHeat : log-normalized metadata.accessCount across the batch * - taskAlign : alignment with the session task (0 when no session) * - agentAffinity: authorship + usage history (0 when no session) * - confidence : currently aliased to semantic; will pick up memory.confidence later * * Re-ranking applies only to the top `rerankWindow` results (default 50). Anything * below that window is appended unchanged, preserving RRF order at the tail. */ import type { SearchResult } from "@massa-th0th/shared"; import type { AgentSession } from "../types.js"; export interface AttentionWeights { semantic: number; recency: number; accessHeat: number; taskAlign: number; agentAffinity: number; confidence: number; } export interface AttentionScoreConfig { enabled: boolean; weights: AttentionWeights; rerankWindow: number; recencyHalfLifeMs: number; /** Multiplier applied to the rrf score to keep it on a comparable [0,1] scale. */ semanticScale: number; } export interface AttentionScoreBreakdown { resultId: string; semantic: number; recency: number; accessHeat: number; taskAlign: number; agentAffinity: number; confidence: number; final: number; } /** * Apply Attention Score over a result set. Returns a new array sorted by * the new final score. Disabled / empty input is returned unchanged. * * Active-weight renormalization (IMP-1): when a signal is structurally * unavailable (no createdAt → recency=0, no session → taskAlign=0, etc.), * its weight is excluded from the sum and the remaining weights are * renormalized to 1.0. This prevents score collapse on result sets that * lack metadata. In the degenerate case where only `semantic` and * `confidence` (its alias) contribute, the final score equals the input * semantic score, preserving the RRF ranking. * * A signal is treated as "available" when its dependency exists: * - recency: result has metadata.createdAt * - accessHeat: any result in the window has metadata.accessCount > 0 * - taskAlign: session is provided AND session.taskContext exists * - agentAffinity: session is provided * * `semantic` and `confidence` are always counted as available; without them * AttentionScore would have nothing to rerank against. */ export declare function applyAttentionScore(results: SearchResult[], config: AttentionScoreConfig, session: AgentSession | null, now?: number): { results: SearchResult[]; breakdowns: AttentionScoreBreakdown[]; }; export declare const DEFAULT_ATTENTION_WEIGHTS: AttentionWeights; export declare const DEFAULT_ATTENTION_CONFIG: AttentionScoreConfig; //# sourceMappingURL=attention-score.d.ts.map