Record Class ChoiceAnswer

java.lang.Object
java.lang.Record
org.springframework.ai.systemone.api.response.ChoiceAnswer
Record Components:
value - the selected option label
probabilities - the probability of each option, keyed by label
confidence - how concentrated the distribution is, between 0 and 1
All Implemented Interfaces:
Answer

public record ChoiceAnswer(String value, Map<String,Double> probabilities, double confidence) extends Record implements Answer
The answer to a Choice: the selected label, the probability of every option and a confidence statistic computed from how concentrated that distribution is. A flat distribution means the options were not well separated for this state.
Since:
2.1.0
Author:
Christian Tzolov
  • Constructor Details

    • ChoiceAnswer

      public ChoiceAnswer(String value, Map<String,Double> probabilities, double confidence)
      Creates an instance of a ChoiceAnswer record class.
      Parameters:
      value - the value for the value record component
      probabilities - the value for the probabilities record component
      confidence - the value for the confidence record component
  • Method Details

    • type

      public AnswerType type()
      Specified by:
      type in interface Answer
      Returns:
      the kind of this answer
    • probabilityOf

      public double probabilityOf(String option)
      Parameters:
      option - the option label
      Returns:
      the probability assigned to the option, or 0 when it is not present
    • optionsAbove

      public List<String> optionsAbove(double threshold)
      Returns the options whose probability is at least threshold, most likely first. Useful for the fan-out pattern, where a close split is explored along several branches instead of committing to the top option.
      Parameters:
      threshold - the inclusive lower probability bound
      Returns:
      the matching option labels, ordered by descending probability
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • value

      public String value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • probabilities

      public Map<String,Double> probabilities()
      Returns the value of the probabilities record component.
      Returns:
      the value of the probabilities record component
    • confidence

      public double confidence()
      Returns the value of the confidence record component.
      Returns:
      the value of the confidence record component