Class: Legion::LLM::Quality::Confidence::Score
- Inherits:
-
Data
- Object
- Data
- Legion::LLM::Quality::Confidence::Score
- Defined in:
- lib/legion/llm/quality/confidence/score.rb
Overview
Immutable value object representing a scored confidence level for an LLM response.
score - Float in [0.0, 1.0] band - Symbol: :very_low, :low, :medium, :high, :very_high source - Symbol: :heuristic, :logprobs, :caller_provided signals - Hash of contributing signals and their raw values (informational)
Constant Summary collapse
- BAND_ORDER =
Band ordering from lowest to highest — defined outside the ::Data.define block so it is accessible as Legion::LLM::Quality::Confidence::Score::BAND_ORDER.
%i[very_low low medium high very_high].freeze
Instance Attribute Summary collapse
-
#band ⇒ Object
readonly
Returns the value of attribute band.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#signals ⇒ Object
readonly
Returns the value of attribute signals.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
-
#at_least?(band_name) ⇒ Boolean
Returns true when the band is at or above the given band name.
- #to_h ⇒ Object
Instance Attribute Details
#band ⇒ Object (readonly)
Returns the value of attribute band
13 14 15 |
# File 'lib/legion/llm/quality/confidence/score.rb', line 13 def band @band end |
#score ⇒ Object (readonly)
Returns the value of attribute score
13 14 15 |
# File 'lib/legion/llm/quality/confidence/score.rb', line 13 def score @score end |
#signals ⇒ Object (readonly)
Returns the value of attribute signals
13 14 15 |
# File 'lib/legion/llm/quality/confidence/score.rb', line 13 def signals @signals end |
#source ⇒ Object (readonly)
Returns the value of attribute source
13 14 15 |
# File 'lib/legion/llm/quality/confidence/score.rb', line 13 def source @source end |
Class Method Details
.build(score:, bands:, source: :heuristic, signals: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/llm/quality/confidence/score.rb', line 14 def self.build(score:, bands:, source: :heuristic, signals: {}) clamped = score.to_f.clamp(0.0, 1.0) new( score: clamped, band: classify(clamped, bands), source: source, signals: signals ) end |
Instance Method Details
#at_least?(band_name) ⇒ Boolean
Returns true when the band is at or above the given band name.
25 26 27 |
# File 'lib/legion/llm/quality/confidence/score.rb', line 25 def at_least?(band_name) Legion::LLM::Quality::Confidence::Score::BAND_ORDER.index(band) >= Legion::LLM::Quality::Confidence::Score::BAND_ORDER.index(band_name.to_sym) end |
#to_h ⇒ Object
29 30 31 |
# File 'lib/legion/llm/quality/confidence/score.rb', line 29 def to_h { score: score, band: band, source: source, signals: signals } end |