Class DoclingDocumentParser.Builder

java.lang.Object
dev.langchain4j.data.document.parser.docling.DoclingDocumentParser.Builder
Enclosing class:
DoclingDocumentParser

public static final class DoclingDocumentParser.Builder extends Object
  • Method Details

    • doclingClient

      public DoclingDocumentParser.Builder doclingClient(ai.docling.serve.api.DoclingServeApi doclingClient)
      Sets the Docling client that will be used to perform operations.
      Parameters:
      doclingClient - the DoclingServeApi instance to communicate with Docling backend services
      Returns:
      this builder instance
    • documentRequest

      public DoclingDocumentParser.Builder documentRequest(ai.docling.serve.api.request.DocumentRequest documentRequest)
      Sets the DocumentRequest template describing the Docling operation to perform (for example ConvertDocumentRequest, HierarchicalChunkDocumentRequest, or HybridChunkDocumentRequest) along with its options.

      Any document source carried by the template is ignored — the parser injects the source of the document being parsed into a fresh copy of the template for each call. With the default request executor the template must describe an in-body operation: a BatchConvertDocumentRequest or a request carrying a non-InBodyTarget target causes build() to fail. Supplying a custom requestExecutor(DoclingRequestExecutor) lifts those restrictions.

      If not set, defaults to a plain ConvertDocumentRequest with default options.

      Parameters:
      documentRequest - the request template
      Returns:
      this builder
    • documentExtractor

      public DoclingDocumentParser.Builder documentExtractor(Function<ai.docling.serve.api.convert.response.InBodyConvertDocumentResponse, Document> documentExtractor)
      Sets a custom function to build a Document from a Docling InBodyConvertDocumentResponse (produced by a ConvertDocumentRequest). Unlike documentTextExtractor(Function), this gives full control over the returned Document, including its Metadata — useful for carrying, for example, provenance information derived from the structured response. The parser adds the "document_size_bytes" metadata entry on top of whatever the function returns.

      Mutually exclusive with documentTextExtractor(Function): configuring both causes build() to throw an IllegalArgumentException. If neither is set, the markdown content of the converted document is used.

      Parameters:
      documentExtractor - the function to build a Document from a conversion response
      Returns:
      this builder
    • documentTextExtractor

      public DoclingDocumentParser.Builder documentTextExtractor(Function<ai.docling.serve.api.convert.response.InBodyConvertDocumentResponse, String> documentTextExtractor)
      Sets a custom function to extract text content from a Docling InBodyConvertDocumentResponse (produced by a ConvertDocumentRequest). The function receives the full response, giving access to the converted document, conversion errors, processing time, and status information. The returned text is wrapped in a Document; for control over the Document itself use documentExtractor(Function).

      Mutually exclusive with documentExtractor(Function): configuring both causes build() to throw an IllegalArgumentException. If not set, defaults to extracting the markdown content of the converted document.

      Parameters:
      documentTextExtractor - the function to extract document text from a conversion response
      Returns:
      this builder
    • chunkExtractor

      public DoclingDocumentParser.Builder chunkExtractor(Function<ai.docling.serve.api.chunk.response.ChunkDocumentResponse, Document> chunkExtractor)
      Sets a custom function to build a Document from a Docling ChunkDocumentResponse (produced by a HierarchicalChunkDocumentRequest or HybridChunkDocumentRequest). Unlike chunkTextExtractor(Function), this gives full control over the returned Document, including its Metadata. The parser adds the "document_size_bytes" metadata entry on top of whatever the function returns.

      Mutually exclusive with chunkTextExtractor(Function): configuring both causes build() to throw an IllegalArgumentException. If neither is set, the text of all chunks joined by newlines is used.

      Parameters:
      chunkExtractor - the function to build a Document from a chunk response
      Returns:
      this builder
    • chunkTextExtractor

      public DoclingDocumentParser.Builder chunkTextExtractor(Function<ai.docling.serve.api.chunk.response.ChunkDocumentResponse, String> chunkTextExtractor)
      Sets a custom function to extract text content from a Docling ChunkDocumentResponse (produced by a HierarchicalChunkDocumentRequest or HybridChunkDocumentRequest). The function receives the full response, giving access to the chunks and their metadata. The returned text is wrapped in a Document; for control over the Document itself use chunkExtractor(Function).

      Mutually exclusive with chunkExtractor(Function): configuring both causes build() to throw an IllegalArgumentException. If not set, defaults to joining the text of all chunks separated by newlines.

      Parameters:
      chunkTextExtractor - the function to extract document text from a chunk response
      Returns:
      this builder
    • requestExecutor

      public DoclingDocumentParser.Builder requestExecutor(DoclingRequestExecutor requestExecutor)
      Sets the strategy used to invoke Docling for a prepared request. The default executor calls the asynchronous convert/chunk endpoints matching the request type (which already submit, poll, and fetch the result on the common ForkJoinPool). Supplying a custom executor lets callers control exactly how Docling is called (for example to add retry behaviour, or to run the blocking call on their own executor instead of the common ForkJoinPool) and lifts the request-type and target restrictions enforced for the default executor.
      Parameters:
      requestExecutor - the executor that invokes Docling
      Returns:
      this builder
    • options

      @Deprecated public DoclingDocumentParser.Builder options(ai.docling.serve.api.convert.request.options.ConvertDocumentOptions options)
      Deprecated.
      use documentRequest(DocumentRequest) with a ConvertDocumentRequest carrying the desired options instead
      Sets the conversion options.
      Parameters:
      options - the ConvertDocumentOptions to use
      Returns:
      this builder
    • build

      public DoclingDocumentParser build()