java.lang.Object
java.lang.Record
org.elasticsearch.inference.InferenceString
- All Implemented Interfaces:
Writeable,ToXContent,ToXContentObject
public record InferenceString(InferenceString.DataType dataType, InferenceString.DataFormat dataFormat, String value)
extends Record
implements Writeable, ToXContentObject
This class represents a String which may be raw text, or the String representation of some other data such as an image in base64
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDescribes the format of data represented by anInferenceStringstatic enumDescribes the type of data represented by anInferenceStringNested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
Fields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY, EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionInferenceString(InferenceString.DataType dataType, String value) Constructs anInferenceStringwith the given value andInferenceString.DataType, using the defaultInferenceString.DataFormatfor the data typeInferenceString(InferenceString.DataType dataType, InferenceString.DataFormat dataFormat, String value) Constructs anInferenceStringwith the given value,InferenceString.DataTypeandInferenceString.DataFormat -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedataFormatrecord component.dataType()Returns the value of thedataTyperecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisImage()booleanisText()static EnumSet<InferenceString.DataFormat> static StringtextValue(InferenceString inferenceString) Converts a singleInferenceStringto aString.final StringtoString()Returns a string representation of this record class.toStringList(List<InferenceString> inferenceStrings) Converts a list ofInferenceStringto a list ofString.toXContent(XContentBuilder builder, ToXContent.Params params) value()Returns the value of thevaluerecord component.voidwriteTo(StreamOutput out) Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xcontent.ToXContentObject
isFragment
-
Constructor Details
-
InferenceString
Constructs anInferenceStringwith the given value andInferenceString.DataType, using the defaultInferenceString.DataFormatfor the data type- Parameters:
dataType- the type of data that the String representsvalue- the String value
-
InferenceString
public InferenceString(InferenceString.DataType dataType, @Nullable InferenceString.DataFormat dataFormat, String value) Constructs anInferenceStringwith the given value,InferenceString.DataTypeandInferenceString.DataFormat- Parameters:
dataType- the type of data that the String representsdataFormat- the format of the data. Ifnull, the default data format for the given type is usedvalue- the String value
-
InferenceString
- Throws:
IOException
-
-
Method Details
-
isImage
public boolean isImage() -
isText
public boolean isText() -
supportedFormatsForType
public static EnumSet<InferenceString.DataFormat> supportedFormatsForType(InferenceString.DataType type) -
toStringList
Converts a list ofInferenceStringto a list ofString.This method should only be called in code paths that do not deal with multimodal inputs, i.e. code paths where all inputs are guaranteed to be raw text, since it discards the
InferenceString.DataTypeassociated with each input.- Parameters:
inferenceStrings- The list ofInferenceStringto convert to a list ofString- Returns:
- a list of String inference inputs that do not contain any non-text inputs
-
textValue
Converts a singleInferenceStringto aString.This method should only be called in code paths that do not deal with multimodal inputs, i.e. code paths where all inputs are guaranteed to be raw text, since it discards the
InferenceString.DataTypeassociated with each input.- Parameters:
inferenceString- TheInferenceStringto convert to aString- Returns:
- a String inference input
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Specified by:
toXContentin interfaceToXContent- Throws:
IOException
-
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. -
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. -
equals
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. All components in this record class are compared withObjects::equals(Object,Object). -
dataType
Returns the value of thedataTyperecord component.- Returns:
- the value of the
dataTyperecord component
-
dataFormat
Returns the value of thedataFormatrecord component.- Returns:
- the value of the
dataFormatrecord component
-
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-