Skip to content

Commit 8da10e6

Browse files
committed
Fix formatting issues in BedrockTitanEmbeddingModel.java
1 parent 95ba402 commit 8da10e6

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/titan/BedrockTitanEmbeddingModel.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838
import io.micrometer.observation.Observation;
3939

4040
/**
41-
* {@link org.springframework.ai.embedding.EmbeddingModel} implementation that
42-
* uses the
43-
* Bedrock Titan Embedding API. Titan Embedding supports text and image (encoded
44-
* in
41+
* {@link org.springframework.ai.embedding.EmbeddingModel} implementation that uses the
42+
* Bedrock Titan Embedding API. Titan Embedding supports text and image (encoded in
4543
* base64) inputs.
4644
*
4745
* Note: Titan Embedding does not support batch embedding.
@@ -59,8 +57,7 @@ public class BedrockTitanEmbeddingModel extends AbstractEmbeddingModel {
5957
private final ObservationRegistry observationRegistry;
6058

6159
/**
62-
* Titan Embedding API input types. Could be either text or image (encoded in
63-
* base64).
60+
* Titan Embedding API input types. Could be either text or image (encoded in base64).
6461
*/
6562
private InputType inputType = InputType.TEXT;
6663

@@ -71,9 +68,7 @@ public BedrockTitanEmbeddingModel(TitanEmbeddingBedrockApi titanEmbeddingBedrock
7168
}
7269

7370
/**
74-
* Titan Embedding API input types. Could be either text or image (encoded in
75-
* base64).
76-
*
71+
* Titan Embedding API input types. Could be either text or image (encoded in base64).
7772
* @param inputType the input type to use.
7873
*/
7974
public BedrockTitanEmbeddingModel withInputType(InputType inputType) {
@@ -101,26 +96,28 @@ public EmbeddingResponse call(EmbeddingRequest request) {
10196

10297
try {
10398
TitanEmbeddingResponse response = Observation
104-
.createNotStarted("bedrock.embedding", this.observationRegistry)
105-
.lowCardinalityKeyValue("model", "titan")
106-
.lowCardinalityKeyValue("input_type", this.inputType.name().toLowerCase())
107-
.highCardinalityKeyValue("input_length", String.valueOf(inputContent.length()))
108-
.observe(() -> {
109-
TitanEmbeddingResponse r = this.embeddingApi.embedding(apiRequest);
110-
Assert.notNull(r, "Embedding API returned null response");
111-
return r;
112-
});
99+
.createNotStarted("bedrock.embedding", this.observationRegistry)
100+
.lowCardinalityKeyValue("model", "titan")
101+
.lowCardinalityKeyValue("input_type", this.inputType.name().toLowerCase())
102+
.highCardinalityKeyValue("input_length", String.valueOf(inputContent.length()))
103+
.observe(() -> {
104+
TitanEmbeddingResponse r = this.embeddingApi.embedding(apiRequest);
105+
Assert.notNull(r, "Embedding API returned null response");
106+
return r;
107+
});
113108

114109
if (response.embedding() == null || response.embedding().length == 0) {
115110
logger.warn("Empty embedding vector returned for input at index {}. Skipping.", indexCounter.get());
116111
continue;
117112
}
118113

119114
embeddings.add(new Embedding(response.embedding(), indexCounter.getAndIncrement()));
120-
} catch (Exception ex) {
115+
}
116+
catch (Exception ex) {
121117
logger.error("Titan API embedding failed for input at index {}: {}", indexCounter.get(),
122118
summarizeInput(inputContent), ex);
123-
throw ex; // Optional: Continue instead of throwing if you want partial success
119+
throw ex; // Optional: Continue instead of throwing if you want partial
120+
// success
124121
}
125122
}
126123

0 commit comments

Comments
 (0)