Class: Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::CognitiveInput

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb

Constant Summary

Constants included from Constants

Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::ATTENTION_THRESHOLD, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::DEFAULT_EFFECT, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::DEFAULT_EFFORT, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::EFFECT_CEILING, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::EFFECT_DECAY, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::EFFECT_FLOOR, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::EFFECT_TYPES, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::EFFORT_CEILING, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::EFFORT_FLOOR, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::EFFORT_INFLATION, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::INPUT_TYPES, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::MAX_CONTEXTS, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::MAX_HISTORY, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::MAX_INPUTS, Legion::Extensions::Agentic::Attention::RelevanceTheory::Helpers::Constants::RELEVANCE_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, input_type:, context:, cognitive_effect: DEFAULT_EFFECT, processing_effort: DEFAULT_EFFORT, effect_type: :new_implication, source_id: nil) ⇒ CognitiveInput

Returns a new instance of CognitiveInput.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 17

def initialize(content:, input_type:, context:, cognitive_effect: DEFAULT_EFFECT,
               processing_effort: DEFAULT_EFFORT, effect_type: :new_implication,
               source_id: nil)
  @id                = SecureRandom.uuid
  @content           = content
  @input_type        = input_type
  @context           = context
  @cognitive_effect  = cognitive_effect.clamp(EFFECT_FLOOR, EFFECT_CEILING)
  @processing_effort = processing_effort.clamp(EFFORT_FLOOR, EFFORT_CEILING)
  @effect_type       = effect_type
  @source_id         = source_id
  @created_at        = Time.now.utc
end

Instance Attribute Details

#cognitive_effectObject (readonly)

Returns the value of attribute cognitive_effect.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def cognitive_effect
  @cognitive_effect
end

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def content
  @content
end

#contextObject (readonly)

Returns the value of attribute context.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def context
  @context
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def created_at
  @created_at
end

#effect_typeObject (readonly)

Returns the value of attribute effect_type.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def effect_type
  @effect_type
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def id
  @id
end

#input_typeObject (readonly)

Returns the value of attribute input_type.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def input_type
  @input_type
end

#processing_effortObject (readonly)

Returns the value of attribute processing_effort.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def processing_effort
  @processing_effort
end

#source_idObject (readonly)

Returns the value of attribute source_id.



14
15
16
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 14

def source_id
  @source_id
end

Instance Method Details

#decay!Object



60
61
62
63
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 60

def decay!
  @cognitive_effect  = (@cognitive_effect - EFFECT_DECAY).clamp(EFFECT_FLOOR, EFFECT_CEILING)
  @processing_effort = (@processing_effort + EFFORT_INFLATION).clamp(EFFORT_FLOOR, EFFORT_CEILING)
end

#increase_effort!(amount: 0.1) ⇒ Object



56
57
58
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 56

def increase_effort!(amount: 0.1)
  @processing_effort = (@processing_effort + amount).clamp(EFFORT_FLOOR, EFFORT_CEILING)
end

#normalized_relevanceObject



35
36
37
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 35

def normalized_relevance
  relevance.clamp(0.0, 1.0)
end

#relevanceObject



31
32
33
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 31

def relevance
  @cognitive_effect / @processing_effort
end

#relevance_labelObject



39
40
41
42
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 39

def relevance_label
  nr = normalized_relevance
  RELEVANCE_LABELS.find { |range, _| range.cover?(nr) }&.last || :irrelevant
end

#strengthen!(amount: 0.1) ⇒ Object



48
49
50
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 48

def strengthen!(amount: 0.1)
  @cognitive_effect = (@cognitive_effect + amount).clamp(EFFECT_FLOOR, EFFECT_CEILING)
end

#to_hObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 65

def to_h
  {
    id:                @id,
    content:           @content,
    input_type:        @input_type,
    context:           @context,
    cognitive_effect:  @cognitive_effect,
    processing_effort: @processing_effort,
    relevance:         relevance.round(3),
    normalized:        normalized_relevance.round(3),
    relevance_label:   relevance_label,
    worth_processing:  worth_processing?,
    effect_type:       @effect_type,
    source_id:         @source_id,
    created_at:        @created_at
  }
end

#weaken!(amount: 0.1) ⇒ Object



52
53
54
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 52

def weaken!(amount: 0.1)
  @cognitive_effect = (@cognitive_effect - amount).clamp(EFFECT_FLOOR, EFFECT_CEILING)
end

#worth_processing?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/legion/extensions/agentic/attention/relevance_theory/helpers/cognitive_input.rb', line 44

def worth_processing?
  normalized_relevance >= ATTENTION_THRESHOLD
end