Class: Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::SemanticNode

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

Constant Summary

Constants included from Constants

Constants::ACTIVATION_DECAY, Constants::ACTIVATION_LABELS, Constants::ACTIVATION_THRESHOLD, Constants::DEFAULT_ACTIVATION, Constants::DEFAULT_WEIGHT, Constants::DEPTH_DECAY_FACTOR, Constants::MAX_ACTIVATION, Constants::MAX_CONNECTIONS, Constants::MAX_NODES, Constants::MAX_SPREAD_DEPTH, Constants::MIN_WEIGHT, Constants::NODE_TYPES, Constants::PRIMING_BOOST, Constants::PRIMING_LABELS, Constants::RESTING_ACTIVATION, Constants::SPREADING_FACTOR, Constants::WEIGHT_DECAY_RATE, Constants::WEIGHT_GROWTH_RATE, Constants::WEIGHT_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, node_type: :concept, activation: DEFAULT_ACTIVATION) ⇒ SemanticNode

Returns a new instance of SemanticNode.



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

def initialize(label:, node_type: :concept, activation: DEFAULT_ACTIVATION)
  @id           = SecureRandom.uuid
  @label        = label.to_s
  @node_type    = node_type.to_sym
  @activation   = activation.to_f.clamp(0.0, MAX_ACTIVATION).round(10)
  @prime_count  = 0
  @access_count = 0
  @created_at   = Time.now.utc
end

Instance Attribute Details

#access_countObject (readonly)

Returns the value of attribute access_count.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 14

def access_count
  @access_count
end

#activationObject (readonly)

Returns the value of attribute activation.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 14

def activation
  @activation
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 14

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 14

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 14

def label
  @label
end

#node_typeObject (readonly)

Returns the value of attribute node_type.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 14

def node_type
  @node_type
end

#prime_countObject (readonly)

Returns the value of attribute prime_count.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 14

def prime_count
  @prime_count
end

Instance Method Details

#access!Object



38
39
40
41
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 38

def access!
  @access_count += 1
  self
end

#activation_labelObject



56
57
58
59
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 56

def activation_label
  match = ACTIVATION_LABELS.find { |range, _| range.cover?(@activation) }
  match ? match.last : :unprimed
end

#active?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 52

def active?
  @activation > ACTIVATION_THRESHOLD
end

#decay!Object



33
34
35
36
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 33

def decay!
  @activation = (@activation - ACTIVATION_DECAY).clamp(0.0, MAX_ACTIVATION).round(10)
  self
end

#prime!(amount: PRIMING_BOOST) ⇒ Object



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

def prime!(amount: PRIMING_BOOST)
  @activation = (@activation + amount).clamp(0.0, MAX_ACTIVATION).round(10)
  @prime_count += 1
  self
end

#primed?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 48

def primed?
  @activation >= 0.4
end

#reset!Object



43
44
45
46
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb', line 43

def reset!
  @activation = RESTING_ACTIVATION
  self
end

#to_hObject



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

def to_h
  {
    id:               @id,
    label:            @label,
    node_type:        @node_type,
    activation:       @activation,
    activation_label: activation_label,
    primed:           primed?,
    active:           active?,
    prime_count:      @prime_count,
    access_count:     @access_count,
    created_at:       @created_at
  }
end