[FEATURE] Support per-call embedding parameters in OpenAiOfficialEmbeddingModel
Is your feature request related to a problem? Please describe.
OpenAiOfficialEmbeddingModel does not implement the EmbeddingModel request/response API, so nothing can be
varied per call. modelName, dimensions and user are fixed on the builder, and encoding_format cannot be
chosen at all.
supportedParameters() is not overridden, so it returns the empty default and any per-call parameter is
rejected:
dev.langchain4j.exception.UnsupportedFeatureException: EmbeddingModel
'dev.langchain4j.model.openaiofficial.OpenAiOfficialEmbeddingModel' does not support the following per-call
parameter(s): dimensions. Only the following are supported:Embedding queries at one dimension and documents at another therefore needs two model instances, each with its own client.
Describe the solution you'd like
Implement supportedParameters(), defaultRequestParameters() and doEmbed(EmbeddingRequest), and add an
OpenAiOfficialEmbeddingRequestParameters carrying the provider-specific user, encoding_format and
custom parameters, so the builder values become defaults and a request can override them for one call:
model.embed(EmbeddingRequest.builder()
.input("hello")
.parameters(OpenAiOfficialEmbeddingRequestParameters.builder()
.dimensions(256)
.user("user-1")
.build())
.build());OpenAiEmbeddingModel in langchain4j-open-ai already works this way through
OpenAiEmbeddingRequestParameters, so the same shape applies here.
Describe alternatives you've considered
Building one model instance per configuration, which is what is needed today. It duplicates the client and the
connection settings for what is a single field on the request, and it does not help with encoding_format,
which has no builder option either.
Additional context
Source: langchain4j/langchain4j