Class BatchResponse<T>

java.lang.Object
dev.langchain4j.model.batch.BatchResponse<T>
Type Parameters:
T - the type of the responses payload (e.g., ChatResponse, Embedding)

@Experimental public class BatchResponse<T> extends Object
Represents the responses of a batch operation.

A batch response contains the batch identifier, current state, and the per-request results once the batch has reached a terminal state.

The results() preserve the order of the submitted requests, so the i-th result corresponds to the i-th request, allowing the caller to correlate every outcome (success or failure) with its originating request. The responses() and errors() methods are convenience views over those results.

  • Constructor Details

  • Method Details

    • batchId

      public String batchId()
      Returns the unique identifier for this batch operation.
    • state

      public BatchState state()
      Returns the current state of the batch job.
    • results

      public List<BatchItemResult<T>> results()
      Returns the per-request results in submission order, or an empty list if the batch has not produced any results yet (e.g., it is still in progress).

      The i-th element corresponds to the i-th submitted request. Each result is either a BatchItemResult.Success or a BatchItemResult.Failure. A batch-level failure (the whole operation failing) is represented as a single BatchItemResult.Failure.

    • responses

      public List<T> responses()
      Convenience view returning only the successful responses, in submission order.

      To correlate responses with their originating requests, use results() instead.

    • errors

      public List<BatchError> errors()
      Convenience view returning only the errors, in submission order.

      To correlate errors with their originating requests, use results() instead.

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static <T> BatchResponse.Builder<T> builder()
      Returns a new builder for constructing BatchResponse instances.
      Type Parameters:
      T - the type of the responses payload
      Returns:
      a new builder instance