Class TransformersEmbeddingClient
java.lang.Object
org.springframework.ai.embedding.AbstractEmbeddingClient
org.springframework.ai.transformers.TransformersEmbeddingClient
- All Implemented Interfaces:
EmbeddingClient
,ModelClient<EmbeddingRequest,
,EmbeddingResponse> org.springframework.beans.factory.InitializingBean
public class TransformersEmbeddingClient
extends AbstractEmbeddingClient
implements org.springframework.beans.factory.InitializingBean
https://www.sbert.net/index.html https://www.sbert.net/docs/pretrained_models.html
- Author:
- Christian Tzolov
-
Field Summary
Fields inherited from class org.springframework.ai.embedding.AbstractEmbeddingClient
embeddingDimensions
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
call
(EmbeddingRequest request) Executes a method call to the AI model.Embeds the given text into a vector.Embeds a batch of texts into vectors.Embeds the given document's content into a vector.embedForResponse
(List<String> texts) Embeds a batch of texts into vectors and returns theEmbeddingResponse
.void
setDisableCaching
(boolean disableCaching) void
setGpuDeviceId
(int gpuDeviceId) void
setModelOutputName
(String modelOutputName) void
setModelResource
(String modelResourceUri) void
setModelResource
(org.springframework.core.io.Resource modelResource) void
setResourceCacheDirectory
(String resourceCacheDir) void
setTokenizerOptions
(Map<String, String> tokenizerOptions) void
setTokenizerResource
(String tokenizerResourceUri) void
setTokenizerResource
(org.springframework.core.io.Resource tokenizerResource) Methods inherited from class org.springframework.ai.embedding.AbstractEmbeddingClient
dimensions, dimensions
-
Field Details
-
DEFAULT_ONNX_TOKENIZER_URI
- See Also:
-
DEFAULT_ONNX_MODEL_URI
- See Also:
-
DEFAULT_MODEL_OUTPUT_NAME
- See Also:
-
tokenizerOptions
-
-
Constructor Details
-
TransformersEmbeddingClient
public TransformersEmbeddingClient() -
TransformersEmbeddingClient
-
-
Method Details
-
setTokenizerOptions
-
setDisableCaching
public void setDisableCaching(boolean disableCaching) -
setResourceCacheDirectory
-
setGpuDeviceId
public void setGpuDeviceId(int gpuDeviceId) -
setTokenizerResource
public void setTokenizerResource(org.springframework.core.io.Resource tokenizerResource) -
setModelResource
public void setModelResource(org.springframework.core.io.Resource modelResource) -
setTokenizerResource
-
setModelResource
-
setModelOutputName
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
embed
Description copied from interface:EmbeddingClient
Embeds the given text into a vector.- Specified by:
embed
in interfaceEmbeddingClient
- Parameters:
text
- the text to embed.- Returns:
- the embedded vector.
-
embed
Description copied from interface:EmbeddingClient
Embeds the given document's content into a vector.- Specified by:
embed
in interfaceEmbeddingClient
- Parameters:
document
- the document to embed.- Returns:
- the embedded vector.
-
embedForResponse
Description copied from interface:EmbeddingClient
Embeds a batch of texts into vectors and returns theEmbeddingResponse
.- Specified by:
embedForResponse
in interfaceEmbeddingClient
- Parameters:
texts
- list of texts to embed.- Returns:
- the embedding response.
-
embed
Description copied from interface:EmbeddingClient
Embeds a batch of texts into vectors.- Specified by:
embed
in interfaceEmbeddingClient
- Parameters:
texts
- list of texts to embed.- Returns:
- list of list of embedded vectors.
-
call
Description copied from interface:ModelClient
Executes a method call to the AI model.- Specified by:
call
in interfaceEmbeddingClient
- Specified by:
call
in interfaceModelClient<EmbeddingRequest,
EmbeddingResponse> - Parameters:
request
- the request object to be sent to the AI model- Returns:
- the response from the AI model
-