Connecting to Milvus Service on IBM watsonx: A Comprehensive Guide

Divya
Milvus Meets Watsonx
3 min read6 days ago

This blogs explains the steps one needs to follow to connect to Milvus on IBM watsonx.

Introduction:

Vector databases like Milvus play a crucial role in modern AI applications. They excel at tasks such as similarity searches and powering recommendation systems, handling complex data structures with ease. By connecting to Milvus, you’re unlocking powerful capabilities for your AI and machine learning projects.

In this guide, we’ll explore the steps to connect to Milvus on IBM watsonx, whether you’re using the cloud-based solution or an on-premises setup. We’ll break down the process into clear, manageable steps, ensuring you can establish your connection regardless of your preferred deployment method.

Let’s begin by looking at the different connection methods and what you’ll need to get started.

Prerequisite to connect to a Milvus instance in watsonx.data

Use the watsonx.data console to provision a Milvus instance in watsonx.data:

Connecting to Milvus on IBM Cloud

Before connecting to the Milvus service on IBM Cloud, ensure you have the following:

  • A client side SDK: Milvus supports SDKs for Java, Go, Python (PyMilvus), and Node.js. For this blog post, we are using PyMilvus, which is the most popular among them. Install the PyMilvus package to interact with the Milvus service. For more information, see About PyMilvus.
  • Hostname and Port: Obtain the Milvus instance’s hostname and port from the Infrastructure Manager.
  • Authorized User Credentials: Ensure you have the necessary credentials to access the Milvus instance.

For the cloud-based solution, you have two options to connect to Milvus:

a) Using API Key:

For generating API key , complete the following steps:

  1. In the IBM Cloud console, go to Manage > Access (IAM) > API keys.
  2. Click Create an IBM Cloud API key.
  3. Enter a name and description for your API key.
  4. Click Create.
  5. Then, click Show to display the API key. Or, click Copy to copy and save it for later, or click Download.
from pymilvus import connections
import fmt
print(fmt.format("start connecting to Milvus"))
connections.connect(
host="<host>",
port="<port>",
secure=True,
server_name="localhost",
user="ibmlhapikey",
password="<api-key>"
)
has = utility.has_collection("hello_milvus")
print(f"Does collection hello_milvus exist in Milvus: {has}")

b) Using URI:

print(fmt.format("start connecting to Milvus"))
connections.connect(
alias="default",
uri="https://<host>:<grpc-port>",
user="ibmlhapikey",
password="<api-key>"
)
has = utility.has_collection("hello_milvus")
print(f"Does collection hello_milvus exist in Milvus: {has}")

Connecting to watsonx.data on Cloud Pak for Data (on-prem):

Before connecting to the Milvus service on Cloud Pak for Data (CPD) on-premises:

  • A client side SDK: Milvus supports SDKs for Java, Go, Python (PyMilvus), and Node.js. For this blog post, we are using PyMilvus. Install the PyMilvus package to interact with the Milvus service. Ensure you have the PyMilvus package installed.
  • Hostname and Port: Obtain the hostname and port for the Milvus server from the web console.
  • Certificates: Acquire the self-signed certificate from the Milvus server.
  • Authorized User Credentials: Ensure you have valid credentials to access the Milvus server.

For the on-premises solution, follow these steps:

Step 1: Provision Milvus Service First, provision a Milvus service in watsonx.data through the web console.

Step 2: Obtain Self-Signed Certificate Run the following command from the terminal of the client machine where PyMilvus SDK is installed:

echo QUIT | openssl s_client -showcerts -connect <milvus-service-host>:443 | awk '/-----BEGIN CERTIFICATE-----/ {p=1}; p; /-----END CERTIFICATE-----/ {p=0}' > milvus_grpc.cert

Step 3: Connect Using Python SDK (PyMilvus) Use the following Python code to connect to Milvus:

from pymilvus import connections
connections.connect(
alias='default',
secure=True,
server_pem_path="<path/to/grpc_certificate>",
server_name="<grpc_route>",
host='<grpc_route>',
port='443',
user='<CPD_username>',
password='<CPD_password>'
)

Conclusion:

Connecting to Milvus service on IBM watsonx, whether on the cloud or on-premises, involves a few key steps. By following this guide, you should be able to establish a connection and start leveraging the power of Milvus for your vector database needs. Remember to keep your credentials secure and follow best practices for managing your connections.

For the most up-to-date information, always refer to the official IBM documentation, as connection methods and requirements may evolve over time.

--

--