Module: Legion::Extensions::Agentic::Memory::Semantic::Runners::SemanticMemory

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb

Instance Method Summary collapse

Instance Method Details

#activate_spread(seed:, hops: nil) ⇒ Object



55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 55

def activate_spread(seed:, hops: nil, **)
  hop_count = hops || Helpers::Constants::MAX_SPREAD_HOPS
  activated = knowledge_store.spreading_activation(seed: seed, hops: hop_count)
  log.debug("[semantic_memory] spread: seed=#{seed} hops=#{hop_count} activated=#{activated.size}")
  { success: true, seed: seed, activated: activated, count: activated.size }
end

#check_category(concept:, category:) ⇒ Object



43
44
45
46
47
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 43

def check_category(concept:, category:, **)
  result = knowledge_store.check_is_a(concept, category)
  log.debug("[semantic_memory] check_category: #{concept} is_a #{category} = #{result}")
  { success: true, concept: concept, category: category, is_member: result }
end

#concepts_in(domain:) ⇒ Object



62
63
64
65
66
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 62

def concepts_in(domain:, **)
  concepts = knowledge_store.concepts_in_domain(domain)
  log.debug("[semantic_memory] domain_query: domain=#{domain} count=#{concepts.size}")
  { success: true, domain: domain, concepts: concepts.map(&:name), count: concepts.size }
end

#find_instances(category:) ⇒ Object



49
50
51
52
53
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 49

def find_instances(category:, **)
  instances = knowledge_store.instances_of(category)
  log.debug("[semantic_memory] instances_of: #{category} count=#{instances.size}")
  { success: true, category: category, instances: instances.map(&:name), count: instances.size }
end

#query_concept_relations(name:, type: nil) ⇒ Object



37
38
39
40
41
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 37

def query_concept_relations(name:, type: nil, **)
  relations = knowledge_store.query_relations(name: name, type: type&.to_sym)
  log.debug("[semantic_memory] query_relations: name=#{name} type=#{type} count=#{relations.size}")
  { success: true, name: name, relations: relations, count: relations.size }
end

#relate_concepts(source:, target:, type:, confidence: nil) ⇒ Object



19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 19

def relate_concepts(source:, target:, type:, confidence: nil, **)
  type_sym = type.to_sym
  result = knowledge_store.relate(source: source, target: target, type: type_sym, confidence: confidence)
  log.debug("[semantic_memory] relate: #{source} --#{type_sym}--> #{target}")
  { success: true, source: source, target: target, type: type_sym, relation: result }
end

#retrieve_concept(name:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 26

def retrieve_concept(name:, **)
  concept = knowledge_store.retrieve(name: name)
  if concept
    log.debug("[semantic_memory] retrieve: name=#{name} conf=#{concept.confidence.round(3)}")
    { success: true, found: true, concept: concept.to_h }
  else
    log.debug("[semantic_memory] retrieve: name=#{name} not_found")
    { success: true, found: false, name: name }
  end
end

#semantic_memory_statsObject



79
80
81
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 79

def semantic_memory_stats(**)
  { success: true, stats: knowledge_store.to_h }
end

#store_concept(name:, domain: :general, confidence: nil, properties: {}) ⇒ Object



13
14
15
16
17
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 13

def store_concept(name:, domain: :general, confidence: nil, properties: {}, **)
  concept = knowledge_store.store(name: name, domain: domain, confidence: confidence, properties: properties)
  log.debug("[semantic_memory] store: name=#{name} domain=#{domain} conf=#{concept.confidence.round(3)}")
  { success: true, concept: concept.to_h }
end

#update_semantic_memoryObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb', line 68

def update_semantic_memory(**)
  knowledge_store.decay_all
  log.debug("[semantic_memory] tick: concepts=#{knowledge_store.concept_count} " \
            "relations=#{knowledge_store.relation_count}")
  {
    success:   true,
    concepts:  knowledge_store.concept_count,
    relations: knowledge_store.relation_count
  }
end