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:
    • 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()