Class: Assistant::TechnicalSupport::ResponseGroundingClaim

Inherits:
Data
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, category: nil, verdict: nil, evidence_ids: [], answer_segment_id: nil) ⇒ ResponseGroundingClaim

Builds an immutable normalized claim.

Parameters:

  • text (String, nil) (defaults to: nil)

    bounded claim text

  • category (String, nil) (defaults to: nil)

    technical claim category

  • verdict (String, nil) (defaults to: nil)

    supported, unsupported, or contradicted

  • evidence_ids (Array<String>) (defaults to: [])

    bounded conversation-evidence identifiers

  • answer_segment_id (String, nil) (defaults to: nil)

    exact answer segment being graded



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_idObject (readonly)

Returns the value of attribute answer_segment_id

Returns:

  • (Object)

    the current value of 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

#categoryObject (readonly)

Returns the value of attribute category

Returns:

  • (Object)

    the current value of category



6
7
8
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6

def category
  @category
end

#evidence_idsObject (readonly)

Returns the value of attribute evidence_ids

Returns:

  • (Object)

    the current value of evidence_ids



6
7
8
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6

def evidence_ids
  @evidence_ids
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



6
7
8
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 6

def text
  @text
end

#verdictObject (readonly)

Returns the value of attribute verdict

Returns:

  • (Object)

    the current value of 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.

Parameters:

  • raw_claim (Hash)

    raw string- or symbol-keyed claim

Returns:



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.

Returns:

  • (Boolean)

    true when canonical tool evidence is mandatory



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.

Parameters:

  • index (Integer)

    zero-based claim position

Returns:

  • (Array<String>)

    validation error keys



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.

Returns:

  • (Boolean)

    true for a supported claim



59
# File 'app/services/assistant/technical_support/response_grounding_claim.rb', line 59

def supported? = verdict == 'supported'

#to_hHash

Serializes the normalized claim for JSONB persistence.

Returns:

  • (Hash)

    string-keyed claim payload



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