/** * Bayesian Surprisal Scoring — T1146 Wave 6 Dreamer Upgrade * * Computes a surprisal score for a brain_observation relative to prior * context (existing embeddings in the same project/peer scope). * * Surprisal definition: how much new information does this observation * add to the existing memory state? * * score = -log(P(observation | prior_context)) * * Implementation: * - High score (novel, >0.7): observation is semantically distant from all * stored embeddings → high priority for consolidation * - Low score (redundant, <0.3): observation is very similar to an existing * embedding → low priority, may be merged/skipped * - Neutral (0.5): returned when embeddings unavailable (graceful degrade) * * Temporal decay and confidence weighting from BRAIN_SOURCE_CONFIDENCE are * applied to adjust the prior similarity. * * No external library: pure TypeScript cosine similarity + log transform. * * @task T1146 * @epic T1146 */ import type { DatabaseSync } from 'node:sqlite'; /** Neutral surprisal returned when embeddings are unavailable. */ export declare const NEUTRAL_SURPRISAL = 0.5; /** An observation row with its embedding for surprisal computation. */ export interface EmbeddableObservation { id: string; embedding: number[] | null | undefined; createdAt?: string | null; } /** Options for {@link computeSurprisalScore}. */ export interface SurprisalOptions { /** Inject a DatabaseSync for testing. */ db?: DatabaseSync | null; /** Project root (used to scope prior observations). */ project?: string | null; /** Peer ID for memory isolation. Default 'global'. */ peerId?: string; } /** Result of surprisal computation. */ export interface SurprisalResult { /** Observation ID scored. */ id: string; /** Surprisal score 0.0–1.0 (higher = more novel = higher consolidation priority). */ score: number; /** Whether embedding was available (false = returned neutral 0.5). */ embeddingAvailable: boolean; /** Most similar prior observation ID (if found). */ mostSimilarId?: string; /** Cosine similarity to most similar prior (0–1). */ maxSimilarity?: number; } /** * Compute a Bayesian surprisal score for a single observation. * * Returns a value in [0.0, 1.0]: * - >0.7 → novel (high surprisal) — high consolidation priority * - <0.3 → redundant (low surprisal) — skip or merge * - 0.5 → neutral (no embeddings available) * * Degrades gracefully when embeddings are unavailable: * returns NEUTRAL_SURPRISAL (0.5) with a console.warn, never throws. * * @param observation - The observation to score (must include embedding if available). * @param options - Scope, db injection for tests. * @returns SurprisalResult with score and diagnostics. * * @task T1146 */ export declare function computeSurprisalScore(observation: EmbeddableObservation, options?: SurprisalOptions): SurprisalResult; /** * Compute surprisal scores for a batch of observations, sorted descending. * * High-surprisal observations are returned first — they should be processed * by the dreamer first (bypass normal rate limit). * * @param observations - Batch to score. * @param options - Scope, db injection. * @returns Sorted array with highest surprisal first. * * @task T1146 */ export declare function computeSurprisalBatch(observations: EmbeddableObservation[], options?: SurprisalOptions): SurprisalResult[]; //# sourceMappingURL=surprisal.d.ts.map