Package org.springframework.ai.embedding
Interface EmbeddingModel
- All Superinterfaces:
Model<EmbeddingRequest,
EmbeddingResponse>
- All Known Implementing Classes:
AbstractEmbeddingModel
,AzureOpenAiEmbeddingModel
,BedrockCohereEmbeddingModel
,BedrockTitanEmbeddingModel
,MiniMaxEmbeddingModel
,MistralAiEmbeddingModel
,OCIEmbeddingModel
,OllamaEmbeddingModel
,OpenAiEmbeddingModel
,PostgresMlEmbeddingModel
,QianFanEmbeddingModel
,TransformersEmbeddingModel
,VertexAiTextEmbeddingModel
,WatsonxAiEmbeddingModel
,ZhiPuAiEmbeddingModel
EmbeddingModel is a generic interface for embedding models.
- Since:
- 1.0.0
- Author:
- Mark Pollack, Christian Tzolov, Josh Long, Soby Chacko, Jihoon Kim
-
Method Summary
Modifier and TypeMethodDescriptioncall
(EmbeddingRequest request) Executes a method call to the AI model.default int
Get the number of dimensions of the embedded vectors.default float[]
Embeds the given text into a vector.default List<float[]>
Embeds a batch of texts into vectors.default List<float[]>
embed
(List<Document> documents, EmbeddingOptions options, BatchingStrategy batchingStrategy) Embeds a batch ofDocument
s into vectors based on aBatchingStrategy
.float[]
Embeds the given document's content into a vector.default EmbeddingResponse
embedForResponse
(List<String> texts) Embeds a batch of texts into vectors and returns theEmbeddingResponse
.
-
Method Details
-
call
Description copied from interface:Model
Executes a method call to the AI model.- Specified by:
call
in interfaceModel<EmbeddingRequest,
EmbeddingResponse> - Parameters:
request
- the request object to be sent to the AI model- Returns:
- the response from the AI model
-
embed
Embeds the given text into a vector.- Parameters:
text
- the text to embed.- Returns:
- the embedded vector.
-
embed
Embeds the given document's content into a vector.- Parameters:
document
- the document to embed.- Returns:
- the embedded vector.
-
embed
Embeds a batch of texts into vectors.- Parameters:
texts
- list of texts to embed.- Returns:
- list of embedded vectors.
-
embed
default List<float[]> embed(List<Document> documents, EmbeddingOptions options, BatchingStrategy batchingStrategy) Embeds a batch ofDocument
s into vectors based on aBatchingStrategy
.- Parameters:
documents
- list ofDocument
s.options
-EmbeddingOptions
.batchingStrategy
-BatchingStrategy
.- Returns:
- a list of float[] that represents the vectors for the incoming
Document
s. The returned list is expected to be in the same order of theDocument
list.
-
embedForResponse
Embeds a batch of texts into vectors and returns theEmbeddingResponse
.- Parameters:
texts
- list of texts to embed.- Returns:
- the embedding response.
-
dimensions
default int dimensions()Get the number of dimensions of the embedded vectors. Note that by default, this method will call the remote Embedding endpoint to get the dimensions of the embedded vectors. If the dimensions are known ahead of time, it is recommended to override this method.- Returns:
- the number of dimensions of the embedded vectors.
-