Package org.springframework.ai.openai
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.springframework.ai.embedding.AbstractEmbeddingModel
embeddingDimensions -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient) Deprecated.in favor ofbuilder()OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode) Deprecated.in favor ofbuilder()OpenAiEmbeddingModel(@Nullable com.openai.client.OpenAIClient openAiClient, @Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options) Deprecated.in favor ofbuilder()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 ofbuilder()OpenAiEmbeddingModel(@Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options) Deprecated.in favor ofbuilder()OpenAiEmbeddingModel(@Nullable org.springframework.ai.document.MetadataMode metadataMode, @Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry) Deprecated.in favor ofbuilder()OpenAiEmbeddingModel(@Nullable OpenAiEmbeddingOptions options) Deprecated.in favor ofbuilder()OpenAiEmbeddingModel(@Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry) Deprecated.in favor ofbuilder() -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenAiEmbeddingModel.Builderbuilder()org.springframework.ai.embedding.EmbeddingResponsecall(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.voidsetObservationConvention(org.springframework.ai.embedding.observation.EmbeddingModelObservationConvention observationConvention) Use the provided convention for reporting observation dataMethods inherited from class org.springframework.ai.embedding.AbstractEmbeddingModel
dimensions, dimensionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.embedding.EmbeddingModel
embed, embed, embed, embedForResponse
-
Constructor Details
-
OpenAiEmbeddingModel
Deprecated.in favor ofbuilder()Creates a new OpenAiEmbeddingModel with default options. -
OpenAiEmbeddingModel
Deprecated.in favor ofbuilder()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 ofbuilder()Creates a new OpenAiEmbeddingModel with the given metadata mode and options.- Parameters:
metadataMode- the metadata modeoptions- the embedding options
-
OpenAiEmbeddingModel
@Deprecated public OpenAiEmbeddingModel(@Nullable OpenAiEmbeddingOptions options, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry) Deprecated.in favor ofbuilder()Creates a new OpenAiEmbeddingModel with the given options and observation registry.- Parameters:
options- the embedding optionsobservationRegistry- 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 ofbuilder()Creates a new OpenAiEmbeddingModel with the given metadata mode, options, and observation registry.- Parameters:
metadataMode- the metadata modeoptions- the embedding optionsobservationRegistry- the observation registry
-
OpenAiEmbeddingModel
Deprecated.in favor ofbuilder()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 ofbuilder()Creates a new OpenAiEmbeddingModel with the given OpenAI client and metadata mode.- Parameters:
openAiClient- the OpenAI clientmetadataMode- 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 ofbuilder()Creates a new OpenAiEmbeddingModel with all configuration options.- Parameters:
openAiClient- the OpenAI clientmetadataMode- the metadata modeoptions- 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 ofbuilder()Creates a new OpenAiEmbeddingModel with all configuration options.- Parameters:
openAiClient- the OpenAI clientmetadataMode- the metadata modeoptions- the embedding optionsobservationRegistry- the observation registry
-
-
Method Details
-
builder
-
getEmbeddingContent
-
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
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
-
builder()