I encountered an error when using AWS Bedrock with Spring AI. The following exception is thrown by the BedrockRuntime service:

Observed Issue:

Error Occured at launch time software.amazon.awssdk.services.bedrockruntime.model.ValidationException: Malformed input request: #: required key [prompt] not found#: required key [max_tokens_to_sample] not found#: extraneous key [texts] is not permitted#: extraneous key [truncate] is not permitted#: extraneous key [input_type] is not permitted, please reformat your input and try again. (Service: BedrockRuntime, Status Code: 400, Request ID: XXXXX)

Expected Behavior

The request should be correctly formatted to be accepted by AWS Bedrock.

Input

  • Spring AI version: last bom version
  • AWS Bedrock model used: anthropic.claude-3-haiku-20240307-v1:0

Properties

AWS_BEDROCK_MODEL=anthropic.claude-3-haiku-20240307-v1:0 spring.ai.bedrock.cohere.embedding.enabled=true spring.ai.bedrock.cohere.embedding.model=${AWS_BEDROCK_MODEL} spring.ai.bedrock.cohere.embedding.options.truncate=none spring.ai.bedrock.cohere.embedding.options.input-type=search_document spring.ai.bedrock.titan.embedding.enabled=false spring.ai.bedrock.titan.embedding.model=${AWS_BEDROCK_MODEL}

Dependencies

        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-bedrock-converse-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-bedrock-ai-spring-boot-starter</artifactId>
        </dependency>

Comment From: dev-jonghoonpark

Anthropic Claude-3 Haiku is a chat model, not an embedding model.

Currently, in Spring AI, You can select a Cohere model instead:

  • cohere.embed-multilingual-v3
  • cohere.embed-english-v3
Property Description Default
spring.ai.bedrock.cohere.embedding.model The model id to use. See the CohereEmbeddingModel for the supported models. cohere.embed-multilingual-v3

Comment From: cjullien

thanks, sorry for the miss understanding