Interface EmbeddingModel
- All Known Implementing Classes:
AbstractInProcessEmbeddingModel, AllMiniLmL6V2EmbeddingModel, AllMiniLmL6V2QuantizedEmbeddingModel, AzureOpenAiEmbeddingModel, BedrockCohereEmbeddingModel, BedrockTitanEmbeddingModel, BgeSmallEnEmbeddingModel, BgeSmallEnQuantizedEmbeddingModel, BgeSmallEnV15EmbeddingModel, BgeSmallEnV15QuantizedEmbeddingModel, BgeSmallZhV15EmbeddingModel, BgeSmallZhV15QuantizedEmbeddingModel, CohereEmbeddingModel, DimensionAwareEmbeddingModel, DisabledEmbeddingModel, E5SmallV2EmbeddingModel, E5SmallV2QuantizedEmbeddingModel, GitHubModelsEmbeddingModel, GoogleAiEmbeddingModel, GoogleGenAiEmbeddingModel, HuggingFaceEmbeddingModel, JinaEmbeddingModel, JlamaEmbeddingModel, LocalAiEmbeddingModel, MistralAiEmbeddingModel, NomicEmbeddingModel, OllamaEmbeddingModel, OnnxEmbeddingModel, OpenAiEmbeddingModel, OpenAiOfficialEmbeddingModel, OracleEmbeddingModel, OvhAiEmbeddingModel, VertexAiEmbeddingModel, VoyageAiEmbeddingModel, WatsonxEmbeddingModel, WorkersAiEmbeddingModel
-
Method Summary
Modifier and TypeMethodDescriptiondefault EmbeddingModeladdListener(EmbeddingModelListener listener) Returns anEmbeddingModelthat wraps this one and notifies the given listener around each embedding call.default EmbeddingModeladdListeners(List<EmbeddingModelListener> listeners) Returns anEmbeddingModelthat wraps this one and notifies the given listeners (in iteration order) around each embedding call.default EmbeddingRequestParametersThe parameters applied to every request unless overridden by the request itself, typically derived from the model's builder-time configuration.default intReturns the dimension of theEmbeddingproduced by this embedding model.default EmbeddingResponsedoEmbed(EmbeddingRequest request) Performs the embedding forembed(EmbeddingRequest).embed(TextSegment textSegment) Embed the text content of aTextSegment.default EmbeddingResponseembed(EmbeddingRequest request) Embeds the inputs of the givenEmbeddingRequestand returns the resulting embeddings.Embed a text.embedAll(List<TextSegment> textSegments) Embeds the text content of a list ofTextSegments.default List<EmbeddingModelListener> TheEmbeddingModelListeners that are notified aroundembed(EmbeddingRequest).default StringReturns the name of the underlying embedding model.default ModelProviderprovider()TheModelProviderof this embedding model (for exampleModelProvider.OPEN_AI).default Set<ContentType> The inputcontent typesthis model can embed.default Set<EmbeddingParameter<?>> The per-callparametersthis model honors.
-
Method Details
-
embed
Embeds the inputs of the givenEmbeddingRequestand returns the resulting embeddings.An
EmbeddingRequestcarries one or more inputs to embed, together with optional per-callparameterssuch asdimensionsor aninput type. A model only honors the parameters listed insupportedParameters()and the content types listed insupportedContentTypes(); a request that uses anything else is rejected with anUnsupportedFeatureExceptionrather than being silently ignored.- Parameters:
request- the inputs to embed and the per-call parameters.- Returns:
- the embeddings and the response metadata.
- Since:
- 1.18.0
-
listeners
TheEmbeddingModelListeners that are notified aroundembed(EmbeddingRequest). Configure them on the model's builder (vialisteners(...)). Defaults to an empty list.- Since:
- 1.18.0
-
provider
TheModelProviderof this embedding model (for exampleModelProvider.OPEN_AI). It is made available tolistenersthrough the request, response and error contexts. Defaults toModelProvider.OTHER.- Since:
- 1.18.0
-
doEmbed
Performs the embedding forembed(EmbeddingRequest). This is the low-level method a provider overrides to build the actual API call;embed(EmbeddingRequest)handles per-call parameter validation andlistenerdispatch around it.An implementation must override either this method (preferred) or
embedAll(List)— the two have mutually-recursive defaults, so overriding neither leads to infinite recursion. The default implementation embeds the text of each input viaembedAll(List), which keeps implementations that only provideembedAll(List)working.When this method is called, the request's parameters have already been merged with
defaultRequestParameters()and validated againstsupportedParameters()andsupportedContentTypes().- Parameters:
request- the request, with parameters already merged and validated.- Returns:
- the response.
- Since:
- 1.18.0
-
defaultRequestParameters
The parameters applied to every request unless overridden by the request itself, typically derived from the model's builder-time configuration. The default isEmbeddingRequestParameters.EMPTY.- Since:
- 1.18.0
-
supportedParameters
The per-callparametersthis model honors. A request that populates a parameter outside this set is rejected byembed(EmbeddingRequest)with anUnsupportedFeatureException, so a parameter a model cannot apply is never silently ignored. Defaults to an empty set (the model accepts no per-call parameters).- Since:
- 1.18.0
-
supportedContentTypes
The inputcontent typesthis model can embed. A request whose inputs use a content type outside this set is rejected byembed(EmbeddingRequest)with anUnsupportedFeatureException. Defaults to{TEXT}; a multimodal model overrides this to also accept, for example,images.- Since:
- 1.18.0
-
embed
-
embed
Embed the text content of aTextSegment.This is a convenience method over
embed(EmbeddingRequest), solistenersare notified and the model's default per-call parameters are applied here too.- Parameters:
textSegment- the text segment to embed.- Returns:
- the embedding.
-
embedAll
Embeds the text content of a list ofTextSegments.This is a convenience method over
embed(EmbeddingRequest), solistenersare notified and the model's default per-call parameters are applied here too. A provider implements its embedding logic by overridingdoEmbed(EmbeddingRequest)(preferred); it may still override this method for batch-specific behavior that the request/response API does not carry (for example applying a document title fromTextSegmentmetadata).- Parameters:
textSegments- the text segments to embed.- Returns:
- the embeddings.
-
dimension
default int dimension()Returns the dimension of theEmbeddingproduced by this embedding model.- Returns:
- dimension of the embedding
-
modelName
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.- Returns:
- the model name or a fallback value if not provided
-
addListener
Returns anEmbeddingModelthat wraps this one and notifies the given listener around each embedding call. Listeners can also be configured directly on a model's builder vialisteners(...)(seelisteners()), which does not require wrapping.- Parameters:
listener- The listener to add.- Returns:
- An
EmbeddingModelthat notifies the given listener. - Since:
- 1.11.0
- See Also:
-
addListeners
Returns anEmbeddingModelthat wraps this one and notifies the given listeners (in iteration order) around each embedding call. Listeners can also be configured directly on a model's builder vialisteners(...)(seelisteners()).- Parameters:
listeners- The listeners to add.- Returns:
- An
EmbeddingModelthat notifies the given listeners. - Since:
- 1.11.0
- See Also:
-