Class EmbeddingModelSupplier
- All Implemented Interfaces:
Supplier<dev.langchain4j.model.embedding.EmbeddingModel>
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default embedding model used when no specific model is configured.Fields inherited from class com.oracle.coherence.rag.model.AbstractModelSupplier
coherenceConfig, config
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
Returns the configuration property key for embedding models.dev.langchain4j.model.embedding.EmbeddingModel
Creates a new embedding model instance for the specified model name.protected String
Returns the default model name when no configuration is provided.protected String
Returns a human-readable description of the model type.Methods inherited from class com.oracle.coherence.rag.model.AbstractModelSupplier
defaultModelName, get, get, get
-
Field Details
-
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
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 classAbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
- Returns:
- "embedding" identifying this as an embedding model supplier
-
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 classAbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
- Returns:
- the default embedding model name
-
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 classAbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
- Returns:
- "model.embedding" as the configuration property key
-
create
Creates a new embedding model instance for the specified model name.This method implements intelligent model resolution with the following strategy:
- If provider is "-", create a local ONNX model using the default factory
- Otherwise, look up the named
ModelProvider
for the provider - If provider is found, delegate creation to the provider
- 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 classAbstractModelSupplier<dev.langchain4j.model.embedding.EmbeddingModel>
- Parameters:
modelName
- the name of the embedding model to create- Returns:
- a new EmbeddingModel instance
-