Class: RubricLLM::RSpecMatchers::FaithfulnessMatcher

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/rubric_llm/rspec.rb

Instance Attribute Summary

Attributes inherited from BaseMatcher

#config, #result, #threshold

Instance Method Summary collapse

Methods inherited from BaseMatcher

#with_config, #with_threshold

Constructor Details

#initialize(context, question: nil) ⇒ FaithfulnessMatcher

Returns a new instance of FaithfulnessMatcher.



56
57
58
59
60
61
# File 'lib/rubric_llm/rspec.rb', line 56

def initialize(context, question: nil)
  super()
  require_context!(context)
  @context = context
  @question = question
end

Instance Method Details

#failure_messageObject



68
69
70
# File 'lib/rubric_llm/rspec.rb', line 68

def failure_message
  "expected faithfulness >= #{threshold}, got #{result[:score] || "nil"}"
end

#failure_message_when_negatedObject



72
73
74
# File 'lib/rubric_llm/rspec.rb', line 72

def failure_message_when_negated
  "expected faithfulness < #{threshold}, got #{result[:score]}"
end

#matches?(answer) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/rubric_llm/rspec.rb', line 63

def matches?(answer)
  score = evaluate(Metrics::Faithfulness, question: @question || "", answer:, context: @context)
  score && score >= threshold
end