Skip to content

feat(memory): Pluggable ImportanceProvider SPI — extract importance scoring behind extensible interface #481

Description

@novaspectrayan

Summary

Extract the current hardcoded ImportanceEstimator logic behind a pluggable ImportanceProvider SPI, enabling third-party and domain-specific importance scoring strategies.

Context & Motivation

Origin: Gork Critique Deep Analysis — P0 recommendation #1

Importance is the single most influential signal in Spector's recall ranking pipeline. A memory with importance 8.0 surfaces far more readily than one with importance 0.3, even if both are semantically similar to the query. Despite this critical role:

  • SalienceProfileProvider SPI exists — handles "what topics matter" via interest/disinterest domains and ICNU weights
  • ImportanceProvider SPI does NOT exist — the "how much does this specific memory matter" question is hardcoded in ImportanceEstimator.java

This means users cannot replace the importance model without modifying core Spector code. The importance pipeline (Welford surprise → ICNU fusion → flashbulb gating → nearest-neighbor novelty) is opinionated and excellent for general use, but domain-specific use cases (enterprise compliance, medical, legal) may need fundamentally different importance strategies.

Current Architecture

SurpriseDetector (Welford z-score)
        │
        ▼
ImportanceEstimator (FINAL CLASS — not pluggable)
   ├── Welford novelty z-score
   ├── ICNU fusion (Interest, Challenge, Novelty, Urgency)
   ├── FlashbulbPolicy (extreme surprise → permanent pin)
   └── Nearest-neighbor distance (diversity)
        │
        ▼
    ImportanceEstimate (score, isFlashbulb, confidence)

Key files:

  • ImportanceEstimator.javafinal class, hardcoded in SpectorMemoryFactory
  • SurpriseDetector.java — Welford online mean/stddev
  • FlashbulbPolicy.java — extreme surprise detection
  • IcnuWeights.java — 4-factor weight configuration
  • BiologicalSubsystemsBuilder.java — wires the subsystem
  • SpectorMemoryFactory.java — instantiates new ImportanceEstimator(...)

Proposed Design

1. Define ImportanceProvider SPI

public interface ImportanceProvider {
    
    ImportanceEstimate estimate(ImportanceContext context);
    
    record ImportanceContext(
        String text,
        float[] embedding,
        Map<String, String> metadata,
        @Nullable SalienceProfile effectiveProfile,
        @Nullable MemoryType targetTier
    ) {}
    
    record ImportanceEstimate(
        double score,          // 0.05 – 10.0
        boolean isFlashbulb,
        double confidence,
        Map<String, Double> breakdown  // explainability: which factors contributed
    ) {}
}

2. Extract Current Logic as Default Implementation

public final class DefaultImportanceProvider implements ImportanceProvider {
    // Current ImportanceEstimator logic, unchanged
    // Welford + ICNU + Flashbulb + nearest-neighbor
}

3. Provide Reference Alternative Implementations

  • LlmImportanceProvider — delegates to an LLM for importance judgment (slower, more contextual)
  • HybridImportanceProvider — heuristic first-pass + LLM refinement for high-uncertainty cases
  • FeedbackDrivenImportanceProvider — learns from reinforce/suppress signals over time

4. Add Importance Explainability

When a memory is scored, expose why it received that importance:

{
  "score": 7.2,
  "breakdown": {
    "welford_novelty": 3.8,
    "icnu_interest": 1.2,
    "icnu_challenge": 0.8,
    "icnu_novelty": 0.9,
    "icnu_urgency": 0.5,
    "salience_boost": 1.2,
    "flashbulb": false
  }
}

Acceptance Criteria

  • ImportanceProvider interface defined in spector-memory public API
  • Current ImportanceEstimator logic extracted into DefaultImportanceProvider (zero behavior change)
  • SpectorMemoryFactory / BiologicalSubsystemsBuilder accept pluggable ImportanceProvider
  • At least one alternative implementation provided (LLM-based or hybrid)
  • Importance breakdown (explainability) exposed via ImportanceEstimate.breakdown()
  • MCP memory_remember response includes importance breakdown when available
  • Configuration: spector.memory.importance.provider=default|llm|hybrid|custom in YAML
  • Developer can swap importance model with < 50 lines of code
  • Existing tests pass with zero regressions
  • Documentation: "How importance is computed and how to replace it"

Effort Estimate

2–3 weeks (includes SPI design, extraction, alternative impl, tests, docs)

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions