
clarifai2.dto.prediction.Embedding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Clarifai Java API Client
The newest version!
package clarifai2.dto.prediction;
import clarifai2.internal.grpc.api.EmbeddingOuterClass;
import com.google.auto.value.AutoValue;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("NullableProblems")
@AutoValue
public abstract class Embedding extends Prediction {
Embedding() {} // AutoValue instances only
@NotNull public final float[] embedding() {
// Return a defensive copy so that they can't modify the original byte-array
final float[] embedding = _embedding();
return Arrays.copyOf(embedding, embedding.length);
}
@SuppressWarnings("PMD.MethodNamingConventions")
@NotNull abstract float[] _embedding();
@NotNull public abstract int numDimensions();
@NotNull public static Embedding deserialize(EmbeddingOuterClass.Embedding embeddingResponse) {
List vectorList = embeddingResponse.getVectorList();
float[] embedding = new float[vectorList.size()];
for (int i = 0; i < vectorList.size(); i++) {
embedding[i] = vectorList.get(i);
}
return new AutoValue_Embedding(
embedding,
embeddingResponse.getNumDimensions()
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy