Module: ClaudeMemory::Index::IndexQueryLogic

Defined in:
lib/claude_memory/index/index_query_logic.rb

Class Method Summary collapse

Class Method Details

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

Pure function: collects fact IDs from provenance records No I/O, no side effects - fully testable

Parameters:

  • provenance_by_content (Hash)

    Map of content_item_id => array of provenance records

  • content_ids (Array<Integer>)

    Content IDs in FTS relevance order

  • limit (Integer)

    Maximum number of 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
35
36
37
38
# File 'lib/claude_memory/index/index_query_logic.rb', line 13

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

  seen_fact_ids = Set.new
  ordered_fact_ids = []

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

    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