Class DoclingDocumentParser.Builder
- Enclosing class:
DoclingDocumentParser
-
Method Summary
Modifier and TypeMethodDescriptionbuild()chunkExtractor(Function<ai.docling.serve.api.chunk.response.ChunkDocumentResponse, Document> chunkExtractor) Sets a custom function to build aDocumentfrom a DoclingChunkDocumentResponse(produced by aHierarchicalChunkDocumentRequestorHybridChunkDocumentRequest).chunkTextExtractor(Function<ai.docling.serve.api.chunk.response.ChunkDocumentResponse, String> chunkTextExtractor) Sets a custom function to extract text content from a DoclingChunkDocumentResponse(produced by aHierarchicalChunkDocumentRequestorHybridChunkDocumentRequest).doclingClient(ai.docling.serve.api.DoclingServeApi doclingClient) Sets the Docling client that will be used to perform operations.documentExtractor(Function<ai.docling.serve.api.convert.response.InBodyConvertDocumentResponse, Document> documentExtractor) Sets a custom function to build aDocumentfrom a DoclingInBodyConvertDocumentResponse(produced by aConvertDocumentRequest).documentRequest(ai.docling.serve.api.request.DocumentRequest documentRequest) Sets theDocumentRequesttemplate describing the Docling operation to perform (for exampleConvertDocumentRequest,HierarchicalChunkDocumentRequest, orHybridChunkDocumentRequest) along with its options.documentTextExtractor(Function<ai.docling.serve.api.convert.response.InBodyConvertDocumentResponse, String> documentTextExtractor) Sets a custom function to extract text content from a DoclingInBodyConvertDocumentResponse(produced by aConvertDocumentRequest).options(ai.docling.serve.api.convert.request.options.ConvertDocumentOptions options) Deprecated.requestExecutor(DoclingRequestExecutor requestExecutor) Sets the strategy used to invoke Docling for a prepared request.
-
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- theDoclingServeApiinstance to communicate with Docling backend services- Returns:
- this builder instance
-
documentRequest
public DoclingDocumentParser.Builder documentRequest(ai.docling.serve.api.request.DocumentRequest documentRequest) Sets theDocumentRequesttemplate describing the Docling operation to perform (for exampleConvertDocumentRequest,HierarchicalChunkDocumentRequest, orHybridChunkDocumentRequest) 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
BatchConvertDocumentRequestor a request carrying a non-InBodyTargettarget causesbuild()to fail. Supplying a customrequestExecutor(DoclingRequestExecutor)lifts those restrictions.If not set, defaults to a plain
ConvertDocumentRequestwith 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 aDocumentfrom a DoclingInBodyConvertDocumentResponse(produced by aConvertDocumentRequest). UnlikedocumentTextExtractor(Function), this gives full control over the returnedDocument, including itsMetadata— 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 causesbuild()to throw anIllegalArgumentException. If neither is set, the markdown content of the converted document is used.- Parameters:
documentExtractor- the function to build aDocumentfrom 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 DoclingInBodyConvertDocumentResponse(produced by aConvertDocumentRequest). 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 aDocument; for control over theDocumentitself usedocumentExtractor(Function).Mutually exclusive with
documentExtractor(Function): configuring both causesbuild()to throw anIllegalArgumentException. 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 aDocumentfrom a DoclingChunkDocumentResponse(produced by aHierarchicalChunkDocumentRequestorHybridChunkDocumentRequest). UnlikechunkTextExtractor(Function), this gives full control over the returnedDocument, including itsMetadata. The parser adds the "document_size_bytes" metadata entry on top of whatever the function returns.Mutually exclusive with
chunkTextExtractor(Function): configuring both causesbuild()to throw anIllegalArgumentException. If neither is set, the text of all chunks joined by newlines is used.- Parameters:
chunkExtractor- the function to build aDocumentfrom 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 DoclingChunkDocumentResponse(produced by aHierarchicalChunkDocumentRequestorHybridChunkDocumentRequest). The function receives the full response, giving access to the chunks and their metadata. The returned text is wrapped in aDocument; for control over theDocumentitself usechunkExtractor(Function).Mutually exclusive with
chunkExtractor(Function): configuring both causesbuild()to throw anIllegalArgumentException. 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
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 commonForkJoinPool). 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 commonForkJoinPool) 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.usedocumentRequest(DocumentRequest)with aConvertDocumentRequestcarrying the desired options insteadSets the conversion options.- Parameters:
options- theConvertDocumentOptionsto use- Returns:
- this builder
-
build
-
documentRequest(DocumentRequest)with aConvertDocumentRequestcarrying the desired options instead