Class OnnxEmbeddingModel

java.lang.Object
dev.langchain4j.model.embedding.DimensionAwareEmbeddingModel
dev.langchain4j.model.embedding.onnx.AbstractInProcessEmbeddingModel
dev.langchain4j.model.embedding.onnx.OnnxEmbeddingModel
All Implemented Interfaces:
dev.langchain4j.model.embedding.EmbeddingModel

public class OnnxEmbeddingModel extends AbstractInProcessEmbeddingModel
An embedding model that runs within your Java application's process using ONNX runtime.
Many models (e.g., from HuggingFace) can be used, as long as they are in the ONNX format.
Information on how to convert models into ONNX format can be found here.
Many models already converted to ONNX format are available here.
  • Constructor Details

    • OnnxEmbeddingModel

      public OnnxEmbeddingModel(Path pathToModel, Path pathToTokenizer, PoolingMode poolingMode)
      Parameters:
      pathToModel - The path to the modelPath file (e.g., "/path/to/model.onnx")
      pathToTokenizer - The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
      poolingMode - The pooling model to use. Can be found in the ".../1_Pooling/config.json" file on HuggingFace. Here is an example. "pooling_mode_mean_tokens": true means that PoolingMode.MEAN should be used.
    • OnnxEmbeddingModel

      public OnnxEmbeddingModel(Path pathToModel, Path pathToTokenizer, PoolingMode poolingMode, Executor executor)
      Parameters:
      pathToModel - The path to the modelPath file (e.g., "/path/to/model.onnx")
      pathToTokenizer - The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
      poolingMode - The pooling model to use. Can be found in the ".../1_Pooling/config.json" file on HuggingFace. Here is an example. "pooling_mode_mean_tokens": true means that PoolingMode.MEAN should be used.
      executor - The executor to use to parallelize the embedding process.
    • OnnxEmbeddingModel

      public OnnxEmbeddingModel(String pathToModel, String pathToTokenizer, PoolingMode poolingMode)
      Parameters:
      pathToModel - The path to the model file (e.g., "/home/me/model.onnx")
      pathToTokenizer - The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
      poolingMode - The pooling model to use. Can be found in the ".../1_Pooling/config.json" file on HuggingFace. Here is an example. "pooling_mode_mean_tokens": true means that PoolingMode.MEAN should be used.
    • OnnxEmbeddingModel

      public OnnxEmbeddingModel(String pathToModel, String pathToTokenizer, PoolingMode poolingMode, Executor executor)
      Parameters:
      pathToModel - The path to the model file (e.g., "/home/me/model.onnx")
      pathToTokenizer - The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
      poolingMode - The pooling model to use. Can be found in the ".../1_Pooling/config.json" file on HuggingFace. Here is an example. "pooling_mode_mean_tokens": true means that PoolingMode.MEAN should be used.
      executor - The executor to use to parallelize the embedding process.
  • Method Details