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

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

Constant Summary

Constants included from Constants

Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::ACTIVATION_DECAY, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::ACTIVATION_LABELS, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::ACTIVATION_THRESHOLD, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::DEFAULT_ACTIVATION, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::DEFAULT_WEIGHT, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::DEPTH_DECAY_FACTOR, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::MAX_ACTIVATION, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::MAX_CONNECTIONS, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::MAX_NODES, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::MAX_SPREAD_DEPTH, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::MIN_WEIGHT, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::NODE_TYPES, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::PRIMING_BOOST, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::PRIMING_LABELS, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::RESTING_ACTIVATION, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::SPREADING_FACTOR, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::WEIGHT_DECAY_RATE, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::WEIGHT_GROWTH_RATE, Legion::Extensions::Agentic::Memory::SemanticPriming::Helpers::Constants::WEIGHT_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_id:, target_id:, weight: DEFAULT_WEIGHT) ⇒ Connection

Returns a new instance of Connection.



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

def initialize(source_id:, target_id:, weight: DEFAULT_WEIGHT)
  @id              = SecureRandom.uuid
  @source_id       = source_id
  @target_id       = target_id
  @weight          = weight.to_f.clamp(MIN_WEIGHT, 1.0).round(10)
  @traversal_count = 0
  @created_at      = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.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/connection.rb', line 14

def id
  @id
end

#source_idObject (readonly)

Returns the value of attribute source_id.



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

def source_id
  @source_id
end

#target_idObject (readonly)

Returns the value of attribute target_id.



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

def target_id
  @target_id
end

#traversal_countObject (readonly)

Returns the value of attribute traversal_count.



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

def traversal_count
  @traversal_count
end

#weightObject (readonly)

Returns the value of attribute weight.



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

def weight
  @weight
end

Instance Method Details

#spreading_amount(source_activation) ⇒ Object



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

def spreading_amount(source_activation)
  (source_activation * @weight * SPREADING_FACTOR).round(10)
end

#strengthen!(amount: WEIGHT_GROWTH_RATE) ⇒ Object



25
26
27
28
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb', line 25

def strengthen!(amount: WEIGHT_GROWTH_RATE)
  @weight = (@weight + amount).clamp(MIN_WEIGHT, 1.0).round(10)
  self
end

#strong?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb', line 41

def strong?
  @weight >= 0.7
end

#to_hObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb', line 58

def to_h
  {
    id:              @id,
    source_id:       @source_id,
    target_id:       @target_id,
    weight:          @weight,
    weight_label:    weight_label,
    strong:          strong?,
    weak:            weak?,
    traversal_count: @traversal_count,
    created_at:      @created_at
  }
end

#traverse!Object



35
36
37
38
39
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb', line 35

def traverse!
  @traversal_count += 1
  strengthen!(amount: WEIGHT_GROWTH_RATE)
  self
end

#weak?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb', line 45

def weak?
  @weight <= 0.2
end

#weaken!(amount: WEIGHT_DECAY_RATE) ⇒ Object



30
31
32
33
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb', line 30

def weaken!(amount: WEIGHT_DECAY_RATE)
  @weight = (@weight - amount).clamp(MIN_WEIGHT, 1.0).round(10)
  self
end

#weight_labelObject



53
54
55
56
# File 'lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb', line 53

def weight_label
  match = WEIGHT_LABELS.find { |range, _| range.cover?(@weight) }
  match ? match.last : :very_weak
end