Class OpenAiSpringEmbeddingModel

java.lang.Object
com.sap.ai.sdk.foundationmodels.openai.spring.OpenAiSpringEmbeddingModel
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 OpenAiSpringEmbeddingModel extends Object implements org.springframework.ai.embedding.EmbeddingModel
SpringAI integration with OpenAiClient to generate embeddings.

This model transforms an EmbeddingRequest into an Azure OpenAI request, processes the response, and returns a Spring AI EmbeddingResponse.

Since:
1.5.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an OpenAiSpringEmbeddingModel with the specified OpenAiClient of some model.
    OpenAiSpringEmbeddingModel(OpenAiClient client, org.springframework.ai.document.MetadataMode metadataMode)
    Constructs an OpenAiSpringEmbeddingModel with the specified OpenAiClient of some model and metadata mode.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.ai.embedding.EmbeddingResponse
    call(org.springframework.ai.embedding.EmbeddingRequest request)
    float[]
    embed(org.springframework.ai.document.Document document)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.ai.embedding.EmbeddingModel

    dimensions, embed, embed, embed, embedForResponse, getEmbeddingContent
  • Constructor Details

    • OpenAiSpringEmbeddingModel

      public OpenAiSpringEmbeddingModel(@Nonnull OpenAiClient client)
      Constructs an OpenAiSpringEmbeddingModel with the specified OpenAiClient of some model.
      Parameters:
      client - the OpenAI client
    • OpenAiSpringEmbeddingModel

      public OpenAiSpringEmbeddingModel(@Nonnull OpenAiClient client, @Nonnull org.springframework.ai.document.MetadataMode metadataMode)
      Constructs an OpenAiSpringEmbeddingModel with the specified OpenAiClient of some model and metadata mode.

      The metadata mode is used by content formatter to determine which metadata to include in the resulting content. Currently, the formatter is only effective for calls to embed(Document).

      Parameters:
      client - the OpenAI client
      metadataMode - the metadata mode
  • Method Details

    • call

      @Nonnull public org.springframework.ai.embedding.EmbeddingResponse call(@Nonnull org.springframework.ai.embedding.EmbeddingRequest request) throws IllegalArgumentException
      Specified by:
      call in interface org.springframework.ai.embedding.EmbeddingModel
      Specified by:
      call in interface org.springframework.ai.model.Model<org.springframework.ai.embedding.EmbeddingRequest,org.springframework.ai.embedding.EmbeddingResponse>
      Throws:
      IllegalArgumentException - if request.getOptions().getModel() is not null.
    • embed

      @Nonnull public float[] embed(@Nonnull org.springframework.ai.document.Document document) throws UnsupportedOperationException
      Specified by:
      embed in interface org.springframework.ai.embedding.EmbeddingModel
      Throws:
      UnsupportedOperationException