Class: Rubino::Memory::Backend
- Inherits:
-
Object
- Object
- Rubino::Memory::Backend
- Defined in:
- lib/rubino/memory/backend.rb
Overview
Duck-typed contract for a pluggable memory backend.
A backend owns the WRITE path (store / replace / forget / extract), the READ path the prompt assembler depends on (user_profile / project_context / retrieve), and the admin surface that powers ‘rubino memory …` (list / find). The method set is the union of what the rest of the gem already calls today — extracting this interface is a mechanical refactor, not a rewrite.
The injection-defense floor (ThreatScanner + the char-budget enforced in Memory::Store) lives in the shared write path, so no backend can splice tainted or over-budget content into a future system prompt. Concrete backends override only what they need; the base raises NotImplementedError for the operations that have no sensible default.
Direct Known Subclasses
Rubino::Memory::Backends::Default, Rubino::Memory::Backends::Sqlite
Class Method Summary collapse
-
.backend_name ⇒ Object
Backend registry key (e.g. “default”).
Instance Method Summary collapse
-
#available? ⇒ Boolean
Deps present + configured (no network).
-
#count ⇒ Object
Total number of stored memories.
- #delete(id) ⇒ Object
-
#extract(session_id) ⇒ Object
Mine a session’s messages for durable facts and persist them.
- #find(id) ⇒ Object
-
#forget(kind:, old_text:) ⇒ Object
Delete the first entry of ‘kind` whose content includes `old_text`.
-
#initialize(config: nil) ⇒ Backend
constructor
A new instance of Backend.
-
#list(kind: nil, limit: 20, include_retired: false) ⇒ Object
Live entries only by default; ‘include_retired: true` opts into the supersession history on backends that soft-retire (sqlite).
-
#project_context ⇒ Object
Project-context text (String) or nil.
-
#replace(kind:, old_text:, content:) ⇒ Object
Replace the content of the first entry of ‘kind` whose content includes `old_text`.
-
#retrieve(session_id:, query: nil) ⇒ Object
Memories relevant to the turn.
-
#store(kind:, content:, source_session_id: nil, confidence: 1.0, metadata: {}) ⇒ Object
Persist one memory entry.
-
#user_profile ⇒ Object
User-profile text (String) or nil.
Constructor Details
#initialize(config: nil) ⇒ Backend
Returns a new instance of Backend.
25 26 27 |
# File 'lib/rubino/memory/backend.rb', line 25 def initialize(config: nil) @config = config || Rubino.configuration end |
Class Method Details
.backend_name ⇒ Object
Backend registry key (e.g. “default”). Subclasses must override.
21 22 23 |
# File 'lib/rubino/memory/backend.rb', line 21 def self.backend_name raise NotImplementedError, "#{self} must define .backend_name" end |
Instance Method Details
#available? ⇒ Boolean
Deps present + configured (no network). Backends with optional dependencies override this; the default is always available.
31 32 33 |
# File 'lib/rubino/memory/backend.rb', line 31 def available? true end |
#count ⇒ Object
Total number of stored memories. Powers the CLI /status line and the web dashboard’s memory card via GET /v1/memory/stats.
99 100 101 |
# File 'lib/rubino/memory/backend.rb', line 99 def count raise NotImplementedError, "#{self.class} must implement #count" end |
#delete(id) ⇒ Object
93 94 95 |
# File 'lib/rubino/memory/backend.rb', line 93 def delete(id) raise NotImplementedError, "#{self.class} must implement #delete" end |
#extract(session_id) ⇒ Object
Mine a session’s messages for durable facts and persist them. Returns the list of stored entries.
57 58 59 |
# File 'lib/rubino/memory/backend.rb', line 57 def extract(session_id) raise NotImplementedError, "#{self.class} must implement #extract" end |
#find(id) ⇒ Object
89 90 91 |
# File 'lib/rubino/memory/backend.rb', line 89 def find(id) raise NotImplementedError, "#{self.class} must implement #find" end |
#forget(kind:, old_text:) ⇒ Object
Delete the first entry of ‘kind` whose content includes `old_text`. Returns the matched row, or nil if nothing matched.
51 52 53 |
# File 'lib/rubino/memory/backend.rb', line 51 def forget(kind:, old_text:) raise NotImplementedError, "#{self.class} must implement #forget" end |
#list(kind: nil, limit: 20, include_retired: false) ⇒ Object
Live entries only by default; ‘include_retired: true` opts into the supersession history on backends that soft-retire (sqlite).
85 86 87 |
# File 'lib/rubino/memory/backend.rb', line 85 def list(kind: nil, limit: 20, include_retired: false) raise NotImplementedError, "#{self.class} must implement #list" end |
#project_context ⇒ Object
Project-context text (String) or nil.
69 70 71 |
# File 'lib/rubino/memory/backend.rb', line 69 def project_context raise NotImplementedError, "#{self.class} must implement #project_context" end |
#replace(kind:, old_text:, content:) ⇒ Object
Replace the content of the first entry of ‘kind` whose content includes `old_text`. Returns the matched row, or nil if nothing matched.
45 46 47 |
# File 'lib/rubino/memory/backend.rb', line 45 def replace(kind:, old_text:, content:) raise NotImplementedError, "#{self.class} must implement #replace" end |
#retrieve(session_id:, query: nil) ⇒ Object
Memories relevant to the turn. ‘query` lets a relevance-aware backend rank by the last user message; the default backend ignores it and returns everything that fits, exactly as today. Returns an array of rows ([kind:, content:, …]).
77 78 79 |
# File 'lib/rubino/memory/backend.rb', line 77 def retrieve(session_id:, query: nil) raise NotImplementedError, "#{self.class} must implement #retrieve" end |
#store(kind:, content:, source_session_id: nil, confidence: 1.0, metadata: {}) ⇒ Object
Persist one memory entry. Returns the stored row (Hash) or raises a Memory::Store::ThreatDetectedError / BudgetExceededError on refusal.
39 40 41 |
# File 'lib/rubino/memory/backend.rb', line 39 def store(kind:, content:, source_session_id: nil, confidence: 1.0, metadata: {}) raise NotImplementedError, "#{self.class} must implement #store" end |
#user_profile ⇒ Object
User-profile text (String) or nil.
64 65 66 |
# File 'lib/rubino/memory/backend.rb', line 64 def user_profile raise NotImplementedError, "#{self.class} must implement #user_profile" end |