Class: ClaudeMemory::Core::EmbeddingCandidateBuilder

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

Overview

Pure logic for building embedding candidates from fact data Follows Functional Core pattern - no I/O, just transformations

Class Method Summary collapse

Class Method Details

.build_candidates(facts_data) ⇒ Array<Hash>

Parse embeddings and prepare candidates for similarity calculation

Parameters:

  • facts_data (Array<Hash>)

    Fact rows with :embedding_json, :id, etc.

Returns:

  • (Array<Hash>)

    Candidates with parsed :embedding arrays



13
14
15
16
17
# File 'lib/claude_memory/core/embedding_candidate_builder.rb', line 13

def self.build_candidates(facts_data)
  facts_data.map do |row|
    parse_candidate(row)
  end.compact
end

.parse_candidate(row) ⇒ Hash?

Parse a single fact row into a candidate

Parameters:

  • row (Hash)

    Fact row with :embedding_json, :id, etc.

Returns:

  • (Hash, nil)

    Candidate hash or nil if parse fails



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/claude_memory/core/embedding_candidate_builder.rb', line 22

def self.parse_candidate(row)
  embedding = JSON.parse(row[:embedding_json])
  {
    fact_id: row[:id],
    embedding: embedding,
    subject_entity_id: row[:subject_entity_id],
    predicate: row[:predicate],
    object_literal: row[:object_literal],
    scope: row[:scope]
  }
rescue JSON::ParserError
  nil
end