
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
llama-index-embeddings-ibm
Advanced tools
This package integrates the LlamaIndex LLMs API with the IBM watsonx.ai Foundation Models API by leveraging ibm-watsonx-ai
SDK. With this integration, you can use one of the embedding models that are available in IBM watsonx.ai to embed a single string or a list of strings.
pip install llama-index-embeddings-ibm
To use IBM's models, you must have an IBM Cloud user API key. Here's how to obtain and set up your API key:
import os
from getpass import getpass
watsonx_api_key = getpass()
os.environ["WATSONX_APIKEY"] = watsonx_api_key
Alternatively, you can set the environment variable in your terminal.
Linux/macOS: Open your terminal and execute the following command:
export WATSONX_APIKEY='your_ibm_api_key'
To make this environment variable persistent across terminal sessions, add the above line to your ~/.bashrc
, ~/.bash_profile
, or ~/.zshrc
file.
Windows: For Command Prompt, use:
set WATSONX_APIKEY=your_ibm_api_key
You might need to adjust embedding parameters for different tasks.
truncate_input_tokens = 3
Initialize the WatsonxEmbeddings
class with the previously set parameters.
Note:
project_id
or space_id
. To get your project or space ID, open your project or space, go to the Manage tab, and click General. For more information see: Project documentation or Deployment space documentation.In this example, we’ll use the project_id
and Dallas URL.
You need to specify the model_id
that will be used for inferencing.
from llama_index.embeddings.ibm import WatsonxEmbeddings
watsonx_embedding = WatsonxEmbeddings(
model_id="ibm/slate-125m-english-rtrvr",
url="https://us-south.ml.cloud.ibm.com",
project_id="PASTE YOUR PROJECT_ID HERE",
truncate_input_tokens=truncate_input_tokens,
)
Alternatively, you can use Cloud Pak for Data credentials. For details, see watsonx.ai software setup.
watsonx_embedding = WatsonxEmbeddings(
model_id="ibm/slate-125m-english-rtrvr",
url="PASTE YOUR URL HERE",
username="PASTE YOUR USERNAME HERE",
password="PASTE YOUR PASSWORD HERE",
instance_id="openshift",
version="4.8",
project_id="PASTE YOUR PROJECT_ID HERE",
truncate_input_tokens=truncate_input_tokens,
)
query = "Example query."
query_result = watsonx_embedding.get_query_embedding(query)
print(query_result[:5])
texts = ["This is a content of one document", "This is another document"]
doc_result = watsonx_embedding.get_text_embedding_batch(texts)
print(doc_result[0][:5])
FAQs
llama-index embeddings IBM watsonx.ai integration
We found that llama-index-embeddings-ibm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.