Class BedrockBatchChatModel
- All Implemented Interfaces:
BatchChatModel, Closeable, AutoCloseable
BatchChatModel for the Amazon Bedrock
batch inference API,
which processes multiple chat requests asynchronously at a lower price than on-demand inference for supported
models.
Jobs are created with the Converse invocation type. Each ChatRequest is written as a JSONL
record to Amazon S3, a model invocation job is submitted, and the results are read back from the S3 output
location. All requests in a batch run against the single model configured on this batch model, because Bedrock
runs one model per job.
Bedrock batch inference does not support tool calling, structured output or prompt caching, so a
ChatRequest that specifies tools, a JSON response format or cache points is rejected with an
UnsupportedFeatureException. So is a request that specifies a service tier or a model other than
BedrockBatchChatModel.Builder.modelId(String).
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidCancels a chat batch operation that is currently pending or running.voidclose()Closes the Bedrock and S3 clients this model created.list(@Nullable BatchPagination pagination) Lists chat batch jobs with optional pagination.Retrieves the job and, once it has ended, its results.submit(BatchRequest<ChatRequest> request) Writes the requests as one JSONL file to Amazon S3 and creates a Bedrock model invocation job for it.
-
Method Details
-
submit
Writes the requests as one JSONL file to Amazon S3 and creates a Bedrock model invocation job for it.The input file is uploaded under
BedrockBatchChatModel.Builder.inputS3Uri(String)and is not deleted afterwards, so it is stored and billed by S3 until you remove it; the same applies to the output Bedrock writes. Bedrock enforces a minimum and a maximum number of records per job as service quotas, and rejects a job that falls outside them.- Specified by:
submitin interfaceBatchChatModel- Parameters:
request- the list of chat requests to process in the batch- Returns:
- a
BatchResponserepresenting the initial state of the batch operation
-
retrieve
Retrieves the job and, once it has ended, its results.Results are read from the output location recorded on the job, for every ended job that produced output. This includes the partial results of a stopped or expired job, since Bedrock charges for the records it processed. Every parsed result is held in memory.
Results are correlated by
recordId, using the identifiers thatsubmit(BatchRequest)generates, and a request that produced no result is represented by a failure. If any identifier is missing, malformed, duplicated or outside the submitted range - which happens for a job that was not submitted through this model - correlation is abandoned for the whole job and the results are returned in the order the output files list them, with a warning logged. Results are never discarded.BatchError.code()holds theerrorCodeBedrock reports for a record that failed, and0for a request that produced no result or for a job-level failure.- Specified by:
retrievein interfaceBatchChatModel- Parameters:
batchId- the batch identifier obtained fromBatchChatModel.submit(BatchRequest)- Returns:
- a
BatchResponserepresenting the current state of the chat batch operation
-
cancel
Description copied from interface:BatchChatModelCancels a chat batch operation that is currently pending or running.- Specified by:
cancelin interfaceBatchChatModel- Parameters:
batchId- the batch identifier to cancel
-
list
Description copied from interface:BatchChatModelLists chat batch jobs with optional pagination.- Specified by:
listin interfaceBatchChatModel- Parameters:
pagination- the maximum number of batch jobs to return and token for retrieving a specific page; if null, uses server default- Returns:
- a
BatchPagecontaining chat batch responses and pagination information
-
close
public void close()Closes the Bedrock and S3 clients this model created. A client or credentials provider passed to theBedrockBatchChatModel.Builderbelongs to the caller and is left open.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
builder
- Returns:
- a new
BedrockBatchChatModel.BuilderforBedrockBatchChatModel.
-