IBM watsonx.ai Embedding Models
IBM watsonx.ai also provides access to embedding models that can be used for vector-based similarity search, semantic retrieval, and RAG scenarios.
Prerequisites
To use watsonx.ai models, configure the following required values in your application.properties file:
Base URL
The base-url depends on the region of your service instance:
-
Frankfurt: https://eu-de.ml.cloud.ibm.com
-
London: https://eu-gb.ml.cloud.ibm.com
-
Sydney: https://au-syd.ml.cloud.ibm.com
-
Toronto: https://ca-tor.ml.cloud.ibm.com
quarkus.langchain4j.watsonx.base-url=https://us-south.ml.cloud.ibm.com
Project ID
Obtain the Project ID via:
-
Visit https://dataplatform.cloud.ibm.com/projects/?context=wx
-
Open your project and click the Manage tab.
-
Copy the Project ID from the Details section.
quarkus.langchain4j.watsonx.project-id=23d...
| You may use the optional space-id as an alternative. |
API Key
Create an API key by visiting https://cloud.ibm.com/iam/apikeys and clicking Create +.
quarkus.langchain4j.watsonx.api-key=your-api-key
You can also use the QUARKUS_LANGCHAIN4J_WATSONX_API_KEY environment variable.
|
Dependency
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-watsonx</artifactId>
<version>1.6.0.CR1</version>
</dependency>
Default Configuration
By default, embedding models are auto-detected if no other LLM extension is installed.
You can inject the embedding model like so:
@Inject
EmbeddingModel model;
To customize the model, set the following property:
quarkus.langchain4j.watsonx.embedding-model.model-name=mistralai/mistral-embed
| The same base-url, project-id, and api-key must be present to successfully authenticate with the watsonx service. |
Configuration
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
|---|---|---|
Whether the model should be enabled. Environment variable: |
boolean |
|
Whether the embedding model should be enabled. Environment variable: |
boolean |
|
Whether the scoring model should be enabled. Environment variable: |
boolean |
|
Specifies the mode of interaction with the LLM model. This property allows you to choose between two modes of operation:
Allowable values: Environment variable: |
string |
|
Specifies the base URL of the watsonx.ai API. A list of all available URLs is provided in the IBM Watsonx.ai documentation at the this link. Environment variable: |
string |
|
IBM Cloud API key. Environment variable: |
string |
|
Timeout for watsonx.ai calls. Environment variable: |
|
|
The version date for the API of the form YYYY-MM-DD. Environment variable: |
string |
|
The space that contains the resource. Either Environment variable: |
string |
|
The project that contains the resource. Either Environment variable: |
string |
|
Whether the watsonx.ai client should log requests. Environment variable: |
boolean |
|
Whether the watsonx.ai client should log responses. Environment variable: |
boolean |
|
Whether to enable the integration. Defaults to Environment variable: |
boolean |
|
Base URL of the IAM Authentication API. Environment variable: |
|
|
Timeout for IAM authentication calls. Environment variable: |
|
|
Grant type for the IAM Authentication API. Environment variable: |
string |
|
Base URL of the Cloud Object Storage API. Environment variable: |
string |
required |
The ID of the connection asset that contains the credentials required to access the data. Environment variable: |
string |
required |
The name of the bucket containing the input document. Environment variable: |
string |
required |
The ID of the connection asset used to store the extracted results. Environment variable: |
string |
required |
The name of the bucket where the output files will be written. Environment variable: |
string |
required |
Whether the Cloud Object Storage client should log requests. Environment variable: |
boolean |
|
Whether the Cloud Object Storage client should log responses. Environment variable: |
boolean |
|
Specifies the model to use for the chat completion. A list of all available models is provided in the IBM watsonx.ai documentation at the this link. To use a model, locate the Environment variable: |
string |
|
Specifies how the model should choose which tool to call during a request. This value can be:
If Setting this value influences the tool-calling behavior of the model when no specific tool is required. Environment variable: |
|
|
Specifies the name of a specific tool that the model must call. When set, the model will be forced to call the specified tool. The name must exactly match one of the available tools defined for the service. Environment variable: |
string |
|
Positive values penalize new tokens based on their existing frequency in the generated text, reducing the likelihood of the model repeating the same lines verbatim. Possible values: Environment variable: |
double |
|
Specifies whether to return the log probabilities of the output tokens. If set to Environment variable: |
boolean |
|
An integer specifying the number of most likely tokens to return at each token position, each with an associated log probability. The option Possible values: Environment variable: |
int |
|
The maximum number of tokens that can be generated in the chat completion. The total length of input tokens and generated tokens is limited by the model’s context length. Set to 0 for the model’s configured max generated tokens. Environment variable: |
int |
|
Specifies how many chat completion choices to generate for each input message. Environment variable: |
int |
|
Applies a penalty to new tokens based on whether they already appear in the generated text so far, encouraging the model to introduce new topics rather than repeat itself. Possible values: Environment variable: |
double |
|
Random number generator seed to use in sampling mode for experimental repeatability. Environment variable: |
int |
|
Defines one or more stop sequences that will cause the model to stop generating further tokens if any of them are encountered in the output. This allows control over where the model should end its response. If a stop sequence is encountered before the minimum number of tokens has been generated, it will be ignored. Possible values: Environment variable: |
list of string |
|
Specifies the sampling temperature to use in the generation process. Higher values (e.g. Possible values: Environment variable: |
double |
|
An alternative to sampling with Possible values: Environment variable: |
double |
|
Specifies the desired format for the model’s output. Allowable values: Environment variable: |
string |
|
Whether chat model requests should be logged. Environment variable: |
boolean |
|
Whether chat model responses should be logged. Environment variable: |
boolean |
|
The id of the model to be used. All available models are listed in the IBM Watsonx.ai documentation at the link: following link. To use a model, locate the Environment variable: |
string |
|
Represents the strategy used for picking the tokens during generation of the output text. During text generation when parameter value is set to Allowable values: Environment variable: |
string |
|
Represents the factor of exponential decay. Larger values correspond to more aggressive decay. Possible values: Environment variable: |
double |
|
A number of generated tokens after which this should take effect. Possible values: Environment variable: |
int |
|
The maximum number of new tokens to be generated. The maximum supported value for this field depends on the model being used. How the "token" is defined depends on the tokenizer and vocabulary size, which in turn depends on the model. Often the tokens are a mix of full words and sub-words. Depending on the users plan, and on the model being used, there may be an enforced maximum number of new tokens. Possible values: Environment variable: |
int |
|
If stop sequences are given, they are ignored until minimum tokens are generated. Possible values: Environment variable: |
int |
|
Random number generator seed to use in sampling mode for experimental repeatability. Possible values: Environment variable: |
int |
|
Stop sequences are one or more strings which will cause the text generation to stop if/when they are produced as part of the output. Stop sequences encountered prior to the minimum number of tokens being generated will be ignored. Possible values: Environment variable: |
list of string |
|
A value used to modify the next-token probabilities in Possible values: Environment variable: |
double |
|
The number of highest probability vocabulary tokens to keep for top-k-filtering. Only applies for Possible values: Environment variable: |
int |
|
Similar to Possible values: Environment variable: |
double |
|
Represents the penalty for penalizing tokens that have already been generated or belong to the context. The value Possible values: Environment variable: |
double |
|
Represents the maximum number of input tokens accepted. This can be used to avoid requests failing due to input being longer than configured limits. If the text is truncated, then it truncates the start of the input (on the left), so the end of the input will remain the same. If this value exceeds the maximum sequence length (refer to the documentation to find this value for the model) then the call will fail if the total number of tokens exceeds the maximum sequence length. Zero means don’t truncate. Possible values: Environment variable: |
int |
|
Pass Environment variable: |
boolean |
|
Whether chat model requests should be logged. Environment variable: |
boolean |
|
Whether chat model responses should be logged. Environment variable: |
boolean |
|
Delimiter used to concatenate the ChatMessage elements into a single string. By setting this property, you can define your preferred way of concatenating messages to ensure that the prompt is structured in the correct way. Environment variable: |
string |
|
Specifies the ID of the model to be used. A list of all available models is provided in the IBM watsonx.ai documentation at the this link. To use a model, locate the Environment variable: |
string |
|
Specifies the maximum number of input tokens accepted. This can be used to prevent requests from failing due to input exceeding the configured token limits. If the input exceeds the specified token limit, the input will be truncated from the end (right side), ensuring that the start of the input remains intact. If the provided value exceeds the model’s maximum sequence length (refer to the documentation for the model’s maximum sequence length), the request will fail if the total number of tokens exceeds the maximum limit. Environment variable: |
int |
|
Whether embedding model requests should be logged. Environment variable: |
boolean |
|
Whether embedding model responses should be logged. Environment variable: |
boolean |
|
The id of the model to be used. All available models are listed in the IBM Watsonx.ai documentation at the link: following link. To use a model, locate the Environment variable: |
string |
|
Specifies the maximum number of input tokens accepted. This helps to avoid requests failing due to input exceeding the configured token limits. If the input exceeds the specified token limit, the text will be truncated from the end (right side), ensuring that the start of the input remains intact. If the provided value exceeds the model’s maximum sequence length (refer to the documentation for the model’s maximum sequence length), the request will fail if the total number of tokens exceeds the maximum limit. Environment variable: |
int |
|
Whether embedding model requests should be logged. Environment variable: |
boolean |
|
Whether embedding model responses should be logged. Environment variable: |
boolean |
|
Base URL for the built-in service. All available URLs are listed in the IBM Watsonx.ai documentation at the following link. Note: If empty, the URL is automatically calculated based on the Environment variable: |
string |
|
IBM Cloud API key. If empty, the api key inherits the value from the Environment variable: |
string |
|
Timeout for built-in tools APIs. If empty, the api key inherits the value from the Environment variable: |
|
|
Whether the built-in rest client should log requests. Environment variable: |
boolean |
|
Whether the built-in rest client should log responses. Environment variable: |
boolean |
|
Maximum number of search results. Possible values: Environment variable: |
int |
|
Type |
Default |
|
Specifies the mode of interaction with the LLM model. This property allows you to choose between two modes of operation:
Allowable values: Environment variable: |
string |
|
Specifies the base URL of the watsonx.ai API. A list of all available URLs is provided in the IBM Watsonx.ai documentation at the this link. Environment variable: |
string |
|
IBM Cloud API key. Environment variable: |
string |
|
Timeout for watsonx.ai calls. Environment variable: |
|
|
The version date for the API of the form YYYY-MM-DD. Environment variable: |
string |
|
The space that contains the resource. Either Environment variable: |
string |
|
The project that contains the resource. Either Environment variable: |
string |
|
Whether the watsonx.ai client should log requests. Environment variable: |
boolean |
|
Whether the watsonx.ai client should log responses. Environment variable: |
boolean |
|
Whether to enable the integration. Defaults to Environment variable: |
boolean |
|
Base URL of the IAM Authentication API. Environment variable: |
|
|
Timeout for IAM authentication calls. Environment variable: |
|
|
Grant type for the IAM Authentication API. Environment variable: |
string |
|
Base URL of the Cloud Object Storage API. Environment variable: |
string |
required |
The ID of the connection asset that contains the credentials required to access the data. Environment variable: |
string |
required |
The name of the bucket containing the input document. Environment variable: |
string |
required |
The ID of the connection asset used to store the extracted results. Environment variable: |
string |
required |
The name of the bucket where the output files will be written. Environment variable: |
string |
required |
Whether the Cloud Object Storage client should log requests. Environment variable: |
boolean |
|
Whether the Cloud Object Storage client should log responses. Environment variable: |
boolean |
|
Specifies the model to use for the chat completion. A list of all available models is provided in the IBM watsonx.ai documentation at the this link. To use a model, locate the Environment variable: |
string |
|
Specifies how the model should choose which tool to call during a request. This value can be:
If Setting this value influences the tool-calling behavior of the model when no specific tool is required. Environment variable: |
|
|
Specifies the name of a specific tool that the model must call. When set, the model will be forced to call the specified tool. The name must exactly match one of the available tools defined for the service. Environment variable: |
string |
|
Positive values penalize new tokens based on their existing frequency in the generated text, reducing the likelihood of the model repeating the same lines verbatim. Possible values: Environment variable: |
double |
|
Specifies whether to return the log probabilities of the output tokens. If set to Environment variable: |
boolean |
|
An integer specifying the number of most likely tokens to return at each token position, each with an associated log probability. The option Possible values: Environment variable: |
int |
|
The maximum number of tokens that can be generated in the chat completion. The total length of input tokens and generated tokens is limited by the model’s context length. Set to 0 for the model’s configured max generated tokens. Environment variable: |
int |
|
Specifies how many chat completion choices to generate for each input message. Environment variable: |
int |
|
Applies a penalty to new tokens based on whether they already appear in the generated text so far, encouraging the model to introduce new topics rather than repeat itself. Possible values: Environment variable: |
double |
|
Random number generator seed to use in sampling mode for experimental repeatability. Environment variable: |
int |
|
Defines one or more stop sequences that will cause the model to stop generating further tokens if any of them are encountered in the output. This allows control over where the model should end its response. If a stop sequence is encountered before the minimum number of tokens has been generated, it will be ignored. Possible values: Environment variable: |
list of string |
|
Specifies the sampling temperature to use in the generation process. Higher values (e.g. Possible values: Environment variable: |
double |
|
An alternative to sampling with Possible values: Environment variable: |
double |
|
Specifies the desired format for the model’s output. Allowable values: Environment variable: |
string |
|
Whether chat model requests should be logged. Environment variable: |
boolean |
|
Whether chat model responses should be logged. Environment variable: |
boolean |
|
The id of the model to be used. All available models are listed in the IBM Watsonx.ai documentation at the link: following link. To use a model, locate the Environment variable: |
string |
|
Represents the strategy used for picking the tokens during generation of the output text. During text generation when parameter value is set to Allowable values: Environment variable: |
string |
|
Represents the factor of exponential decay. Larger values correspond to more aggressive decay. Possible values: Environment variable: |
double |
|
A number of generated tokens after which this should take effect. Possible values: Environment variable: |
int |
|
The maximum number of new tokens to be generated. The maximum supported value for this field depends on the model being used. How the "token" is defined depends on the tokenizer and vocabulary size, which in turn depends on the model. Often the tokens are a mix of full words and sub-words. Depending on the users plan, and on the model being used, there may be an enforced maximum number of new tokens. Possible values: Environment variable: |
int |
|
If stop sequences are given, they are ignored until minimum tokens are generated. Possible values: Environment variable: |
int |
|
Random number generator seed to use in sampling mode for experimental repeatability. Possible values: Environment variable: |
int |
|
Stop sequences are one or more strings which will cause the text generation to stop if/when they are produced as part of the output. Stop sequences encountered prior to the minimum number of tokens being generated will be ignored. Possible values: Environment variable: |
list of string |
|
A value used to modify the next-token probabilities in Possible values: Environment variable: |
double |
|
The number of highest probability vocabulary tokens to keep for top-k-filtering. Only applies for Possible values: Environment variable: |
int |
|
Similar to Possible values: Environment variable: |
double |
|
Represents the penalty for penalizing tokens that have already been generated or belong to the context. The value Possible values: Environment variable: |
double |
|
Represents the maximum number of input tokens accepted. This can be used to avoid requests failing due to input being longer than configured limits. If the text is truncated, then it truncates the start of the input (on the left), so the end of the input will remain the same. If this value exceeds the maximum sequence length (refer to the documentation to find this value for the model) then the call will fail if the total number of tokens exceeds the maximum sequence length. Zero means don’t truncate. Possible values: Environment variable: |
int |
|
Pass Environment variable: |
boolean |
|
Whether chat model requests should be logged. Environment variable: |
boolean |
|
Whether chat model responses should be logged. Environment variable: |
boolean |
|
Delimiter used to concatenate the ChatMessage elements into a single string. By setting this property, you can define your preferred way of concatenating messages to ensure that the prompt is structured in the correct way. Environment variable: |
string |
|
Specifies the ID of the model to be used. A list of all available models is provided in the IBM watsonx.ai documentation at the this link. To use a model, locate the Environment variable: |
string |
|
Specifies the maximum number of input tokens accepted. This can be used to prevent requests from failing due to input exceeding the configured token limits. If the input exceeds the specified token limit, the input will be truncated from the end (right side), ensuring that the start of the input remains intact. If the provided value exceeds the model’s maximum sequence length (refer to the documentation for the model’s maximum sequence length), the request will fail if the total number of tokens exceeds the maximum limit. Environment variable: |
int |
|
Whether embedding model requests should be logged. Environment variable: |
boolean |
|
Whether embedding model responses should be logged. Environment variable: |
boolean |
|
The id of the model to be used. All available models are listed in the IBM Watsonx.ai documentation at the link: following link. To use a model, locate the Environment variable: |
string |
|
Specifies the maximum number of input tokens accepted. This helps to avoid requests failing due to input exceeding the configured token limits. If the input exceeds the specified token limit, the text will be truncated from the end (right side), ensuring that the start of the input remains intact. If the provided value exceeds the model’s maximum sequence length (refer to the documentation for the model’s maximum sequence length), the request will fail if the total number of tokens exceeds the maximum limit. Environment variable: |
int |
|
Whether embedding model requests should be logged. Environment variable: |
boolean |
|
Whether embedding model responses should be logged. Environment variable: |
boolean |
|
|
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|
| IBM watsonx.ai also provides a scoring model interface (used for reranking tasks). This feature is documented separately in the RAG and reranking section. |