Enum Class EmbeddingTask

java.lang.Object
java.lang.Enum<EmbeddingTask>
com.tnsai.llm.cache.EmbeddingTask
All Implemented Interfaces:
Serializable, Comparable<EmbeddingTask>, Constable

public enum EmbeddingTask extends Enum<EmbeddingTask>
The task an embedding is generated for.

Instruction-tuned embedding models (e.g. nomic-embed-text) are contrastively trained with a per-task instruction prefix and condition the vector on it — the same text embedded for two different tasks yields two different vectors. Picking the right task is what pulls related text apart from unrelated text; embedding such a model with no task at all collapses every vector into one degenerate sub-space.

Symmetric vs asymmetric

  • CLUSTERING and CLASSIFICATION are symmetric: like is compared with like (prompt↔prompt similarity, dedup, semantic textual similarity, the semantic cache). Both sides of a comparison must use the same task or the vectors are not comparable.
  • QUERY and DOCUMENT are the asymmetric retrieval pair: a short query is embedded as QUERY and matched against corpus text embedded as DOCUMENT (the RAG / vector-store path).

Providers whose model has no task convention (e.g. HashEmbeddingProvider, OpenAI text-embedding-3) ignore this and return the same vector regardless — see the task-free defaults on EmbeddingProvider.

Since:
0.13.0
See Also:
  • Enum Constant Details

    • QUERY

      public static final EmbeddingTask QUERY
      Asymmetric retrieval: a search query, matched against DOCUMENT vectors.
    • DOCUMENT

      public static final EmbeddingTask DOCUMENT
      Asymmetric retrieval: corpus text to be retrieved by a QUERY. Also the neutral default for embedding a single standalone piece of text.
    • CLUSTERING

      public static final EmbeddingTask CLUSTERING
      Symmetric similarity: clustering, deduplication, semantic textual similarity, semantic cache.
    • CLASSIFICATION

      public static final EmbeddingTask CLASSIFICATION
      Symmetric classification / label assignment.
  • Method Details

    • values

      public static EmbeddingTask[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static EmbeddingTask valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null