Class DocumentRequest

java.lang.Object
ai.docling.serve.api.request.DocumentRequest
Direct Known Subclasses:
BatchConvertDocumentRequest, ChunkDocumentRequest, ConvertDocumentRequest

public abstract sealed class DocumentRequest extends Object permits ConvertDocumentRequest, BatchConvertDocumentRequest, ChunkDocumentRequest
Abstract base class for all document processing requests. Provides the common fields shared across conversion, chunking, and batch conversion requests: document sources and an optional output target.

This is a sealed class — the only permitted subtypes are ConvertDocumentRequest, BatchConvertDocumentRequest, and ChunkDocumentRequest — enabling exhaustive pattern matching:


 switch (request) {
   case ConvertDocumentRequest r    -> client.convertSource(r);
   case BatchConvertDocumentRequest r -> client.convertSourceBatch(r);
   case HierarchicalChunkDocumentRequest r -> client.chunkSourceWithHierarchicalChunker(r);
   case HybridChunkDocumentRequest r       -> client.chunkSourceWithHybridChunker(r);
 }
 

Because toBuilder() is available on the base type, a source (or target) can be injected once — polymorphically — before dispatching, without needing to know the concrete type:


 DocumentRequest withSource = request.toBuilder().source(source).build();
 
  • Constructor Details

  • Method Details

    • toBuilder

      public abstract DocumentRequest.Builder<?,?> toBuilder()
      Returns a builder pre-populated with this request's current field values, allowing a modified copy to be created. Each concrete subtype returns its own builder covariantly.
      Returns:
      a builder initialized from this request
    • getSources

      public List<Source> getSources()
      List of document sources to be processed. Each source can be a file (base64-encoded), an HTTP URL, or an S3 reference.
      Returns:
      the list of document sources
    • getTarget

      public @Nullable Target getTarget()
      Specification for the type of output target. If not specified, the result is returned in the response body.
      Returns:
      the output target specification, or null if not specified
    • toString

      public @NonNull String toString()
      Overrides:
      toString in class Object