Class: Phronomy::Memory::Storage::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/memory/storage/base.rb

Overview

This class is abstract.

Subclass and implement all abstract methods.

Abstract base class for conversation storage backends.

Each backend manages two independent datasets per thread:

  1. Raw messages — the original, unmodified conversation history. Every message is stored with a monotonically increasing seq number (0-based, scoped to thread_id). Raw messages are never modified or deleted; they are the authoritative record.

  2. Compaction records — the output of LLM-based compaction (summarization). Each record covers a contiguous range [start_seq..end_seq] of raw messages and stores the summary text produced for that range. Multiple non-overlapping compaction records may exist per thread.

The conventional load/save/clear interface is kept for use by ConversationManager (compression path) and direct storage access.

Direct Known Subclasses

ActiveRecord, InMemory

Instance Method Summary collapse

Instance Method Details

#append_raw(thread_id:, messages:, starting_seq:) ⇒ Object

Append new messages to the raw history for a thread. Each message is stored together with its seq number.

Parameters:

  • thread_id (String)
  • messages (Array)

    message objects to append

  • starting_seq (Integer)

    seq number to assign to messages[0]

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/phronomy/memory/storage/base.rb', line 62

def append_raw(thread_id:, messages:, starting_seq:)
  raise NotImplementedError, "#{self.class}#append_raw is not implemented"
end

#clear(thread_id:) ⇒ Object

Delete all messages for a thread.

Parameters:

  • thread_id (String)

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/phronomy/memory/storage/base.rb', line 48

def clear(thread_id:)
  raise NotImplementedError, "#{self.class}#clear is not implemented"
end

#clear_compactions(thread_id:) ⇒ Object

Delete all compaction records for a thread.

Parameters:

  • thread_id (String)

Raises:

  • (NotImplementedError)


108
109
110
# File 'lib/phronomy/memory/storage/base.rb', line 108

def clear_compactions(thread_id:)
  raise NotImplementedError, "#{self.class}#clear_compactions is not implemented"
end

#clear_raw(thread_id:) ⇒ Object

Delete raw messages for a thread (used in #clear).

Parameters:

  • thread_id (String)

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/phronomy/memory/storage/base.rb', line 77

def clear_raw(thread_id:)
  raise NotImplementedError, "#{self.class}#clear_raw is not implemented"
end

#load(thread_id:) ⇒ Array

Load all messages for a thread in chronological order.

Parameters:

  • thread_id (String)

Returns:

  • (Array)

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/phronomy/memory/storage/base.rb', line 33

def load(thread_id:)
  raise NotImplementedError, "#{self.class}#load is not implemented"
end

#load_compactions(thread_id:) ⇒ Array<Hash>

Return all compaction records for a thread in ascending start_seq order.

Parameters:

  • thread_id (String)

Returns:

  • (Array<Hash>)

    each entry: { start_seq:, end_seq:, summary_text: }

Raises:

  • (NotImplementedError)


101
102
103
# File 'lib/phronomy/memory/storage/base.rb', line 101

def load_compactions(thread_id:)
  raise NotImplementedError, "#{self.class}#load_compactions is not implemented"
end

#load_raw(thread_id:) ⇒ Array<Hash>

Return all raw messages for a thread as an array of hashes.

Parameters:

  • thread_id (String)

Returns:

  • (Array<Hash>)

    each entry: { seq: Integer, message: Object }

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/phronomy/memory/storage/base.rb', line 70

def load_raw(thread_id:)
  raise NotImplementedError, "#{self.class}#load_raw is not implemented"
end

#purge(thread_id:) ⇒ Object

Remove all stored data (raw messages, compaction records, legacy store) for a thread. Equivalent to #clear, provided as a named alias to make the "right to erasure" intent explicit.

Parameters:

  • thread_id (String)


117
118
119
# File 'lib/phronomy/memory/storage/base.rb', line 117

def purge(thread_id:)
  clear(thread_id: thread_id)
end

#purge_older_than(thread_id:, older_than:) ⇒ Object

Remove raw messages recorded before +older_than+ for a thread. The default implementation is a no-op; backends that support timestamp-based deletion should override this method.

Parameters:

  • thread_id (String)
  • older_than (Time)


127
128
129
# File 'lib/phronomy/memory/storage/base.rb', line 127

def purge_older_than(thread_id:, older_than:)
  # no-op by default
end

#save(thread_id:, messages:) ⇒ Object

Persist messages for a thread (replaces existing messages).

Parameters:

  • thread_id (String)
  • messages (Array)

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/phronomy/memory/storage/base.rb', line 41

def save(thread_id:, messages:)
  raise NotImplementedError, "#{self.class}#save is not implemented"
end

#save_compaction(thread_id:, start_seq:, end_seq:, summary_text:) ⇒ Object

Persist a compaction record for a thread. A compaction record stores the LLM-generated summary that covers raw messages from start_seq to end_seq (inclusive).

Parameters:

  • thread_id (String)
  • start_seq (Integer)
  • end_seq (Integer)
  • summary_text (String)

Raises:

  • (NotImplementedError)


93
94
95
# File 'lib/phronomy/memory/storage/base.rb', line 93

def save_compaction(thread_id:, start_seq:, end_seq:, summary_text:)
  raise NotImplementedError, "#{self.class}#save_compaction is not implemented"
end