Class Document.Builder

java.lang.Object
org.springframework.ai.document.Document.Builder
Enclosing class:
Document

public static class Document.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • idGenerator

      public Document.Builder idGenerator(IdGenerator idGenerator)
    • id

      public Document.Builder id(String id)
    • text

      public Document.Builder text(@Nullable String text)
      Sets the text content of the document.

      Either text or media content must be set before building the document, but not both.

      Parameters:
      text - the text content
      Returns:
      the builder instance
      See Also:
    • content

      @Deprecated(since="1.0.0-M5", forRemoval=true) public Document.Builder content(@Nullable String text)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1.0.0-M5, use text(String) instead as it more accurately reflects that this Document instance will contain text rather than generic content. This method will be removed in a future release.
      Sets the text content of the document.
      Parameters:
      text - the text content to set
      Returns:
      the builder instance
    • media

      public Document.Builder media(@Nullable Media media)
      Sets the media content of the document.

      Either text or media content must be set before building the document, but not both.

      Parameters:
      media - the media content
      Returns:
      the builder instance
      See Also:
    • metadata

      public Document.Builder metadata(Map<String,Object> metadata)
    • metadata

      public Document.Builder metadata(String key, Object value)
    • score

      public Document.Builder score(@Nullable Double score)
      Sets a score value for this document.

      Common uses include:

      • Measure of similarity between the embedding value of the document's text/media and a query vector, where higher scores indicate greater similarity (opposite of distance measure)
      • Text relevancy rankings from retrieval systems
      • Custom relevancy metrics from RAG patterns

      Higher values typically indicate greater relevance or similarity.

      Parameters:
      score - the document score, may be null
      Returns:
      the builder instance
    • build

      public Document build()