Class: Legion::Extensions::Agentic::Memory::Semantic::Helpers::Concept
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Memory::Semantic::Helpers::Concept
- Defined in:
- lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb
Instance Attribute Summary collapse
-
#access_count ⇒ Object
Returns the value of attribute access_count.
-
#confidence ⇒ Object
Returns the value of attribute confidence.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Instance Method Summary collapse
- #access ⇒ Object
- #add_relation(type:, target_name:, confidence: nil) ⇒ Object
- #decay ⇒ Object
- #faded? ⇒ Boolean
- #get_property(key) ⇒ Object
-
#initialize(name:, domain: :general, confidence: nil, properties: {}) ⇒ Concept
constructor
A new instance of Concept.
- #label ⇒ Object
- #related_concepts ⇒ Object
- #relations_of_type(type) ⇒ Object
- #set_property(key, value) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name:, domain: :general, confidence: nil, properties: {}) ⇒ Concept
Returns a new instance of Concept.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 13 def initialize(name:, domain: :general, confidence: nil, properties: {}) @id = SecureRandom.uuid @name = name @domain = domain @confidence = (confidence || Constants::DEFAULT_CONFIDENCE).clamp(0.0, 1.0) @properties = properties.dup @relations = [] @access_count = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#access_count ⇒ Object
Returns the value of attribute access_count.
11 12 13 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 11 def access_count @access_count end |
#confidence ⇒ Object
Returns the value of attribute confidence.
11 12 13 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 11 def confidence @confidence end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 10 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 10 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 10 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 10 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
10 11 12 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 10 def properties @properties end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
10 11 12 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 10 def relations @relations end |
Instance Method Details
#access ⇒ Object
55 56 57 58 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 55 def access @access_count += 1 @confidence = [@confidence + Constants::ACCESS_BOOST, 1.0].min end |
#add_relation(type:, target_name:, confidence: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 24 def add_relation(type:, target_name:, confidence: nil) return false unless Constants::RELATION_TYPES.include?(type) existing = @relations.find { |r| r[:type] == type && r[:target] == target_name } if existing existing[:confidence] = [existing[:confidence] + Constants::ACCESS_BOOST, 1.0].min return existing end trim_relations if @relations.size >= Constants::MAX_RELATIONS_PER_CONCEPT rel = { type: type, target: target_name, confidence: (confidence || Constants::DEFAULT_CONFIDENCE).clamp(0.0, 1.0) } @relations << rel rel end |
#decay ⇒ Object
60 61 62 63 64 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 60 def decay @confidence = [@confidence - Constants::CONFIDENCE_DECAY, Constants::CONFIDENCE_FLOOR].max @relations.each { |r| r[:confidence] = [r[:confidence] - Constants::CONFIDENCE_DECAY, Constants::CONFIDENCE_FLOOR].max } @relations.reject! { |r| r[:confidence] <= Constants::CONFIDENCE_FLOOR } end |
#faded? ⇒ Boolean
66 67 68 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 66 def faded? @confidence <= Constants::CONFIDENCE_FLOOR end |
#get_property(key) ⇒ Object
51 52 53 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 51 def get_property(key) @properties[key] end |
#label ⇒ Object
70 71 72 73 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 70 def label Constants::CONFIDENCE_LABELS.each { |range, lbl| return lbl if range.cover?(@confidence) } :uncertain end |
#related_concepts ⇒ Object
43 44 45 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 43 def @relations.map { |r| r[:target] }.uniq end |
#relations_of_type(type) ⇒ Object
39 40 41 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 39 def relations_of_type(type) @relations.select { |r| r[:type] == type } end |
#set_property(key, value) ⇒ Object
47 48 49 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 47 def set_property(key, value) @properties[key] = value end |
#to_h ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb', line 75 def to_h { id: @id, name: @name, domain: @domain, confidence: @confidence, properties: @properties, relations: @relations, access_count: @access_count, label: label, created_at: @created_at } end |