Class: Insika::Context::Providers::Memory

Inherits:
Insika::ContextProvider show all
Defined in:
lib/insika/context/providers/memory.rb

Overview

Read path for cross-session memory. Thin adapter over the MemoryStore — same pattern as the Skill/ToolSearch provider: one :system fragment with the tenant's facts + recent notes. Deterministic (no embeddings/ranking).

Instance Method Summary collapse

Methods inherited from Insika::ContextProvider

#id, #required?

Constructor Details

#initialize(store:, notes_limit: 10) ⇒ Memory

Returns a new instance of Memory.



11
12
13
14
# File 'lib/insika/context/providers/memory.rb', line 11

def initialize(store:, notes_limit: 10)
  @store = store
  @notes_limit = notes_limit
end

Instance Method Details

#call(request) ⇒ Object

required? == false (default): a failure (store unavailable) becomes a :provider_warning + graceful degradation — never aborts the turn.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/insika/context/providers/memory.rb', line 22

def call(request)
  tenant = memory_tenant(request)
  facts = @store.facts(tenant: tenant)
  notes = @store.notes(tenant: tenant, limit: @notes_limit)
  return [] if facts.empty? && notes.empty?

  # priority MEMORY (75): between skills (80) and deferred tools (70) in
  # the sacrifice order. pinned false (cuttable under a tight budget).
  [ContextFragment.build(content: format_block(facts, notes),
                         placement: :system, priority: Context::Priority::MEMORY, source: id)]
end

#enabled_for?(profile) ⇒ Boolean

Per-agent opt-in. The Builder still applies the context_providers allowlist on top (two gates, like the other providers).

Returns:

  • (Boolean)


18
# File 'lib/insika/context/providers/memory.rb', line 18

def enabled_for?(profile) = !!profile.memory