Class EmbeddingModelSupplier

java.lang.Object
com.oracle.coherence.rag.model.AbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
com.oracle.coherence.rag.model.EmbeddingModelSupplier
All Implemented Interfaces:
Supplier<dev.langchain4j.model.embedding.EmbeddingModel>

@ApplicationScoped public class EmbeddingModelSupplier extends AbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
CDI supplier for embedding models in the Coherence RAG framework.

This supplier extends AbstractModelSupplier to provide embedding model instances for converting text into vector representations. It supports both remote AI service providers and local ONNX-based models, with intelligent fallback strategies for maximum flexibility.

The supplier provides the following model resolution strategies:

  • Local ONNX models: Using the "-" provider prefix (e.g., "-/all-MiniLM-L6-v2")
  • Remote providers: Through ModelProvider implementations (OpenAI, OCI, etc.)
  • Fallback to local ONNX: If a provider is not found, attempts local ONNX model

This design enables seamless switching between cloud-based and edge-based embedding generation, supporting both connected and offline deployment scenarios.

Configuration:

  • Default model: "-/all-MiniLM-L6-v2"
  • Configuration property: model.embedding
  • Supports runtime configuration changes

Usage examples:

 // Get default embedding model (local ONNX)
 EmbeddingModel model = embeddingModelSupplier.get();
 
 // Get specific remote provider model
 EmbeddingModel openAiModel = embeddingModelSupplier.get("openai/text-embedding-ada-002");
 
 // Get specific local ONNX model
 EmbeddingModel localModel = embeddingModelSupplier.get("-/sentence-transformers/all-MiniLM-L6-v2");
 

Since:
25.09
Author:
Aleks Seovic 2025.07.04
  • Field Details

    • DEFAULT_EMBEDDING_MODEL

      public static final String DEFAULT_EMBEDDING_MODEL
      The default embedding model used when no specific model is configured.

      This uses a local ONNX model that provides good quality embeddings without requiring external API calls, making it suitable for development and edge deployment scenarios.

      See Also:
  • Constructor Details

    • EmbeddingModelSupplier

      public EmbeddingModelSupplier()
  • Method Details

    • description

      protected String description()
      Returns a human-readable description of the model type.

      This description is used in logging and error messages to identify the type of models this supplier manages.

      Specified by:
      description in class AbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
      Returns:
      "embedding" identifying this as an embedding model supplier
    • defaultModel

      protected String defaultModel()
      Returns the default model name when no configuration is provided.

      This method provides the fallback embedding model that will be used when no explicit configuration is available.

      Specified by:
      defaultModel in class AbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
      Returns:
      the default embedding model name
    • configProperty

      protected String configProperty()
      Returns the configuration property key for embedding models.

      This property can be used to configure the default embedding model at runtime through various configuration sources.

      Specified by:
      configProperty in class AbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
      Returns:
      "model.embedding" as the configuration property key
    • create

      public dev.langchain4j.model.embedding.EmbeddingModel create(ModelName modelName)
      Creates a new embedding model instance for the specified model name.

      This method implements intelligent model resolution with the following strategy:

      1. If provider is "-", create a local ONNX model using the default factory
      2. Otherwise, look up the named ModelProvider for the provider
      3. If provider is found, delegate creation to the provider
      4. If provider is not found, fall back to local ONNX model creation

      This fallback strategy ensures that embedding models are always available, even when specific providers are not configured or accessible.

      Specified by:
      create in class AbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
      Parameters:
      modelName - the name of the embedding model to create
      Returns:
      a new EmbeddingModel instance