Class: Legion::Extensions::Agentic::Memory::Hologram::Helpers::HolographicFragment

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

Constant Summary

Constants included from Constants

Constants::FIDELITY_LABELS, Constants::FRAGMENT_LABELS, Constants::INTERFERENCE_DECAY, Constants::INTERFERENCE_LABELS, Constants::MAX_HOLOGRAMS, Constants::RECONSTRUCTION_THRESHOLD, Constants::RESOLUTION_LABELS, Constants::RESOLUTION_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

label_for

Constructor Details

#initialize(content:, parent_hologram_id:, completeness: 1.0, fidelity: 1.0) ⇒ HolographicFragment

Returns a new instance of HolographicFragment.



18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 18

def initialize(content:, parent_hologram_id:, completeness: 1.0, fidelity: 1.0)
  @id                = SecureRandom.uuid
  @content           = content
  @parent_hologram_id = parent_hologram_id
  @completeness      = completeness.clamp(0.0, 1.0)
  @fidelity          = fidelity.clamp(0.0, 1.0)
  @created_at        = Time.now.utc
end

Instance Attribute Details

#completenessObject

Returns the value of attribute completeness.



16
17
18
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 16

def completeness
  @completeness
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#fidelityObject

Returns the value of attribute fidelity.



16
17
18
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 16

def fidelity
  @fidelity
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#parent_hologram_idObject (readonly)

Returns the value of attribute parent_hologram_id.



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

def parent_hologram_id
  @parent_hologram_id
end

Instance Method Details

#completeness_labelObject



43
44
45
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 43

def completeness_label
  Constants.label_for(Constants::FRAGMENT_LABELS, @completeness)
end

#degrade!(rate = Constants::INTERFERENCE_DECAY) ⇒ Object



27
28
29
30
31
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 27

def degrade!(rate = Constants::INTERFERENCE_DECAY)
  @completeness = (@completeness - rate).round(10).clamp(0.0, 1.0)
  @fidelity     = (@fidelity - rate).round(10).clamp(0.0, 1.0)
  self
end

#enhance!(boost = 0.1) ⇒ Object



33
34
35
36
37
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 33

def enhance!(boost = 0.1)
  @completeness = (@completeness + boost).round(10).clamp(0.0, 1.0)
  @fidelity     = (@fidelity + boost).round(10).clamp(0.0, 1.0)
  self
end

#fidelity_labelObject



47
48
49
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 47

def fidelity_label
  Constants.label_for(Constants::FIDELITY_LABELS, @fidelity)
end

#sufficient?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 39

def sufficient?
  @completeness > Constants::RECONSTRUCTION_THRESHOLD
end

#to_hObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb', line 51

def to_h
  {
    id:                 @id,
    parent_hologram_id: @parent_hologram_id,
    content:            @content,
    completeness:       @completeness,
    fidelity:           @fidelity,
    completeness_label: completeness_label,
    fidelity_label:     fidelity_label,
    sufficient:         sufficient?,
    created_at:         @created_at.iso8601
  }
end