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
Open AI Embedding Model implementation.
- Author:
- Christian Tzolov, Thomas Vitale, Josh Long
-
Field Summary
Fields inherited from class org.springframework.ai.embedding.AbstractEmbeddingModel
embeddingDimensions -
Constructor Summary
ConstructorsConstructorDescriptionOpenAiEmbeddingModel(OpenAiApi openAiApi) Constructor for the OpenAiEmbeddingModel class.OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode) Initializes a new instance of the OpenAiEmbeddingModel class.OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode, OpenAiEmbeddingOptions openAiEmbeddingOptions) Initializes a new instance of the OpenAiEmbeddingModel class.OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode, OpenAiEmbeddingOptions options, org.springframework.retry.support.RetryTemplate retryTemplate) Initializes a new instance of the OpenAiEmbeddingModel class.OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode, OpenAiEmbeddingOptions options, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry) Initializes a new instance of the OpenAiEmbeddingModel class. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.ai.embedding.EmbeddingResponsecall(org.springframework.ai.embedding.EmbeddingRequest request) float[]embed(org.springframework.ai.document.Document document) 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
Constructor for the OpenAiEmbeddingModel class.- Parameters:
openAiApi- The OpenAiApi instance to use for making API requests.
-
OpenAiEmbeddingModel
public OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode) Initializes a new instance of the OpenAiEmbeddingModel class.- Parameters:
openAiApi- The OpenAiApi instance to use for making API requests.metadataMode- The mode for generating metadata.
-
OpenAiEmbeddingModel
public OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode, OpenAiEmbeddingOptions openAiEmbeddingOptions) Initializes a new instance of the OpenAiEmbeddingModel class.- Parameters:
openAiApi- The OpenAiApi instance to use for making API requests.metadataMode- The mode for generating metadata.openAiEmbeddingOptions- The options for OpenAi embedding.
-
OpenAiEmbeddingModel
public OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode, OpenAiEmbeddingOptions options, org.springframework.retry.support.RetryTemplate retryTemplate) Initializes a new instance of the OpenAiEmbeddingModel class.- Parameters:
openAiApi- - The OpenAiApi instance to use for making API requests.metadataMode- - The mode for generating metadata.options- - The options for OpenAI embedding.retryTemplate- - The RetryTemplate for retrying failed API requests.
-
OpenAiEmbeddingModel
public OpenAiEmbeddingModel(OpenAiApi openAiApi, org.springframework.ai.document.MetadataMode metadataMode, OpenAiEmbeddingOptions options, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry) Initializes a new instance of the OpenAiEmbeddingModel class.- Parameters:
openAiApi- - The OpenAiApi instance to use for making API requests.metadataMode- - The mode for generating metadata.options- - The options for OpenAI embedding.retryTemplate- - The RetryTemplate for retrying failed API requests.observationRegistry- - The ObservationRegistry used for instrumentation.
-
-
Method Details
-
embed
public float[] embed(org.springframework.ai.document.Document document) -
call
public org.springframework.ai.embedding.EmbeddingResponse call(org.springframework.ai.embedding.EmbeddingRequest request) -
setObservationConvention
public void setObservationConvention(org.springframework.ai.embedding.observation.EmbeddingModelObservationConvention observationConvention) Use the provided convention for reporting observation data- Parameters:
observationConvention- The provided convention
-