Module: HTM::Config::Validator

Included in:
HTM::Config
Defined in:
lib/htm/config/validator.rb

Constant Summary collapse

SUPPORTED_PROVIDERS =
%i[
  openai anthropic gemini azure ollama
  huggingface openrouter bedrock deepseek
].freeze
SUPPORTED_JOB_BACKENDS =
%i[active_job sidekiq inline thread fiber].freeze
SUPPORTED_WEEK_STARTS =
%i[sunday monday].freeze

Instance Method Summary collapse

Instance Method Details

#validate_callablesObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/htm/config/validator.rb', line 54

def validate_callables
  unless @embedding_generator.respond_to?(:call)
    raise HTM::ValidationError, "embedding_generator must be callable"
  end

  unless @tag_extractor.respond_to?(:call)
    raise HTM::ValidationError, "tag_extractor must be callable"
  end

  unless @proposition_extractor.respond_to?(:call)
    raise HTM::ValidationError, "proposition_extractor must be callable"
  end

  return if @token_counter.respond_to?(:call)
  raise HTM::ValidationError, "token_counter must be callable"
end

#validate_configObject



14
15
16
17
18
19
# File 'lib/htm/config/validator.rb', line 14

def validate_config
  validate_providers
  validate_job_backend
  validate_week_start
  validate_relevance_weights
end

#validate_job_backendObject



34
35
36
37
38
39
# File 'lib/htm/config/validator.rb', line 34

def validate_job_backend
  return unless job_backend

  return if SUPPORTED_JOB_BACKENDS.include?(job_backend)
  raise_validation_error("job.backend must be one of: #{SUPPORTED_JOB_BACKENDS.join(', ')} (got #{job_backend.inspect})")
end

#validate_loggerObject



71
72
73
74
# File 'lib/htm/config/validator.rb', line 71

def validate_logger
  return if @logger.respond_to?(:info) && @logger.respond_to?(:warn) && @logger.respond_to?(:error)
  raise HTM::ValidationError, "logger must respond to :info, :warn, and :error"
end

#validate_provider(name, value) ⇒ Object



27
28
29
30
31
32
# File 'lib/htm/config/validator.rb', line 27

def validate_provider(name, value)
  return if value.nil?

  return if SUPPORTED_PROVIDERS.include?(value)
  raise_validation_error("#{name} must be one of: #{SUPPORTED_PROVIDERS.join(', ')} (got #{value.inspect})")
end

#validate_providersObject



21
22
23
24
25
# File 'lib/htm/config/validator.rb', line 21

def validate_providers
  validate_provider(:embedding_provider, embedding_provider)
  validate_provider(:tag_provider, tag_provider)
  validate_provider(:proposition_provider, proposition_provider)
end

#validate_relevance_weightsObject



46
47
48
49
50
51
52
# File 'lib/htm/config/validator.rb', line 46

def validate_relevance_weights
  total = relevance_semantic_weight + relevance_tag_weight +
          relevance_recency_weight + relevance_access_weight

  return if (0.99..1.01).cover?(total)
  raise_validation_error("relevance weights must sum to 1.0 (got #{total})")
end

#validate_week_startObject



41
42
43
44
# File 'lib/htm/config/validator.rb', line 41

def validate_week_start
  return if SUPPORTED_WEEK_STARTS.include?(week_start)
  raise_validation_error("week_start must be one of: #{SUPPORTED_WEEK_STARTS.join(', ')} (got #{week_start.inspect})")
end