Class: Legion::Extensions::Agentic::Memory::Offloading::Helpers::ExternalStore

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb

Constant Summary

Constants included from Constants

Constants::DEFAULT_STORE_TRUST, Constants::IMPORTANCE_LABELS, Constants::ITEM_TYPES, Constants::MAX_ITEMS, Constants::MAX_STORES, Constants::OFFLOAD_LABELS, Constants::RETRIEVAL_SUCCESS_THRESHOLD, Constants::STORE_TYPES, Constants::TRUST_BOOST, Constants::TRUST_DECAY, Constants::TRUST_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, store_type:) ⇒ ExternalStore

Returns a new instance of ExternalStore.



18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 18

def initialize(name:, store_type:)
  @id                   = ::SecureRandom.uuid
  @name                 = name
  @store_type           = store_type
  @trust                = DEFAULT_STORE_TRUST
  @items_stored         = 0
  @successful_retrievals = 0
  @failed_retrievals     = 0
  @created_at = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def created_at
  @created_at
end

#failed_retrievalsObject (readonly)

Returns the value of attribute failed_retrievals.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def failed_retrievals
  @failed_retrievals
end

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def id
  @id
end

#items_storedObject (readonly)

Returns the value of attribute items_stored.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def items_stored
  @items_stored
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def name
  @name
end

#store_typeObject (readonly)

Returns the value of attribute store_type.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def store_type
  @store_type
end

#successful_retrievalsObject (readonly)

Returns the value of attribute successful_retrievals.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def successful_retrievals
  @successful_retrievals
end

#trustObject (readonly)

Returns the value of attribute trust.



15
16
17
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 15

def trust
  @trust
end

Instance Method Details

#increment_items!Object



29
30
31
32
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 29

def increment_items!
  @items_stored += 1
  self
end

#record_failure!Object



40
41
42
43
44
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 40

def record_failure!
  @failed_retrievals += 1
  @trust = (@trust - TRUST_DECAY).clamp(0.0, 1.0).round(10)
  self
end

#record_success!Object



34
35
36
37
38
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 34

def record_success!
  @successful_retrievals += 1
  @trust = (@trust + TRUST_BOOST).clamp(0.0, 1.0).round(10)
  self
end

#reliable?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 53

def reliable?
  @trust >= RETRIEVAL_SUCCESS_THRESHOLD
end

#retrieval_rateObject



46
47
48
49
50
51
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 46

def retrieval_rate
  total = @successful_retrievals + @failed_retrievals
  return 0.0 if total.zero?

  (@successful_retrievals.to_f / total).round(10)
end

#to_hObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 61

def to_h
  {
    id:                    @id,
    name:                  @name,
    store_type:            @store_type,
    trust:                 @trust.round(10),
    trust_label:           trust_label,
    items_stored:          @items_stored,
    successful_retrievals: @successful_retrievals,
    failed_retrievals:     @failed_retrievals,
    retrieval_rate:        retrieval_rate,
    reliable:              reliable?,
    created_at:            @created_at
  }
end

#trust_labelObject



57
58
59
# File 'lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb', line 57

def trust_label
  TRUST_LABELS.find { |range, _| range.cover?(@trust) }&.last || :unreliable
end