Class: SmartBrain::Governance::FactCheck
- Inherits:
-
Object
- Object
- SmartBrain::Governance::FactCheck
- Defined in:
- lib/smart_brain/governance/fact_check.rb
Overview
Offline, zero-LLM, zero-network contradiction detector (mempal parity). Scans a piece of text against a session's entities + KG edges and reports three finding types:
- SimilarNameConflict: a token within Levenshtein <= N of a known entity
- RelationContradiction: text mentions both endpoints of an active edge
alongside a negation/contrary cue (may contradict the relation)
- StaleFact: text references an edge whose valid_to < now (invalidated)
Heuristic by design — surfaces candidates for human/agent review.
Constant Summary collapse
- TOKEN_RE =
/[[:alnum:]_\-\p{Han}]+/.freeze
Instance Method Summary collapse
- #check(session_id:, text:, now: Time.now.utc, scope_ids: nil) ⇒ Object
-
#initialize(memory_store:, config:) ⇒ FactCheck
constructor
A new instance of FactCheck.
Constructor Details
#initialize(memory_store:, config:) ⇒ FactCheck
Returns a new instance of FactCheck.
20 21 22 23 |
# File 'lib/smart_brain/governance/fact_check.rb', line 20 def initialize(memory_store:, config:) @memory_store = memory_store @config = config end |
Instance Method Details
#check(session_id:, text:, now: Time.now.utc, scope_ids: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/smart_brain/governance/fact_check.rb', line 25 def check(session_id:, text:, now: Time.now.utc, scope_ids: nil) now = Time.parse(now).utc if now.is_a?(String) text_l = text.to_s.downcase tokens = text.to_s.downcase.scan(TOKEN_RE) findings = [] findings.concat(similar_name_conflicts(session_id:, scope_ids:, tokens: tokens)) findings.concat(relation_contradictions(session_id:, scope_ids:, text_l: text_l)) findings.concat(stale_facts(session_id:, scope_ids:, text_l: text_l, now: now)) { findings: findings, checked_at: Time.now.utc.iso8601, counts: { total: findings.size, similar_name: findings.count { |f| f[:type] == 'SimilarNameConflict' }, relation_contradiction: findings.count { |f| f[:type] == 'RelationContradiction' }, stale_fact: findings.count { |f| f[:type] == 'StaleFact' } } } end |