{"record":{"id":"a64ba7ab1bee4ec7","repo":"spring-projects/spring-ai","slug":"model-cannot-be-null-or-empty-a64ba7","errorCode":null,"errorMessage":"model cannot be null or empty","messagePattern":"model cannot be null or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/text/VertexAiTextEmbeddingModel.java","lineNumber":200,"sourceCode":"\t\t\t\t\t\tModelOptionsUtils.mergeOption(requestOptions.getDimensions(), this.options.getDimensions()));\n\n\t\t\tif (requestOptions instanceof VertexAiTextEmbeddingOptions vertexOptions) {\n\t\t\t\tbuilder.taskType(ModelOptionsUtils.mergeOption(vertexOptions.getTaskType(), this.options.getTaskType()))\n\t\t\t\t\t.title(ModelOptionsUtils.mergeOption(vertexOptions.getTitle(), this.options.getTitle()))\n\t\t\t\t\t.autoTruncate(ModelOptionsUtils.mergeOption(vertexOptions.getAutoTruncate(),\n\t\t\t\t\t\t\tthis.options.getAutoTruncate()));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbuilder.taskType(this.options.getTaskType())\n\t\t\t\t\t.title(this.options.getTitle())\n\t\t\t\t\t.autoTruncate(this.options.getAutoTruncate());\n\t\t\t}\n\t\t\toptions = builder.build();\n\t\t}\n\n\t\t// Validate request options\n\t\tif (!StringUtils.hasText(options.getModel())) {\n\t\t\tthrow new IllegalArgumentException(\"model cannot be null or empty\");\n\t\t}\n\n\t\treturn new EmbeddingRequest(embeddingRequest.getInstructions(), options);\n\t}\n\n\tprotected PredictRequest.Builder getPredictRequestBuilder(EmbeddingRequest request, EndpointName endpointName,\n\t\t\tVertexAiTextEmbeddingOptions finalOptions) {\n\t\tPredictRequest.Builder predictRequestBuilder = PredictRequest.newBuilder().setEndpoint(endpointName.toString());\n\n\t\tTextParametersBuilder parametersBuilder = TextParametersBuilder.of();\n\n\t\tif (finalOptions.getAutoTruncate() != null) {\n\t\t\tparametersBuilder.autoTruncate(finalOptions.getAutoTruncate());\n\t\t}\n\n\t\tif (finalOptions.getDimensions() != null) {\n\t\t\tparametersBuilder.outputDimensionality(finalOptions.getDimensions());\n\t\t}","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/text/VertexAiTextEmbeddingModel.java#L182-L218","documentation":"The text embedding model validates that resolved options carry a non-empty model name before sending the request. Vertex AI requires an endpoint/model identifier; if options.getModel() is null or blank after merging request options with defaults, the request cannot be built and an IllegalArgumentException is thrown from buildEmbeddingRequest.","triggerScenarios":"Calling VertexAiTextEmbeddingModel.call()/embed() with EmbeddingRequest options (or a defaultOptions instance) where the 'model' field is set to null or \"\" in a way that overrides the default model name; constructing options programmatically with new VertexAiTextEmbeddingOptions.builder().model(null)...","commonSituations":"Upgrading Spring AI versions where default options changed; copying builder code and omitting .model(); building options dynamically from config where the model property is an empty string.","solutions":["Set the model explicitly: .model(\"textembedding-gecko@003\") or the desired version","Ensure your config property (spring.ai.vertex.ai.embedding.text.options.model) is not blank","Use VertexAiTextEmbeddingOptions.builder() defaults and only override fields you need","Validate the model string before constructing the EmbeddingRequest"],"exampleFix":"// before\nvar options = VertexAiTextEmbeddingOptions.builder().build();\noptions.setModel(\"\"); // blank -> throws\n// after\nvar options = VertexAiTextEmbeddingOptions.builder()\n    .model(\"textembedding-gecko@003\")\n    .build();","handlingStrategy":"validation","validationCode":"Assert.hasText(options.getModel(), \"Vertex AI embedding model must be set, e.g. textembedding-gecko@003\");","typeGuard":"static boolean validModel(VertexAiTextEmbeddingOptions o) { return o != null && StringUtils.hasText(o.getModel()); }","tryCatchPattern":"try { return model.call(request); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"model cannot be null\")) { /* rebuild options with default model */ } throw e; }","preventionTips":["Never set model to null/empty string explicitly - use builder defaults","Externalize the model name in application config and validate it at startup","Pin the model version explicitly (e.g. textembedding-gecko@003)"],"tags":["java","google-vertex-ai","validation","embedding"],"backgroundTag":"empty-required-field","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}