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:, limit: nil, offset: 0, after_id: nil) ⇒ Object
All Records for a scope (mostly for inspection/tests).
-
#delete(scope:, id:) ⇒ Object
Remove a memory by id.
-
#search(embedding:, scope:, limit:, kinds: nil, embedding_metadata: nil) ⇒ Object
Return up to
limitRecords inscopenearest toembedding, ordered most-relevant first. -
#touch(scope:, id:, at: Time.now) ⇒ Object
Update the last-accessed timestamp of a memory.
-
#update(scope:, 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:, limit: nil, offset: 0, after_id: nil) ⇒ Object
All Records for a scope (mostly for inspection/tests).
Supports optional limit and offset for batching large sweeps.
Returned records are sorted in stable id order when batching is used.
Use after_id for keyset pagination.
24 25 26 |
# File 'lib/engram/ports/memory_store.rb', line 24 def all(scope:, limit: nil, offset: 0, after_id: nil) raise NotImplementedError, "#{self.class} must implement #all" end |
#delete(scope:, id:) ⇒ Object
Remove a memory by id. Used by consolidation (FORGET). Returns the number of affected rows: 1 when deleted, 0 when the scoped record does not exist.
37 38 39 |
# File 'lib/engram/ports/memory_store.rb', line 37 def delete(scope:, id:) raise NotImplementedError, "#{self.class} must implement #delete" end |
#search(embedding:, scope:, limit:, kinds: nil, embedding_metadata: 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, embedding_metadata: nil) raise NotImplementedError, "#{self.class} must implement #search" end |
#touch(scope:, id:, at: Time.now) ⇒ Object
Update the last-accessed timestamp of a memory. Used by recency-aware recall. Returns the number of affected rows: 1 when touched, 0 when the scoped record does not exist.
44 45 46 |
# File 'lib/engram/ports/memory_store.rb', line 44 def touch(scope:, id:, at: Time.now) raise NotImplementedError, "#{self.class} must implement #touch" end |
#update(scope:, id:, record:) ⇒ Object
Replace the content/embedding of an existing memory. Used by consolidation (UPDATE). Returns the updated Record. Raises Engram::Error when the scoped record does not exist or the replacement would move it to another scope.
31 32 33 |
# File 'lib/engram/ports/memory_store.rb', line 31 def update(scope:, id:, record:) raise NotImplementedError, "#{self.class} must implement #update" end |