Class: Legion::Extensions::Agentic::Memory::Hologram::Helpers::HologramEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::Hologram::Helpers::HologramEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.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 Method Summary
collapse
Methods included from Constants
label_for
Constructor Details
Returns a new instance of HologramEngine.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 12
def initialize
@holograms = {}
end
|
Instance Method Details
#best_preserved(limit: 5) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 60
def best_preserved(limit: 5)
@holograms.values
.select { |h| h.fragments.any? }
.sort_by { |h| -h.resolution }
.first(limit)
end
|
#create_hologram(domain:, content:) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 16
def create_hologram(domain:, content:)
prune! if @holograms.size >= Constants::MAX_HOLOGRAMS
hologram = Hologram.new(domain: domain, content: content)
@holograms[hologram.id] = hologram
hologram
end
|
#degrade_all! ⇒ Object
54
55
56
57
58
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 54
def degrade_all!
@holograms.each_value do |hologram|
hologram.fragments.each(&:degrade!)
end
end
|
#fragment_hologram(hologram_id:, count: 4) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 24
def fragment_hologram(hologram_id:, count: 4)
hologram = @holograms[hologram_id]
return nil unless hologram
hologram.fragment!(count)
end
|
#get(hologram_id) ⇒ Object
93
94
95
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 93
def get(hologram_id)
@holograms[hologram_id]
end
|
#hologram_report ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 74
def hologram_report
total = @holograms.size
with_fragments = @holograms.values.count { |h| h.fragments.any? }
avg_resolution = resolution_average
{
total_holograms: total,
holograms_with_frags: with_fragments,
average_resolution: avg_resolution,
resolution_label: Constants.label_for(Constants::RESOLUTION_LABELS, avg_resolution),
best_preserved_count: best_preserved(limit: 3).size,
most_fragmented_count: most_fragmented(limit: 3).size
}
end
|
#holograms ⇒ Object
89
90
91
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 89
def holograms
@holograms.values
end
|
#measure_interference(hologram_id_a:, hologram_id_b:) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 39
def measure_interference(hologram_id_a:, hologram_id_b:)
holo_a = @holograms[hologram_id_a]
holo_b = @holograms[hologram_id_b]
return { interference: 0.0, label: :negligible, reason: :hologram_not_found } unless holo_a && holo_b
score = holo_a.interference_with(holo_b)
{
interference: score,
label: Constants.label_for(Constants::INTERFERENCE_LABELS, score),
hologram_a: hologram_id_a,
hologram_b: hologram_id_b
}
end
|
#most_fragmented(limit: 5) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 67
def most_fragmented(limit: 5)
@holograms.values
.select { |h| h.fragments.any? }
.sort_by(&:resolution)
.first(limit)
end
|
#reconstruct_from_fragments(fragment_ids:, hologram_id:) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb', line 31
def reconstruct_from_fragments(fragment_ids:, hologram_id:)
hologram = @holograms[hologram_id]
return { success: false, reason: :hologram_not_found } unless hologram
fragments = hologram.fragments.select { |f| fragment_ids.include?(f.id) }
hologram.reconstruct(fragments)
end
|