/** * Predictive Memory Engine * * The core algorithm that makes predictions feel "magical" by anticipating * what users need before they realize it. * * Scoring Formula: * score = (semantic * 0.40) + (temporal * 0.30) + (frequency * 0.20) + (serendipity * 0.10) * * Each component: * - Semantic: Cosine similarity between context embedding and memory embedding * - Temporal: Exponential decay based on age (Ebbinghaus-inspired) * - Frequency: How often similar memories are accessed * - Serendipity: Bonus for "adjacent possible" discoveries */ import { PredictiveContext, PredictiveRecallParams, PredictedMemory, PredictiveRecallResult, PredictionScoreBreakdown, PredictionReason, ScoredMemoryCandidate, PredictionScoringConfig } from "../core/prediction-types.js"; import { MemoryTypeValue } from "../core/types.js"; /** * Calculate semantic similarity score (0-100) * Uses cosine similarity between context embedding and memory embedding */ export declare function calculateSemanticScore(contextEmbedding: number[], memoryEmbedding: number[], threshold?: number): number; /** * Calculate temporal relevance score (0-100) * Uses exponential decay based on Ebbinghaus forgetting curve * * Formula: score = 100 * e^(-t/halfLife) where t is days since creation * * Examples with 14-day half-life: * - 0 days: 100 * - 7 days: 60 * - 14 days: 50 * - 30 days: 14 * - 60 days: 2 */ export declare function calculateTemporalScore(createdAt: Date, now?: Date, halfLifeDays?: number): number; /** * Calculate frequency/usage score (0-100) * Based on how often the memory or similar memories are accessed */ export declare function calculateFrequencyScore(accessCount?: number, maxAccessCount?: number): number; /** * Calculate serendipity/surprise score (0-100) * Rewards memories that are "adjacent" to current context (not too similar, not too different) * * The "adjacent possible" concept: the best discoveries are often just outside * what we're currently focused on. */ export declare function calculateSerendipityScore(contextEmbedding: number[], memoryEmbedding: number[], range?: { min: number; max: number; }): number; /** * Calculate the full prediction score breakdown */ export declare function calculatePredictionScore(contextEmbedding: number[], memory: ScoredMemoryCandidate, config?: PredictionScoringConfig, maxAccessCount?: number): PredictionScoreBreakdown; /** * Determine the primary reason for a prediction */ export declare function determinePredictionReason(scoreBreakdown: PredictionScoreBreakdown, hasTeamContext?: boolean): { reason: PredictionReason; explanation: string; }; /** * Suggest an action based on the prediction context */ export declare function suggestAction(scoreBreakdown: PredictionScoreBreakdown, memoryType: MemoryTypeValue): "review" | "apply" | "reference" | "explore"; /** * Process memories and generate predictions */ export declare function generatePredictions(contextEmbedding: number[], memories: ScoredMemoryCandidate[], params: PredictiveRecallParams, config?: PredictionScoringConfig): PredictedMemory[]; /** * Build context used summary */ export declare function buildContextUsedSummary(context: PredictiveContext): { projectContext: boolean; topicsContext: boolean; filesContext: boolean; textContext: boolean; teamContext: boolean; }; /** * Build the full prediction result */ export declare function buildPredictionResult(predictions: PredictedMemory[], memoriesAnalyzed: number, context: PredictiveContext, config?: PredictionScoringConfig, timeWindowDays?: number): PredictiveRecallResult; /** * Build a combined context string for embedding generation */ export declare function buildContextText(context: PredictiveContext): string;