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
  • Field Summary

    Fields inherited from class org.springframework.ai.embedding.AbstractEmbeddingModel

    embeddingDimensions
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new OpenAiEmbeddingModel with default options.
    OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient)
    Creates a new OpenAiEmbeddingModel with the given OpenAI client.
    OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode)
    Creates a new OpenAiEmbeddingModel with the given OpenAI client and metadata mode.
    OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options)
    Creates a new OpenAiEmbeddingModel with all configuration options.
    OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
    Creates a new OpenAiEmbeddingModel with all configuration options.
    OpenAiEmbeddingModel(@Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options)
    Creates a new OpenAiEmbeddingModel with the given metadata mode and options.
    OpenAiEmbeddingModel(@Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
    Creates a new OpenAiEmbeddingModel with the given metadata mode, options, and observation registry.
    Creates a new OpenAiEmbeddingModel with the given options.
    OpenAiEmbeddingModel(@Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
    Creates a new OpenAiEmbeddingModel with the given options and observation registry.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.ai.embedding.EmbeddingResponse
    call(org.springframework.ai.embedding.EmbeddingRequest embeddingRequest)
     
    float[]
    embed(org.springframework.ai.document.Document document)
     
    getEmbeddingContent(org.springframework.ai.document.Document document)
     
    Gets the embedding options for this model.
    void
    setObservationConvention(org.springframework.ai.embedding.observation.EmbeddingModelObservationConvention observationConvention)
    Use the provided convention for reporting observation data

    Methods inherited from class org.springframework.ai.embedding.AbstractEmbeddingModel

    dimensions, dimensions

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.ai.embedding.EmbeddingModel

    embed, embed, embed, embedForResponse
  • Constructor Details

    • OpenAiEmbeddingModel

      public OpenAiEmbeddingModel()
      Creates a new OpenAiEmbeddingModel with default options.
    • OpenAiEmbeddingModel

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

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

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

      public OpenAiEmbeddingModel(@Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
      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

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

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

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

      public OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry)
      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

    • 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