Class: RubricLLM::RSpecMatchers::HallucinationMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RubricLLM::RSpecMatchers::HallucinationMatcher
- Defined in:
- lib/rubric_llm/rspec.rb
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(context, question: nil) ⇒ HallucinationMatcher
constructor
A new instance of HallucinationMatcher.
-
#matches?(answer) ⇒ Boolean
Fail closed: a missing score is not evidence of a hallucination.
Methods inherited from BaseMatcher
Constructor Details
#initialize(context, question: nil) ⇒ HallucinationMatcher
Returns a new instance of HallucinationMatcher.
119 120 121 122 123 124 |
# File 'lib/rubric_llm/rspec.rb', line 119 def initialize(context, question: nil) super() require_context!(context) @context = context @question = question end |
Instance Method Details
#failure_message ⇒ Object
132 133 134 |
# File 'lib/rubric_llm/rspec.rb', line 132 def "expected hallucination (faithfulness < #{threshold}), got #{result[:score] || "nil"}" end |
#failure_message_when_negated ⇒ Object
136 137 138 |
# File 'lib/rubric_llm/rspec.rb', line 136 def "expected no hallucination (faithfulness >= #{threshold}), got #{result[:score] || "nil"}" end |
#matches?(answer) ⇒ Boolean
Fail closed: a missing score is not evidence of a hallucination.
127 128 129 130 |
# File 'lib/rubric_llm/rspec.rb', line 127 def matches?(answer) score = evaluate(Metrics::Faithfulness, question: @question || "", answer:, context: @context) !score.nil? && score < threshold end |