spring-projects/spring-ai · error · java.lang.UnsupportedOperationException

Embedding is not supported for this model:

Error message

Embedding is not supported for this model: 

What it means

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.

Source

Thrown at models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java:196

		return this.modelId;
	}

	/**
	 * Get the AWS region.
	 * @return The AWS region.
	 */
	public Region getRegion() {
		return this.region;
	}

	/**
	 * Compute the embedding for the given text.
	 *
	 * @param request The embedding request.
	 * @return Returns the embedding response.
	 */
	protected O embedding(I request) {
		throw new UnsupportedOperationException("Embedding is not supported for this model: " + this.modelId);
	}

	/**
	 * Chat completion invocation.
	 *
	 * @param request The chat completion request.
	 * @return The chat completion response.
	 */
	protected O chatCompletion(I request) {
		throw new UnsupportedOperationException("Chat completion is not supported for this model: " + this.modelId);
	}

	/**
	 * Chat completion invocation with streaming response.
	 *
	 * @param request The chat completion request.
	 * @return The chat completion response stream.
	 */

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Use the Titan embedding client (BedrockTitanEmbeddingApi) or another Bedrock API subclass that overrides embedding()
  2. Verify the Spring AI wrapper (e.g. BedrockTitanEmbeddingModel) matches the model type you configured
  3. Check the modelId/region config so the chat client is not mistakenly used as an EmbeddingModel

Example fix

// before
AbstractBedrockApi<?> api = new BedrockAnthropicChatApi(modelId, region);
api.embedding(request); // throws
// after
var api = new BedrockTitanEmbeddingApi("amazon.titan-embed-text-v1", region);
api.embedding(request);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!(bedrockApi instanceof BedrockTitanEmbeddingApi)) { throw new IllegalStateException("Selected Bedrock API does not support embeddings"); }

Type guard

boolean supportsEmbeddings(AbstractBedrockApi<?> api) { return api instanceof BedrockTitanEmbeddingApi; }

Try / catch

try { api.embedding(request); } catch (UnsupportedOperationException e) { /* fall back to Titan embedding client or surface config error */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/86f3e12528021592. Report an issue: GitHub.