Module: Engram::Ports::MemoryStore
- Included in:
- Adapters::InMemoryStore, Adapters::PgvectorStore
- Defined in:
- lib/engram/ports/memory_store.rb
Overview
Contract for a place memories are persisted and searched. Implementations: Adapters::InMemoryStore, Adapters::PgvectorStore.
Instance Method Summary collapse
-
#add(record) ⇒ Object
Persist a Record.
-
#all(scope:) ⇒ Object
All Records for a scope (mostly for inspection/tests).
-
#delete(id:) ⇒ Object
Remove a memory by id.
-
#search(embedding:, scope:, limit:, kinds: nil) ⇒ Object
Return up to ‘limit` Records in `scope` nearest to `embedding`, ordered most-relevant first.
-
#touch(id:, at: Time.now) ⇒ Object
Update the last-accessed timestamp of a memory.
-
#update(id:, record:) ⇒ Object
Replace the content/embedding of an existing memory.
Instance Method Details
#add(record) ⇒ Object
Persist a Record. Returns the stored Record.
9 10 11 |
# File 'lib/engram/ports/memory_store.rb', line 9 def add(record) raise NotImplementedError, "#{self.class} must implement #add" end |
#all(scope:) ⇒ Object
All Records for a scope (mostly for inspection/tests).
21 22 23 |
# File 'lib/engram/ports/memory_store.rb', line 21 def all(scope:) raise NotImplementedError, "#{self.class} must implement #all" end |
#delete(id:) ⇒ Object
Remove a memory by id. Used by consolidation (FORGET).
32 33 34 |
# File 'lib/engram/ports/memory_store.rb', line 32 def delete(id:) raise NotImplementedError, "#{self.class} must implement #delete" end |
#search(embedding:, scope:, limit:, kinds: nil) ⇒ Object
Return up to ‘limit` Records in `scope` nearest to `embedding`, ordered most-relevant first. When `kinds` is provided, only records with those canonical memory kinds are eligible.
16 17 18 |
# File 'lib/engram/ports/memory_store.rb', line 16 def search(embedding:, scope:, limit:, kinds: nil) raise NotImplementedError, "#{self.class} must implement #search" end |
#touch(id:, at: Time.now) ⇒ Object
Update the last-accessed timestamp of a memory. Used by recency-aware recall.
37 38 39 |
# File 'lib/engram/ports/memory_store.rb', line 37 def touch(id:, at: Time.now) raise NotImplementedError, "#{self.class} must implement #touch" end |
#update(id:, record:) ⇒ Object
Replace the content/embedding of an existing memory. Used by consolidation (UPDATE). Returns the updated Record.
27 28 29 |
# File 'lib/engram/ports/memory_store.rb', line 27 def update(id:, record:) raise NotImplementedError, "#{self.class} must implement #update" end |