Class AbstractEmbeddingClient

java.lang.Object
org.springframework.ai.embedding.AbstractEmbeddingClient
All Implemented Interfaces:
EmbeddingClient, ModelClient<EmbeddingRequest,EmbeddingResponse>
Direct Known Subclasses:
AzureOpenAiEmbeddingClient, BedrockCohereEmbeddingClient, BedrockTitanEmbeddingClient, MistralAiEmbeddingClient, OllamaEmbeddingClient, OpenAiEmbeddingClient, PostgresMlEmbeddingClient, TransformersEmbeddingClient, VertexAiPaLm2EmbeddingClient

public abstract class AbstractEmbeddingClient extends Object implements EmbeddingClient
Abstract implementation of the EmbeddingClient interface that provides dimensions calculation caching.
Author:
Christian Tzolov
  • Field Details

    • embeddingDimensions

      protected final AtomicInteger embeddingDimensions
  • Constructor Details

    • AbstractEmbeddingClient

      public AbstractEmbeddingClient()
  • Method Details

    • dimensions

      public static int dimensions(EmbeddingClient embeddingClient, String modelName, String dummyContent)
      Return the dimension of the requested embedding generative name. If the generative name is unknown uses the EmbeddingClient to perform a dummy EmbeddingClient#embed and count the response dimensions.
      Parameters:
      embeddingClient - Fall-back client to determine, empirically the dimensions.
      modelName - Embedding generative name to retrieve the dimensions for.
      dummyContent - Dummy content to use for the empirical dimension calculation.
      Returns:
      Returns the embedding dimensions for the modelName.
    • dimensions

      public int dimensions()
      Specified by:
      dimensions in interface EmbeddingClient
      Returns:
      the number of dimensions of the embedded vectors. It is generative specific.