Class Document

java.lang.Object
org.springframework.ai.document.Document
All Implemented Interfaces:
Content, MediaContent

public class Document extends Object implements MediaContent
A document is a container for the content and metadata of a document. It also contains the document's unique ID and an optional embedding.
  • Field Details

  • Constructor Details

  • Method Details

    • builder

      public static Document.Builder builder()
    • getId

      public String getId()
    • getContent

      public String getContent()
      Description copied from interface: Content
      Get the content of the message.
      Specified by:
      getContent in interface Content
      Returns:
      the content of the message
    • getMedia

      public Collection<Media> getMedia()
      Description copied from interface: MediaContent
      Get the media associated with the content.
      Specified by:
      getMedia in interface MediaContent
    • getFormattedContent

      public String getFormattedContent()
    • getFormattedContent

      public String getFormattedContent(MetadataMode metadataMode)
    • getFormattedContent

      public String getFormattedContent(ContentFormatter formatter, MetadataMode metadataMode)
      Helper content extractor that uses and external ContentFormatter.
    • getMetadata

      public Map<String,Object> getMetadata()
      Description copied from interface: Content
      Get the metadata associated with the content.
      Specified by:
      getMetadata in interface Content
      Returns:
      the metadata associated with the content
    • getEmbedding

      @Deprecated(since="1.0.0-M4") public float[] getEmbedding()
      Deprecated.
      We are considering getting rid of this, please comment on https://github.com/spring-projects/spring-ai/issues/1781
      Return the embedding that were calculated.
      Returns:
      the embeddings
    • setEmbedding

      public void setEmbedding(float[] embedding)
    • getContentFormatter

      public ContentFormatter getContentFormatter()
      Deprecated.
      We are considering getting rid of this, please comment on https://github.com/spring-projects/spring-ai/issues/1782
      Returns the content formatter associated with this document.
      Returns:
      the current ContentFormatter instance used for formatting the document content.
    • setContentFormatter

      public void setContentFormatter(ContentFormatter contentFormatter)
      Replace the document's ContentFormatter.
      Parameters:
      contentFormatter - new formatter to use.
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object