Class: RubricLLM::RSpecMatchers::RelevanceMatcher

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(question) ⇒ RelevanceMatcher

Returns a new instance of RelevanceMatcher.



99
100
101
102
# File 'lib/rubric_llm/rspec.rb', line 99

def initialize(question)
  super()
  @question = question
end

Instance Method Details

#failure_messageObject



109
110
111
# File 'lib/rubric_llm/rspec.rb', line 109

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

#failure_message_when_negatedObject



113
114
115
# File 'lib/rubric_llm/rspec.rb', line 113

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

#matches?(answer) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
107
# File 'lib/rubric_llm/rspec.rb', line 104

def matches?(answer)
  score = evaluate(Metrics::Relevance, question: @question, answer:)
  score && score >= threshold
end