Class WatsonxGatewayEmbeddingModel
- All Implemented Interfaces:
EmbeddingModel
EmbeddingModel implementation that integrates the IBM watsonx.ai Model Gateway with LangChain4j.
Example usage:
EmbeddingModel embeddingModel = WatsonxGatewayEmbeddingModel.builder()
.baseUrl("https://...") // or use CloudRegion
.apiKey("...")
.modelName("text-embedding-3-small")
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for constructingWatsonxGatewayEmbeddingModelinstances with configurable parameters. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Returns a newWatsonxGatewayEmbeddingModel.Builderinstance.The parameters applied to every request unless overridden by the request itself, typically derived from the model's builder-time configuration.doEmbed(EmbeddingRequest request) Performs the embedding forEmbeddingModel.embed(EmbeddingRequest).embedAll(List<TextSegment> textSegments, com.ibm.watsonx.ai.gateway.embedding.ModelGatewayEmbeddingParameters parameters) Embeds the text content of a list of TextSegment using the specifiedModelGatewayEmbeddingParameters.TheEmbeddingModelListeners that are notified aroundEmbeddingModel.embed(EmbeddingRequest).Returns the name of the underlying embedding model.provider()TheModelProviderof this embedding model (for exampleModelProvider.OPEN_AI).The per-callparametersthis model honors.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EmbeddingModel
addListener, addListeners, dimension, doEmbedAsync, embed, embed, embed, embedAll, embedAsync, supportedContentTypes
-
Method Details
-
listeners
Description copied from interface:EmbeddingModelTheEmbeddingModelListeners that are notified aroundEmbeddingModel.embed(EmbeddingRequest). Configure them on the model's builder (vialisteners(...)). Defaults to an empty list.- Specified by:
listenersin interfaceEmbeddingModel
-
provider
Description copied from interface:EmbeddingModelTheModelProviderof this embedding model (for exampleModelProvider.OPEN_AI). It is made available tolistenersthrough the request, response and error contexts. Defaults toModelProvider.OTHER.- Specified by:
providerin interfaceEmbeddingModel
-
modelName
Description copied from interface:EmbeddingModelReturns 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:
modelNamein interfaceEmbeddingModel- Returns:
- the model name or a fallback value if not provided
-
defaultRequestParameters
Description copied from interface:EmbeddingModelThe parameters applied to every request unless overridden by the request itself, typically derived from the model's builder-time configuration. The default isEmbeddingRequestParameters.EMPTY.- Specified by:
defaultRequestParametersin interfaceEmbeddingModel
-
supportedParameters
Description copied from interface:EmbeddingModelThe per-callparametersthis model honors. A request that populates a parameter outside this set is rejected byEmbeddingModel.embed(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).- Specified by:
supportedParametersin interfaceEmbeddingModel
-
doEmbed
Description copied from interface:EmbeddingModelPerforms the embedding forEmbeddingModel.embed(EmbeddingRequest). This is the low-level method a provider overrides to build the actual API call;EmbeddingModel.embed(EmbeddingRequest)handles per-call parameter validation andlistenerdispatch around it.An implementation must override either this method (preferred) or
EmbeddingModel.embedAll(List)— the two have mutually-recursive defaults, so overriding neither leads to infinite recursion. The default implementation embeds the text of each input viaEmbeddingModel.embedAll(List), which keeps implementations that only provideEmbeddingModel.embedAll(List)working.When this method is called, the request's parameters have already been merged with
EmbeddingModel.defaultRequestParameters()and validated againstEmbeddingModel.supportedParameters()andEmbeddingModel.supportedContentTypes().- Specified by:
doEmbedin interfaceEmbeddingModel- Parameters:
request- the request, with parameters already merged and validated.- Returns:
- the response.
-
embedAll
public Response<List<Embedding>> embedAll(List<TextSegment> textSegments, com.ibm.watsonx.ai.gateway.embedding.ModelGatewayEmbeddingParameters parameters) Embeds the text content of a list of TextSegment using the specifiedModelGatewayEmbeddingParameters.The given parameters replace the ones set on the builder, they are not merged with them.
The registered
EmbeddingModelListeners are notified around the call, as they are for every other embedding method.- Parameters:
textSegments- the text segments to embed.parameters- the embedding parameters to use, ornullto use the ones set on the builder.- Returns:
- the embeddings.
-
builder
Returns a newWatsonxGatewayEmbeddingModel.Builderinstance.Example usage:
EmbeddingModel embeddingModel = WatsonxGatewayEmbeddingModel.builder() .baseUrl("https://...") // or use CloudRegion .apiKey("...") .modelName("text-embedding-3-small") .build();- Returns:
WatsonxGatewayEmbeddingModel.Builderinstance.
-