Class WatsonxEmbeddingModel

java.lang.Object
dev.langchain4j.model.watsonx.WatsonxEmbeddingModel
All Implemented Interfaces:
EmbeddingModel

public class WatsonxEmbeddingModel extends Object implements EmbeddingModel
A EmbeddingModel implementation that integrates IBM watsonx.ai with LangChain4j.

Example usage:

EmbeddingModel embeddingModel = WatsonxEmbeddingModel.builder()
    .baseUrl("https://...") // or use CloudRegion
    .apiKey("...")
    .projectId("...")
    .modelName("ibm/granite-embedding-278m-multilingual")
    .build();
  • Method Details

    • embedAll

      public Response<List<Embedding>> embedAll(List<TextSegment> textSegments)
      Description copied from interface: EmbeddingModel
      Embeds the text content of a list of TextSegments.
      Specified by:
      embedAll in interface EmbeddingModel
      Parameters:
      textSegments - the text segments to embed.
      Returns:
      the embeddings.
    • modelName

      public String modelName()
      Description copied from interface: EmbeddingModel
      Returns the name of the underlying embedding model.

      Implementations are encouraged to override this method and provide the actual model name. The default implementation returns "unknown", which indicates that the model name is unknown.

      Specified by:
      modelName in interface EmbeddingModel
      Returns:
      the model name or a fallback value if not provided
    • embedAll

      public Response<List<Embedding>> embedAll(List<TextSegment> textSegments, com.ibm.watsonx.ai.embedding.EmbeddingParameters parameters)
      Embeds the text content of a list of TextSegment using the specified EmbeddingParameters.
      Parameters:
      textSegments - the text segments to embed.
      parameters - the embedding parameters to use.
      Returns:
      the embeddings.
    • builder

      public static WatsonxEmbeddingModel.Builder builder()
      Returns a new WatsonxEmbeddingModel.Builder instance.

      Example usage:

      EmbeddingModel embeddingModel = WatsonxEmbeddingModel.builder()
          .baseUrl("https://...") // or use CloudRegion
          .apiKey("...")
          .projectId("...")
          .modelName("ibm/granite-embedding-278m-multilingual")
          .build();
      
      Returns:
      WatsonxEmbeddingModel.Builder instance.