Class: SmartBrain::Governance::KnowledgeGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_brain/governance/knowledge_graph.rb

Overview

Knowledge graph: typed triples (subject-predicate-object) with temporal validity (valid_from/valid_to) over a MemoryStore. Orthogonal to the Stage-1 lifecycle and to memory_items — edges live in kg_edges and are added explicitly (via turn_events extraction) or by the agent.

Instance Method Summary collapse

Constructor Details

#initialize(memory_store:, config:) ⇒ KnowledgeGraph

Returns a new instance of KnowledgeGraph.



10
11
12
13
# File 'lib/smart_brain/governance/knowledge_graph.rb', line 10

def initialize(memory_store:, config:)
  @memory_store = memory_store
  @config = config
end

Instance Method Details

#add(session_id:, subject:, predicate:, object:, source_turn_id: nil, source_memory_item_id: nil, confidence: nil, valid_from: nil, scope_id: nil, scope: nil, source_session_id: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/smart_brain/governance/knowledge_graph.rb', line 15

def add(session_id:, subject:, predicate:, object:, source_turn_id: nil,
        source_memory_item_id: nil, confidence: nil, valid_from: nil,
        scope_id: nil, scope: nil, source_session_id: nil)
  memory_store.add_edge(
    session_id: session_id,
    scope_id: scope_id,
    scope: scope,
    source_session_id: source_session_id,
    edge: {
      subject: subject, predicate: predicate, object: object,
      source_turn_id: source_turn_id, source_memory_item_id: source_memory_item_id,
      confidence: confidence || default_confidence, valid_from: valid_from
    }
  )
end

#invalidate(edge_id:, reason: nil) ⇒ Object



41
42
43
# File 'lib/smart_brain/governance/knowledge_graph.rb', line 41

def invalidate(edge_id:, reason: nil)
  memory_store.invalidate_edge(id: edge_id, reason: reason)
end

#query(session_id: nil, scope_ids: nil, subject: nil, predicate: nil, object: nil, include_invalid: false) ⇒ Object



31
32
33
34
35
# File 'lib/smart_brain/governance/knowledge_graph.rb', line 31

def query(session_id: nil, scope_ids: nil, subject: nil, predicate: nil, object: nil, include_invalid: false)
  memory_store.query_edges(session_id: session_id, scope_ids: scope_ids, subject: subject,
                           predicate: predicate, object: object,
                           include_invalid: include_invalid)
end

#stats(session_id: nil, scope_ids: nil) ⇒ Object



45
46
47
# File 'lib/smart_brain/governance/knowledge_graph.rb', line 45

def stats(session_id: nil, scope_ids: nil)
  memory_store.edge_stats(session_id: session_id, scope_ids: scope_ids)
end

#timeline(session_id: nil, scope_ids: nil, subject:) ⇒ Object



37
38
39
# File 'lib/smart_brain/governance/knowledge_graph.rb', line 37

def timeline(session_id: nil, scope_ids: nil, subject:)
  memory_store.edges_for_subject(session_id: session_id, scope_ids: scope_ids, subject: subject)
end