Class: ClaudeMemory::Core::FactCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_memory/core/fact_collector.rb

Overview

Pure logic for collecting and ordering fact IDs from provenance records Follows Functional Core pattern - no I/O, just transformations

Class Method Summary collapse

Class Method Details

.collect_ordered_fact_ids(provenance_by_content, content_ids, limit) ⇒ Array<Integer>

Collect fact IDs from provenance records, maintaining content order and deduplicating

Parameters:

  • provenance_by_content (Hash)

    Map of content_id => array of provenance records with :fact_id

  • content_ids (Array<Integer>)

    Ordered content IDs

  • limit (Integer)

    Maximum fact IDs to collect

Returns:

  • (Array<Integer>)

    Ordered, deduplicated fact IDs



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/claude_memory/core/fact_collector.rb', line 13

def self.collect_ordered_fact_ids(provenance_by_content, content_ids, limit)
  return [] if limit <= 0

  seen_fact_ids = Set.new
  ordered_fact_ids = []

  content_ids.each do |content_id|
    provenance_records = provenance_by_content[content_id] || []

    provenance_records.each do |prov|
      fact_id = prov[:fact_id]
      next if seen_fact_ids.include?(fact_id)

      seen_fact_ids.add(fact_id)
      ordered_fact_ids << fact_id
      break if ordered_fact_ids.size >= limit
    end
    break if ordered_fact_ids.size >= limit
  end

  ordered_fact_ids
end

.extract_content_ids(provenance_records) ⇒ Array<Integer>

Extract unique content IDs from array of provenance records

Parameters:

  • provenance_records (Array<Hash>)

    Records with :content_item_id

Returns:

  • (Array<Integer>)

    Unique content IDs



46
47
48
# File 'lib/claude_memory/core/fact_collector.rb', line 46

def self.extract_content_ids(provenance_records)
  provenance_records.map { |p| p[:content_item_id] }.uniq
end

.extract_fact_ids(provenance_records) ⇒ Array<Integer>

Extract unique fact IDs from array of provenance records

Parameters:

  • provenance_records (Array<Hash>)

    Records with :fact_id

Returns:

  • (Array<Integer>)

    Unique fact IDs



39
40
41
# File 'lib/claude_memory/core/fact_collector.rb', line 39

def self.extract_fact_ids(provenance_records)
  provenance_records.map { |p| p[:fact_id] }.uniq
end