Class Embedding

java.lang.Object
dev.langchain4j.data.embedding.Embedding

public class Embedding extends Object
Represents a dense vector embedding of a text. This class encapsulates a float array that captures the "meaning" or semantic information of the text. Texts with similar meanings will have their vectors located close to each other in the embedding space. The embeddings are typically created by embedding models.
See Also:
  • Constructor Details

    • Embedding

      public Embedding(float[] vector)
      Creates a new Embedding.
      Parameters:
      vector - the vector, takes ownership of the array.
  • Method Details

    • vector

      public float[] vector()
      Returns the vector.
      Returns:
      the vector.
    • vectorAsList

      public List<Float> vectorAsList()
      Returns a copy of the vector as a list.
      Returns:
      the vector as a list.
    • normalize

      public void normalize()
      Normalize vector
    • dimension

      public int dimension()
      Returns the dimension of the vector.
      Returns:
      the dimension of the vector.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • from

      public static Embedding from(float[] vector)
      Creates a new Embedding from the given vector.
      Parameters:
      vector - the vector, takes ownership of the array.
      Returns:
      the new Embedding.
    • from

      public static Embedding from(List<Float> vector)
      Creates a new Embedding from the given vector.
      Parameters:
      vector - the vector.
      Returns:
      the new Embedding.