Class: Assistant::TechnicalSupport::ResponseGroundingClaim
- Inherits:
-
Data
- Object
- Data
- Assistant::TechnicalSupport::ResponseGroundingClaim
- Defined in:
- app/services/assistant/technical_support/response_grounding_claim.rb,
app/services/assistant/technical_support/response_grounding_claim.rb
Overview
Immutable normalized technical claim returned by the structured grader.
Constant Summary collapse
- CATEGORIES =
%w[measurement compatibility diagnosis procedure safety part_number other].freeze
- CANONICAL_EVIDENCE_CATEGORIES =
%w[compatibility diagnosis procedure safety part_number].freeze
- VERDICTS =
%w[supported unsupported contradicted].freeze
- LIMITS =
{ text_chars: 500, evidence_ids: ResponseGroundingEvidence::MAX_EVIDENCE_ENTRIES }.freeze
Instance Attribute Summary collapse
-
#answer_segment_id ⇒ Object
readonly
Returns the value of attribute answer_segment_id.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#evidence_ids ⇒ Object
readonly
Returns the value of attribute evidence_ids.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#verdict ⇒ Object
readonly
Returns the value of attribute verdict.
Class Method Summary collapse
-
.from(raw_claim) ⇒ ResponseGroundingClaim
Normalizes one raw structured-grader claim.
Instance Method Summary collapse
-
#canonical_evidence_required? ⇒ Boolean
Reports whether reported user context can never establish this category.
-
#errors(index:) ⇒ Array<String>
Returns deterministic schema and evidence validation errors.
-
#initialize(text: nil, category: nil, verdict: nil, evidence_ids: [], answer_segment_id: nil) ⇒ ResponseGroundingClaim
constructor
Builds an immutable normalized claim.
-
#supported? ⇒ Boolean
Reports whether the grader marked this claim supported.
-
#to_h ⇒ Hash
Serializes the normalized claim for JSONB persistence.
Constructor Details
#initialize(text: nil, category: nil, verdict: nil, evidence_ids: [], answer_segment_id: nil) ⇒ ResponseGroundingClaim
Builds an immutable normalized claim.
24 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 24 def initialize(text: nil, category: nil, verdict: nil, evidence_ids: [], answer_segment_id: nil) = super |
Instance Attribute Details
#answer_segment_id ⇒ Object (readonly)
Returns the value of attribute answer_segment_id
6 7 8 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6 def answer_segment_id @answer_segment_id end |
#category ⇒ Object (readonly)
Returns the value of attribute category
6 7 8 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6 def category @category end |
#evidence_ids ⇒ Object (readonly)
Returns the value of attribute evidence_ids
6 7 8 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6 def evidence_ids @evidence_ids end |
#text ⇒ Object (readonly)
Returns the value of attribute text
6 7 8 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6 def text @text end |
#verdict ⇒ Object (readonly)
Returns the value of attribute verdict
6 7 8 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6 def verdict @verdict end |
Class Method Details
.from(raw_claim) ⇒ ResponseGroundingClaim
Normalizes one raw structured-grader claim.
30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 30 def self.from(raw_claim) claim = raw_claim.to_h.stringify_keys new( text: claim['text'].to_s.first(LIMITS.fetch(:text_chars)), category: claim['category'].to_s, verdict: claim['verdict'].to_s, evidence_ids: Array(claim['evidence_ids']).map(&:to_s).uniq.first(LIMITS.fetch(:evidence_ids)), answer_segment_id: claim['answer_segment_id'].to_s ) end |
Instance Method Details
#canonical_evidence_required? ⇒ Boolean
Reports whether reported user context can never establish this category.
64 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 64 def canonical_evidence_required? = CANONICAL_EVIDENCE_CATEGORIES.include?(category) |
#errors(index:) ⇒ Array<String>
Returns deterministic schema and evidence validation errors.
45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 45 def errors(index:) number = index + 1 [ ("claim_#{number}_text" if text.blank?), ("claim_#{number}_category" unless CATEGORIES.include?(category)), ("claim_#{number}_verdict" unless VERDICTS.include?(verdict)), ("claim_#{number}_missing_evidence" if supported? && evidence_ids.empty?), ("claim_#{number}_answer_segment" if answer_segment_id.blank?) ].compact end |
#supported? ⇒ Boolean
Reports whether the grader marked this claim supported.
59 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 59 def supported? = verdict == 'supported' |
#to_h ⇒ Hash
Serializes the normalized claim for JSONB persistence.
69 70 71 72 73 74 75 76 77 |
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 69 def to_h { 'text' => text, 'category' => category, 'verdict' => verdict, 'evidence_ids' => evidence_ids, 'answer_segment_id' => answer_segment_id } end |