{"record":{"id":"86f3e12528021592","repo":"spring-projects/spring-ai","slug":"embedding-is-not-supported-for-this-model","errorCode":null,"errorMessage":"Embedding is not supported for this model: ","messagePattern":"Embedding is not supported for this model: ","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java","lineNumber":196,"sourceCode":"\t\treturn this.modelId;\n\t}\n\n\t/**\n\t * Get the AWS region.\n\t * @return The AWS region.\n\t */\n\tpublic Region getRegion() {\n\t\treturn this.region;\n\t}\n\n\t/**\n\t * Compute the embedding for the given text.\n\t *\n\t * @param request The embedding request.\n\t * @return Returns the embedding response.\n\t */\n\tprotected O embedding(I request) {\n\t\tthrow new UnsupportedOperationException(\"Embedding is not supported for this model: \" + this.modelId);\n\t}\n\n\t/**\n\t * Chat completion invocation.\n\t *\n\t * @param request The chat completion request.\n\t * @return The chat completion response.\n\t */\n\tprotected O chatCompletion(I request) {\n\t\tthrow new UnsupportedOperationException(\"Chat completion is not supported for this model: \" + this.modelId);\n\t}\n\n\t/**\n\t * Chat completion invocation with streaming response.\n\t *\n\t * @param request The chat completion request.\n\t * @return The chat completion response stream.\n\t */","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java#L178-L214","documentation":"AbstractBedrockApi is a generic base class where concrete subclasses (Titan for embeddings, Anthropic/Cohere/Llama for chat) override only the operations they support. This default embedding(I) implementation throws UnsupportedOperationException when the concrete model API does not implement embeddings, meaning the configured modelId cannot compute vector embeddings.","triggerScenarios":"Calling embedding(request) on a subclass of AbstractBedrockApi that did not override the method — e.g. invoking embedding on the Anthropic, Cohere chat-only, or Llama Bedrock API client.","commonSituations":"Injecting the wrong AbstractBedrockApi subclass into an EmbeddingModel wrapper; configuring a chat model ID where an embedding model is required; copy-pasting client setup across models.","solutions":["Use the Titan embedding client (BedrockTitanEmbeddingApi) or another Bedrock API subclass that overrides embedding()","Verify the Spring AI wrapper (e.g. BedrockTitanEmbeddingModel) matches the model type you configured","Check the modelId/region config so the chat client is not mistakenly used as an EmbeddingModel"],"exampleFix":"// before\nAbstractBedrockApi<?> api = new BedrockAnthropicChatApi(modelId, region);\napi.embedding(request); // throws\n// after\nvar api = new BedrockTitanEmbeddingApi(\"amazon.titan-embed-text-v1\", region);\napi.embedding(request);","handlingStrategy":"try-catch","validationCode":"if (!(bedrockApi instanceof BedrockTitanEmbeddingApi)) { throw new IllegalStateException(\"Selected Bedrock API does not support embeddings\"); }","typeGuard":"boolean supportsEmbeddings(AbstractBedrockApi<?> api) { return api instanceof BedrockTitanEmbeddingApi; }","tryCatchPattern":"try { api.embedding(request); } catch (UnsupportedOperationException e) { /* fall back to Titan embedding client or surface config error */ }","preventionTips":["Pair each model ID with the matching Spring AI API client class","Use BedrockTitanEmbeddingModel for embeddings, chat clients for chat","Review AbstractBedrockApi subclass overrides before use"],"tags":["bedrock","embeddings","unsupported-operation"],"backgroundTag":"method-not-implemented","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"}