Skip to content

Step 6: Forgetting service — decay scoring, contradiction detection, and autonomous pruning #40

Description

@Atharva-Kanherkar

Summary

Add a forgetting service that:

  • detects semantically related candidates when a new semantic memory is stored
  • lets the host LLM or operator decide whether a contradiction actually exists
  • periodically scores semantic, episodic, and procedural memories for keep / fade / prune
  • safely prunes records and owned media without introducing broken references

This issue body supersedes the previous plan where they conflict.

Validated conclusions

1. Exponential decay is still the right default

Keep an exponential half-life model for memory retention. This is consistent with MemoryBank, FadeMem, and the broader forgetting literature.

2. Generic embedding similarity is candidate retrieval only

The current repo uses generic semantic embeddings. Those embeddings are suitable for recalling topically related memories, but they must not be treated as contradiction judges.

The safe design is still two-phase:

  1. embeddings recall candidates
  2. the host LLM or operator judges the logical relationship

3. Forgetting needs mutation primitives, not just scan + delete

The current stores can read, write, retrieve, and update access metadata, but they cannot yet:

  • scan all records through the public interface
  • delete arbitrary records through the public interface
  • replace or mutate an existing record through the public interface

Fade and supersession both require mutation support.

4. Duplicate handling must happen before final bucket assignment

The forgetting cycle cannot:

  1. score
  2. bucket
  3. then flag likely duplicates

That ordering leaves stale buckets. Duplicate or superseded records must either:

  • be forced into the prune path before bucketing, or
  • trigger a second bucketing pass

5. Prune order should be DB first, media second

Delete the ChromaDB record first, then delete owned media. If media deletion fails, log the orphan and continue. That leaves no live record pointing at a missing file.

6. CLI should call the API for forgetting operations

The forgetting cycle should run inside the API service rather than through a second local CLI process opening the same persistent Chroma database. There are open Chroma reports where get() and vector query() diverge across processes on the same persistent store.

7. Reuse the existing event surface

The repo already has an in-memory event recorder and /api/events. Forgetting should extend that surface rather than introduce a parallel history subsystem in v1.

Store capabilities required first

Before any forgetting logic, the store layer needs:

  • get_all_records(include_embeddings: bool = False) -> list[MemoryRecord]
  • delete(record_id: str) -> None
  • replace(record: MemoryRecord) -> None or update_record(record)

This is a hard dependency for the rest of Step 6.

Updated architecture

flowchart TD
    subgraph "Real-time semantic store path"
        A[Store semantic memory] --> B[Use stored embedding to find related candidates]
        B --> C[Return potential_contradictions to caller]
        C --> D[Host LLM or operator judges]
        D -->|Confirmed replacement| E[Resolve supersession]
        D -->|No contradiction| F[No mutation]
    end

    subgraph "Batch forgetting cycle"
        G[Scan all stores] --> H[Find likely duplicate semantic pairs]
        H --> I[Build forced-prune / forced-zero-importance set]
        I --> J[Compute decay score with one snapshot time]
        J --> K[Bucket keep / fade / prune]
        K --> L[Execute writes and deletes]
        L --> M[Emit events and return report]
    end
Loading

Updated sub-issue map

Updated delivery order

  1. 6A: Store interface extensions — scan, delete, and record mutation #41 — store primitives
  2. 6B: Decay scoring function #42 — decay scoring
  3. 6C: Contradiction detection — similarity candidates and supersession flagging #43 — candidate retrieval + supersession resolution
  4. 6D: Pruning cycle — scan, score, fade/prune, media cleanup #44 — forgetting cycle
  5. 6E: API endpoints, events, CLI, UI, and full integration test #45 — API/UI/CLI wiring and end-to-end tests

Decisions locked for v1

Decision Why
Exponential decay Supported by the cited memory systems and forgetting literature
Generic embeddings only recall candidates Safe with the current embedding stack
No auto-delete from semantic similarity alone Similarity is not contradiction judgment
Importance floor for critical memories Preserves durable facts
DB delete before media delete Safer failure mode
Batch deletes Reduces long lock windows
CLI calls API for forgetting Avoids multi-process Chroma consistency risk
Reuse /api/events Existing surface already exists in the repo

References checked during research

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions