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>
This commit is contained in:
committed by
Ilayaperumal Gopinathan
parent
127f7009eb
commit
d5203ed038
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import org.springframework.core.io.DefaultResourceLoader;
|
||||
*/
|
||||
public abstract class AbstractEmbeddingModel implements EmbeddingModel {
|
||||
|
||||
private static Map<String, Integer> KNOWN_EMBEDDING_DIMENSIONS = loadKnownModelDimensions();
|
||||
private static final Map<String, Integer> KNOWN_EMBEDDING_DIMENSIONS = loadKnownModelDimensions();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.ai.embedding;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.ai.model.ModelResult;
|
||||
@@ -25,11 +26,11 @@ import org.springframework.ai.model.ModelResult;
|
||||
*/
|
||||
public class Embedding implements ModelResult<float[]> {
|
||||
|
||||
private float[] embedding;
|
||||
private final float[] embedding;
|
||||
|
||||
private Integer index;
|
||||
private final Integer index;
|
||||
|
||||
private EmbeddingResultMetadata metadata;
|
||||
private final EmbeddingResultMetadata metadata;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Embedding} instance.
|
||||
@@ -83,12 +84,12 @@ public class Embedding implements ModelResult<float[]> {
|
||||
return false;
|
||||
}
|
||||
Embedding other = (Embedding) o;
|
||||
return Objects.equals(this.embedding, other.embedding) && Objects.equals(this.index, other.index);
|
||||
return Arrays.equals(this.embedding, other.embedding) && Objects.equals(this.index, other.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.embedding, this.index);
|
||||
return Objects.hash(Arrays.hashCode(this.embedding), this.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -81,13 +81,13 @@ public class EmbeddingResultMetadata implements ResultMetadata {
|
||||
|
||||
public static class ModalityUtils {
|
||||
|
||||
private static MimeType TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType("text/*");
|
||||
private static final MimeType TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType("text/*");
|
||||
|
||||
private static MimeType IMAGE_MIME_TYPE = MimeTypeUtils.parseMimeType("image/*");
|
||||
private static final MimeType IMAGE_MIME_TYPE = MimeTypeUtils.parseMimeType("image/*");
|
||||
|
||||
private static MimeType VIDEO_MIME_TYPE = MimeTypeUtils.parseMimeType("video/*");
|
||||
private static final MimeType VIDEO_MIME_TYPE = MimeTypeUtils.parseMimeType("video/*");
|
||||
|
||||
private static MimeType AUDIO_MIME_TYPE = MimeTypeUtils.parseMimeType("audio/*");
|
||||
private static final MimeType AUDIO_MIME_TYPE = MimeTypeUtils.parseMimeType("audio/*");
|
||||
|
||||
/**
|
||||
* Infers the {@link ModalityType} of the source data used to generate the
|
||||
|
||||
Reference in New Issue
Block a user