Class OpenAiEmbeddingModel

java.lang.Object
org.springframework.ai.embedding.AbstractEmbeddingModel
org.springframework.ai.openai.OpenAiEmbeddingModel
All Implemented Interfaces:
org.springframework.ai.embedding.EmbeddingModel, org.springframework.ai.model.Model<org.springframework.ai.embedding.EmbeddingRequest,org.springframework.ai.embedding.EmbeddingResponse>

public class OpenAiEmbeddingModel extends org.springframework.ai.embedding.AbstractEmbeddingModel
Embedding Model implementation using the OpenAI Java SDK.
Author:
Julien Dubois, Soby Chacko, Thomas Vitale, Christian Tzolov, Josh Long, guan xu
  • Constructor Details

    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel()
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with default options.
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable OpenAiEmbeddingOptions options)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with the given options.
      Parameters:
      options - the embedding options
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with the given metadata mode and options.
      Parameters:
      metadataMode - the metadata mode
      options - the embedding options
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with the given options and observation registry.
      Parameters:
      options - the embedding options
      observationRegistry - the observation registry
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with the given metadata mode, options, and observation registry.
      Parameters:
      metadataMode - the metadata mode
      options - the embedding options
      observationRegistry - the observation registry
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with the given OpenAI client.
      Parameters:
      openAiClient - the OpenAI client
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with the given OpenAI client and metadata mode.
      Parameters:
      openAiClient - the OpenAI client
      metadataMode - the metadata mode
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with all configuration options.
      Parameters:
      openAiClient - the OpenAI client
      metadataMode - the metadata mode
      options - the embedding options
    • OpenAiEmbeddingModel

      @Deprecated public OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
      Deprecated.
      in favor of builder()
      Creates a new OpenAiEmbeddingModel with all configuration options.
      Parameters:
      openAiClient - the OpenAI client
      metadataMode - the metadata mode
      options - the embedding options
      observationRegistry - the observation registry
  • Method Details

    • builder

      public static OpenAiEmbeddingModel.Builder builder()
    • getEmbeddingContent

      public String getEmbeddingContent(org.springframework.ai.document.Document document)
    • embed

      public float[] embed(org.springframework.ai.document.Document document)
    • call

      public org.springframework.ai.embedding.EmbeddingResponse call(org.springframework.ai.embedding.EmbeddingRequest embeddingRequest)
    • getOptions

      public OpenAiEmbeddingOptions getOptions()
      Gets the embedding options for this model.
      Returns:
      the embedding options
    • setObservationConvention

      public void setObservationConvention(org.springframework.ai.embedding.observation.EmbeddingModelObservationConvention observationConvention)
      Use the provided convention for reporting observation data
      Parameters:
      observationConvention - The provided convention