Class: Legion::LLM::ConfidenceScore
- Inherits:
-
Data
- Object
- Data
- Legion::LLM::ConfidenceScore
- Defined in:
- lib/legion/llm/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::ConfidenceScore::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
11 12 13 |
# File 'lib/legion/llm/confidence_score.rb', line 11 def band @band end |
#score ⇒ Object (readonly)
Returns the value of attribute score
11 12 13 |
# File 'lib/legion/llm/confidence_score.rb', line 11 def score @score end |
#signals ⇒ Object (readonly)
Returns the value of attribute signals
11 12 13 |
# File 'lib/legion/llm/confidence_score.rb', line 11 def signals @signals end |
#source ⇒ Object (readonly)
Returns the value of attribute source
11 12 13 |
# File 'lib/legion/llm/confidence_score.rb', line 11 def source @source end |
Class Method Details
.build(score:, bands:, source: :heuristic, signals: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/legion/llm/confidence_score.rb', line 12 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.
23 24 25 |
# File 'lib/legion/llm/confidence_score.rb', line 23 def at_least?(band_name) Legion::LLM::ConfidenceScore::BAND_ORDER.index(band) >= Legion::LLM::ConfidenceScore::BAND_ORDER.index(band_name.to_sym) end |
#to_h ⇒ Object
27 28 29 |
# File 'lib/legion/llm/confidence_score.rb', line 27 def to_h { score: score, band: band, source: source, signals: signals } end |