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.



94
95
96
97
# File 'lib/rubric_llm/rspec.rb', line 94

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

Instance Method Details

#failure_messageObject



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

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

#failure_message_when_negatedObject



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

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

#matches?(answer) ⇒ Boolean

Returns:

  • (Boolean)


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

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