Class: Legion::Extensions::Agentic::Memory::SemanticSatiation::Helpers::SatiationEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::SemanticSatiation::Helpers::SatiationEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb
Constant Summary
Constants included
from Constants
Constants::DEFAULT_FLUENCY, Constants::FLUENCY_LABELS, Constants::MAX_CONCEPTS, Constants::NOVELTY_LABELS, Constants::RECOVERY_RATE, Constants::SATIATION_RATE, Constants::SATIATION_THRESHOLD
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SatiationEngine.
14
15
16
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 14
def initialize
@concepts = {}
end
|
Instance Attribute Details
#concepts ⇒ Object
Returns the value of attribute concepts.
12
13
14
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 12
def concepts
@concepts
end
|
Instance Method Details
#domain_satiation(domain:) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 60
def domain_satiation(domain:)
domain_concepts = @concepts.values.select { |c| c.domain == domain }
return 0.0 if domain_concepts.empty?
avg = domain_concepts.sum(&:fluency) / domain_concepts.size.to_f
avg.round(10)
end
|
#expose_by_label(label:, domain: :general) ⇒ Object
37
38
39
40
41
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 37
def expose_by_label(label:, domain: :general)
concept = find_by_label(label) || register_concept(label: label, domain: domain)
concept.expose!
concept.to_h
end
|
#expose_concept(concept_id:) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 29
def expose_concept(concept_id:)
concept = @concepts[concept_id]
return { error: :not_found, concept_id: concept_id } unless concept
concept.expose!
concept.to_h
end
|
#freshest(limit: 5) ⇒ Object
56
57
58
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 56
def freshest(limit: 5)
@concepts.values.sort_by { |c| -c.fluency }.first(limit)
end
|
#most_exposed(limit: 5) ⇒ Object
52
53
54
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 52
def most_exposed(limit: 5)
@concepts.values.sort_by { |c| -c.exposure_count }.first(limit)
end
|
#novelty_report ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 68
def novelty_report
distribution = Hash.new(0)
@concepts.each_value do |c|
distribution[c.novelty_label] += 1
end
distribution
end
|
#prune_saturated ⇒ Object
76
77
78
79
80
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 76
def prune_saturated
to_remove = @concepts.select { |_, c| c.fluency <= 0.05 }.keys
to_remove.each { |id| @concepts.delete(id) }
to_remove.size
end
|
#recover_all ⇒ Object
43
44
45
46
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 43
def recover_all
@concepts.each_value(&:recover!)
{ recovered: @concepts.size }
end
|
#register_concept(label:, domain: :general) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 18
def register_concept(label:, domain: :general)
prune_saturated if @concepts.size >= MAX_CONCEPTS
existing = find_by_label(label)
return existing if existing
concept = Concept.new(label: label, domain: domain)
@concepts[concept.id] = concept
concept
end
|
#satiated_concepts ⇒ Object
48
49
50
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 48
def satiated_concepts
@concepts.values.select(&:satiated?)
end
|
#to_h ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb', line 82
def to_h
{
concept_count: @concepts.size,
satiated_count: satiated_concepts.size,
novelty_report: novelty_report,
most_exposed: most_exposed.map(&:to_h),
freshest: freshest.map(&:to_h)
}
end
|