Class Embedding


  • public class Embedding
    extends Object
    Represents a strongly typed vector of numeric data.
    • Constructor Detail

      • Embedding

        public Embedding()
        Initializes a new instance of the Embedding class.
      • Embedding

        public Embedding​(@Nonnull
                         List<Float> vector)
        Initializes a new instance of the Embedding class that contains numeric elements copied from the specified collection
        Parameters:
        vector - The collection whose elements are copied to the new Embedding
    • Method Detail

      • getVector

        public List<Float> getVector()
        Return the embedding vector as a read-only list.
        Returns:
        The embedding vector as a read-only list.
      • dot

        public float dot​(@Nonnull
                         Embedding other)
        Calculates the dot product of this Embedding with another.
        Parameters:
        other - The other Embedding to compute the dot product with
        Returns:
        The dot product between the Embedding vectors
      • euclideanLength

        public float euclideanLength()
        Calculates the Euclidean length of this vector.
        Returns:
        Euclidean length
      • cosineSimilarity

        public float cosineSimilarity​(@Nonnull
                                      Embedding other)
        Calculates the cosine similarity of this vector with another.
        Parameters:
        other - The other vector to compute cosine similarity with.
        Returns:
        Cosine similarity between vectors
      • multiply

        public Embedding multiply​(float multiplier)
        Multiply the Embedding vector by a multiplier.
        Parameters:
        multiplier - The multiplier to multiply the Embedding vector by
        Returns:
        A new Embedding with the vector multiplied by the multiplier
      • divide

        public Embedding divide​(float divisor)
        Divide the Embedding vector by a divisor.
        Parameters:
        divisor - The divisor to divide the Embedding vector by
        Returns:
        A new Embedding with the vector divided by the divisor
      • normalize

        public Embedding normalize()
        Normalizes the underlying vector, such that the Euclidean length is 1.
        Returns:
        A new Embedding with the normalized vector