Class PostgresRepresentationStore

java.lang.Object
at.aimon.memory.postgres.PostgresRepresentationStore
All Implemented Interfaces:
at.aimon.core.memory.RepresentationStore

public final class PostgresRepresentationStore extends Object implements at.aimon.core.memory.RepresentationStore
Postgres-backed RepresentationStore per design §5.3 / §5.5.

Representations are append-only. save(at.aimon.core.memory.Representation) always inserts a new row in mem_representation; the typed columns (subject_*, observer_*, session_id, generated_at) drive the two indexes that satisfy findLatestGlobal(at.aimon.core.memory.PeerView) and findLatestLocal(at.aimon.core.memory.PeerView, at.aimon.core.memory.PeerView, java.lang.String), while a self-contained JSONB snapshot (encoded by RepresentationRowCodec) lives in payload_blob and is the single source of truth for hydration. Storing the full snapshot in JSONB preserves immutability across later observation deletions: a representation captures "what we knew at time T", and that capture must not be silently mutated when the underlying observations are later GC'd.

The observation_local_ids JSONB column is written for cross-table audits / housekeeping queries (e.g. "which representations referenced this observation?") but is not required for read-side hydration.

  • Constructor Details

    • PostgresRepresentationStore

      public PostgresRepresentationStore(DataSource dataSource, com.fasterxml.jackson.databind.ObjectMapper mapper)
  • Method Details

    • save

      public at.aimon.core.memory.Representation save(at.aimon.core.memory.Representation representation)
      Specified by:
      save in interface at.aimon.core.memory.RepresentationStore
    • findLatestGlobal

      public Optional<at.aimon.core.memory.Representation> findLatestGlobal(at.aimon.core.memory.PeerView subject)
      Specified by:
      findLatestGlobal in interface at.aimon.core.memory.RepresentationStore
    • findLatestLocal

      public Optional<at.aimon.core.memory.Representation> findLatestLocal(at.aimon.core.memory.PeerView subject, at.aimon.core.memory.PeerView observer, String sessionId)
      Specified by:
      findLatestLocal in interface at.aimon.core.memory.RepresentationStore
    • deleteOlderThan

      public void deleteOlderThan(at.aimon.core.memory.Workspace workspace, Instant cutoff)
      Specified by:
      deleteOlderThan in interface at.aimon.core.memory.RepresentationStore