![JAR search and dependency download from the Maven repository](/logo.png)
com.microsoft.semantickernel.services.textembedding.Embedding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of semantickernel-api Show documentation
Show all versions of semantickernel-api Show documentation
Defines the public interface for the Semantic Kernel
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.services.textembedding;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/** Represents a strongly typed vector of numeric data. */
@SuppressFBWarnings("SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR") // This class is not a singleton
public class Embedding {
// vector is immutable!
private final List vector;
private static final Embedding EMPTY = new Embedding();
/**
* Returns an empty {@code Embedding} instance.
* @return An empty {@code Embedding} instance.
*/
public static Embedding empty() {
return EMPTY;
}
/** Initializes a new instance of the Embedding class. */
public Embedding() {
this.vector = Collections.emptyList();
}
/**
* Initializes a new instance of the Embedding class that contains numeric elements copied from
* the specified collection
*
* @param vector The collection whose elements are copied to the new Embedding
*/
public Embedding(@Nonnull List vector) {
Objects.requireNonNull(vector);
this.vector = Collections.unmodifiableList(vector);
}
/**
* Initializes a new instance of the Embedding class that contains numeric elements copied from
* the specified array
*
* @param vector The array whose elements are copied to the new Embedding
*/
public Embedding(@Nonnull float[] vector) {
Objects.requireNonNull(vector);
List list = new ArrayList<>(vector.length);
for (float f : vector) {
list.add(f);
}
this.vector = Collections.unmodifiableList(list);
}
/**
* Return the embedding vector as a read-only list.
*
* @return The embedding vector as a read-only list.
*/
public List getVector() {
return Collections.unmodifiableList(this.vector);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy