{"record":{"id":"9b369a4e335acb9b","repo":"apache/beam","slug":"min-batch-size-not-reached-nbatch-size-needs-to-be-larger-or","errorCode":null,"errorMessage":"Min batch size not reached.%nBatch size needs to be larger or equal than %d","messagePattern":"Min batch size not reached\\.%nBatch size needs to be larger or equal than (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateImages.java","lineNumber":109,"sourceCode":"   * @param desiredRequestParallelism desiredRequestParallelism desired number of concurrent batched\n   *     requests.\n   */\n  public AnnotateImages(List<Feature> featureList, long batchSize, int desiredRequestParallelism) {\n    this.desiredRequestParallelism = desiredRequestParallelism;\n    contextSideInput = null;\n    this.featureList = featureList;\n    checkBatchSizeCorrectness(batchSize);\n    this.batchSize = batchSize;\n  }\n\n  private void checkBatchSizeCorrectness(long batchSize) {\n    if (batchSize > MAX_BATCH_SIZE) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Max batch size exceeded.%n\" + \"Batch size needs to be equal or smaller than %d\",\n              MAX_BATCH_SIZE));\n    } else if (batchSize < MIN_BATCH_SIZE) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Min batch size not reached.%n\" + \"Batch size needs to be larger or equal than %d\",\n              MIN_BATCH_SIZE));\n    }\n  }\n\n  /**\n   * Applies all necessary transforms to call the Vision API. In order to group requests into\n   * batches, we assign keys to the requests, as {@link GroupIntoBatches} works only on {@link KV}s.\n   */\n  @Override\n  public PCollection<List<AnnotateImageResponse>> expand(PCollection<T> input) {\n    ParDo.SingleOutput<T, AnnotateImageRequest> inputToRequestMapper;\n    if (contextSideInput != null) {\n      inputToRequestMapper =\n          ParDo.of(new MapInputToRequest(contextSideInput)).withSideInputs(contextSideInput);\n    } else {\n      inputToRequestMapper = ParDo.of(new MapInputToRequest(null));","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateImages.java#L91-L127","documentation":"AnnotateImages enforces a minimum batch size (MIN_BATCH_SIZE = 1). checkBatchSizeCorrectness throws IllegalArgumentException if batchSize is below MIN_BATCH_SIZE, because a non-positive batch would never send any image to the Vision API.","triggerScenarios":"Building AnnotateImages with .withBatchSize(n) where n < 1 (zero or negative batch size).","commonSituations":"Computing the batch size dynamically and accidentally producing 0 or a negative value; misconfigured pipeline options yielding an unset/zero value.","solutions":["Set batchSize to at least 1: .withBatchSize(1).","Clamp the computed value: Math.max(1, Math.min(batchSize, 16)).","Validate upstream pipeline options before constructing the transform."],"exampleFix":"// before\nAnnotateImages.newBuilder().setBatchSize(options.getBatchSize()).build(); // batchSize = 0\n// after\nAnnotateImages.newBuilder().setBatchSize(Math.max(1, options.getBatchSize())).build();","handlingStrategy":"validation","validationCode":"if (batchSize < 1) throw new IllegalArgumentException(\"Batch size must be >= 1\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp computed batch sizes: Math.max(1, n)","Never default numeric options to 0","Validate options before constructing transforms"],"tags":["java","google-cloud-vision","batch-size","apache-beam"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}