Skip to content

Commit d5203ed

Browse files
sobychackoilayaperumalg
authored andcommitted
Fix array comparison and add final modifiers in embedding classes
- Fix Embedding equals() using Arrays.equals() for embedding array comparison - Fix Embedding hashCode() using Arrays.hashCode() for proper array hashing - Add final modifiers to fields in Embedding classes Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
1 parent 127f700 commit d5203ed

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

spring-ai-core/src/main/java/org/springframework/ai/embedding/AbstractEmbeddingModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
*/
3333
public abstract class AbstractEmbeddingModel implements EmbeddingModel {
3434

35-
private static Map<String, Integer> KNOWN_EMBEDDING_DIMENSIONS = loadKnownModelDimensions();
35+
private static final Map<String, Integer> KNOWN_EMBEDDING_DIMENSIONS = loadKnownModelDimensions();
3636

3737
/**
3838
* Default constructor.

spring-ai-core/src/main/java/org/springframework/ai/embedding/Embedding.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ai.embedding;
1818

19+
import java.util.Arrays;
1920
import java.util.Objects;
2021

2122
import org.springframework.ai.model.ModelResult;
@@ -25,11 +26,11 @@
2526
*/
2627
public class Embedding implements ModelResult<float[]> {
2728

28-
private float[] embedding;
29+
private final float[] embedding;
2930

30-
private Integer index;
31+
private final Integer index;
3132

32-
private EmbeddingResultMetadata metadata;
33+
private final EmbeddingResultMetadata metadata;
3334

3435
/**
3536
* Creates a new {@link Embedding} instance.
@@ -83,12 +84,12 @@ public boolean equals(Object o) {
8384
return false;
8485
}
8586
Embedding other = (Embedding) o;
86-
return Objects.equals(this.embedding, other.embedding) && Objects.equals(this.index, other.index);
87+
return Arrays.equals(this.embedding, other.embedding) && Objects.equals(this.index, other.index);
8788
}
8889

8990
@Override
9091
public int hashCode() {
91-
return Objects.hash(this.embedding, this.index);
92+
return Objects.hash(Arrays.hashCode(this.embedding), this.index);
9293
}
9394

9495
@Override

spring-ai-core/src/main/java/org/springframework/ai/embedding/EmbeddingResultMetadata.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -81,13 +81,13 @@ public enum ModalityType {
8181

8282
public static class ModalityUtils {
8383

84-
private static MimeType TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType("text/*");
84+
private static final MimeType TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType("text/*");
8585

86-
private static MimeType IMAGE_MIME_TYPE = MimeTypeUtils.parseMimeType("image/*");
86+
private static final MimeType IMAGE_MIME_TYPE = MimeTypeUtils.parseMimeType("image/*");
8787

88-
private static MimeType VIDEO_MIME_TYPE = MimeTypeUtils.parseMimeType("video/*");
88+
private static final MimeType VIDEO_MIME_TYPE = MimeTypeUtils.parseMimeType("video/*");
8989

90-
private static MimeType AUDIO_MIME_TYPE = MimeTypeUtils.parseMimeType("audio/*");
90+
private static final MimeType AUDIO_MIME_TYPE = MimeTypeUtils.parseMimeType("audio/*");
9191

9292
/**
9393
* Infers the {@link ModalityType} of the source data used to generate the

0 commit comments

Comments
 (0)