java.lang.Object
java.lang.Record
org.elasticsearch.search.vectors.VectorData
- All Implemented Interfaces:
Writeable,ToXContent,ToXContentFragment
public record VectorData(float[] floatVector, byte[] byteVector, String stringVector)
extends Record
implements Writeable, ToXContentFragment
-
Nested Class Summary
Nested 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
ConstructorsConstructorDescriptionVectorData(byte[] byteVector) VectorData(float[] floatVector) VectorData(float[] floatVector, byte[] byteVector, String stringVector) Creates an instance of aVectorDatarecord class.VectorData(String stringVector) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToBuffer(DenseVectorFieldMapper.Element element, ByteBuffer byteBuffer) byte[]float[]byte[]Returns the value of thebyteVectorrecord component.static VectorDatadecodeQueryVector(String encoded, DenseVectorFieldMapper.ElementType elementType, int dims) Decodes an encoded string (hex or base64) to VectorData based on the element type and dimensions.booleanIndicates whether some other object is "equal to" this one.float[]Returns the value of thefloatVectorrecord component.static VectorDatafromBytes(byte[] vec) static VectorDatafromFloats(float[] vec) static VectorDatafromStringVector(String encoded) inthashCode()Returns a hash code value for this object.booleanisFloat()booleanstatic VectorDataparseXContent(XContentParser parser) intsize()Returns the value of thestringVectorrecord component.toString()Returns a string representation of this record class.toXContent(XContentBuilder builder, ToXContent.Params params) 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.ToXContentFragment
isFragment
-
Constructor Details
-
VectorData
public VectorData(float[] floatVector) -
VectorData
public VectorData(byte[] byteVector) -
VectorData
-
VectorData
- Throws:
IOException
-
VectorData
Creates an instance of aVectorDatarecord class.- Parameters:
floatVector- the value for thefloatVectorrecord componentbyteVector- the value for thebyteVectorrecord componentstringVector- the value for thestringVectorrecord component
-
-
Method Details
-
isFloat
public boolean isFloat() -
isStringVector
public boolean isStringVector() -
stringVector
Returns the value of thestringVectorrecord component.- Returns:
- the value of the
stringVectorrecord component
-
size
public int size() -
asByteVector
public byte[] asByteVector() -
asFloatVector
public float[] asFloatVector() -
addToBuffer
-
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. -
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). -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
parseXContent
- Throws:
IOException
-
fromFloats
-
fromBytes
-
fromStringVector
-
decodeQueryVector
public static VectorData decodeQueryVector(String encoded, DenseVectorFieldMapper.ElementType elementType, int dims) Decodes an encoded string (hex or base64) to VectorData based on the element type and dimensions. Base64 encoding is supported for all element types with proper byte interpretation. Hex encoding produces byte vectors and is supported for BYTE and BIT element types, and for FLOAT/BFLOAT16 when the decoded byte length matches the expected dimensions.- Parameters:
encoded- the encoded vector stringelementType- the element type (BYTE, FLOAT, BFLOAT16, BIT)dims- the expected dimensions- Returns:
- the decoded VectorData
- Throws:
IllegalArgumentException- if the string cannot be decoded or doesn't match expected dimensions
-
floatVector
public float[] floatVector()Returns the value of thefloatVectorrecord component.- Returns:
- the value of the
floatVectorrecord component
-
byteVector
public byte[] byteVector()Returns the value of thebyteVectorrecord component.- Returns:
- the value of the
byteVectorrecord component
-