spring-projects / spring-projects/spring-ai

AWS Bedrock Cohere Embedding Model returns no metrics

Open
#6,098 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 10h
Merged PRs (30d)
5

Description

Bug description
When using the AWS Bedrock Cohere Embedding Model (cohere.embed-multilingual-v3), no metrics are included in the response. So I cannot track the used tokens.

When logging the raw response, the input token usage is included as HTTP response header, so Spring AI could parse it and fill the metrics.
e.g. "X-Amzn-Bedrock-Input-Token-Count: 743", "X-Amzn-Bedrock-Invocation-Latency: 186".

Environment
Java 21, Spring AI 1.1.6

Steps to reproduce
Configure the AWS Bedrock Cohere Embedding Model.
Submit any request.
See that no metrics are attached.

Expected behavior
The metrics were set from the information included in the HTTP headers.

Setup

Application Properties:

spring.ai.model.embedding=bedrock-cohere
spring.ai.bedrock.cohere.embedding.model=cohere.embed-multilingual-v3
spring.ai.bedrock.cohere.embedding.options.input-type=CLUSTERING

Service:

import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.embedding.EmbeddingRequest;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
class EmbeddingServiceImpl implements EmbeddingService {

    private final EmbeddingModel model;

    @Override
    public EmbeddingResponse embed(EmbeddingRequest request) {
        EmbeddingResponse response = embeddingModel.call(embeddingRequest);   // <-- call Spring AI
        return response;
    }
}

Dependencies:

dependencies {
    implementation("org.springframework.ai:spring-ai-starter-model-bedrock-converse")
    implementation("org.springframework.ai:spring-ai-starter-model-bedrock")
    implementation("software.amazon.awssdk:apache-client")
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the AWS Bedrock Cohere Embedding Model from the EmbeddingModel call and inspect how the raw HTTP response headers are handled. Reproduce the request with cohere.embed-multilingual-v3 and verify that X-Amzn-Bedrock-Input-Token-Count and X-Amzn-Bedrock-Invocation-Latency are reflected in the returned metrics.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, java, spring
Domain
ai, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.