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 Details

  • Constructor Details

    • TransformersEmbeddingClient

      public TransformersEmbeddingClient()
    • TransformersEmbeddingClient

      public TransformersEmbeddingClient(MetadataMode metadataMode)
  • Method Details

    • setTokenizerOptions

      public void setTokenizerOptions(Map<String,String> tokenizerOptions)
    • setDisableCaching

      public void setDisableCaching(boolean disableCaching)
    • setResourceCacheDirectory

      public void setResourceCacheDirectory(String resourceCacheDir)
    • 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

      public void setTokenizerResource(String tokenizerResourceUri)
    • setModelResource

      public void setModelResource(String modelResourceUri)
    • setModelOutputName

      public void setModelOutputName(String modelOutputName)
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • embed

      public List<Double> embed(String text)
      Description copied from interface: EmbeddingClient
      Embeds the given text into a vector.
      Specified by:
      embed in interface EmbeddingClient
      Parameters:
      text - the text to embed.
      Returns:
      the embedded vector.
    • embed

      public List<Double> embed(Document document)
      Description copied from interface: EmbeddingClient
      Embeds the given document's content into a vector.
      Specified by:
      embed in interface EmbeddingClient
      Parameters:
      document - the document to embed.
      Returns:
      the embedded vector.
    • embedForResponse

      public EmbeddingResponse embedForResponse(List<String> texts)
      Description copied from interface: EmbeddingClient
      Embeds a batch of texts into vectors and returns the EmbeddingResponse.
      Specified by:
      embedForResponse in interface EmbeddingClient
      Parameters:
      texts - list of texts to embed.
      Returns:
      the embedding response.
    • embed

      public List<List<Double>> embed(List<String> texts)
      Description copied from interface: EmbeddingClient
      Embeds a batch of texts into vectors.
      Specified by:
      embed in interface EmbeddingClient
      Parameters:
      texts - list of texts to embed.
      Returns:
      list of list of embedded vectors.
    • call

      public EmbeddingResponse call(EmbeddingRequest request)
      Description copied from interface: ModelClient
      Executes a method call to the AI model.
      Specified by:
      call in interface EmbeddingClient
      Specified by:
      call in interface ModelClient<EmbeddingRequest,EmbeddingResponse>
      Parameters:
      request - the request object to be sent to the AI model
      Returns:
      the response from the AI model