Record Class EmbeddedDocument

java.lang.Object
java.lang.Record
org.springframework.ai.vectorstore.EmbeddedDocument
Record Components:
document - the document to store; must not be null
embedding - the pre-computed embedding vector; must not be null, must be non-empty, and must contain only finite values (no NaN or Infinity). Caller-supplied vectors are validated here because, unlike VectorStore.add(java.util.List<org.springframework.ai.document.Document>), upsert never re-embeds through a trusted model.

public record EmbeddedDocument(Document document, float[] embedding) extends Record
A Document paired with a pre-computed embedding vector, written to a VectorStore via VectorStore.upsert(java.util.List) without invoking the store's embedding model.

This is the "bring your own vector" entry point: the caller supplies the embedding — computed by a batch API, an external embedding pipeline, or exported from another system — and the store persists it as-is.

The embedding array is defensively copied on construction and on access, so the vector held by an instance cannot be mutated after handoff. Equality compares the document and the element-by-element contents of the embedding array; a record's generated equals would compare the array by reference instead.

Since:
2.1.0
Author:
Soby Chacko
  • Constructor Summary

    Constructors
    Constructor
    Description
    EmbeddedDocument(Document document, float[] embedding)
    Creates an instance of a EmbeddedDocument record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the document record component.
    float[]
    Returns a copy of the embedding vector.
    boolean
    equals(@Nullable Object o)
    Indicates whether some other object is "equal to" this one.
    int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • EmbeddedDocument

      public EmbeddedDocument(Document document, float[] embedding)
      Creates an instance of a EmbeddedDocument record class.
      Parameters:
      document - the value for the document record component
      embedding - the value for the embedding record component
  • Method Details

    • embedding

      public float[] embedding()
      Returns a copy of the embedding vector. Mutating the returned array does not affect this instance.
      Returns:
      a defensive copy of the embedding vector
    • equals

      public boolean equals(@Nullable 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • 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
    • document

      public Document document()
      Returns the value of the document record component.
      Returns:
      the value of the document record component