Connect to Cluster
This article offers a systematic guide on connecting to a cluster.
Before you start
Ensure the following prerequisites are met before proceeding:
-
You have registered an account with Zilliz Cloud. For details, see Register with Zilliz Cloud.
-
You have created a cluster. For details, see Create Cluster.
-
You have installed a Milvus SDK applicable to your use case. For details, see Install SDKs.
For those leaning towards the utilization of RESTful APIs over SDKs, it's important to understand that a continuous connection cannot be established. This is attributed to the HTTP protocol's unidirectional communication mode.
Connect to a cluster
Once your cluster is operational, connect to it utilizing its public endpoint and an authentication token.
-
Cluster public endpoint: You can obtain this on the Zilliz Cloud web console. Navigate to the Cluster Details page of the target cluster. On the Connect card, you can copy the cluster public endpoint.
-
Token: This token can be an API key or a cluster credential that consists of a username and password pair.
The following example shows how to connect to a cluster.
- Python
- Java
- NodeJS
# Connect using a MilvusClient object
from pymilvus import MilvusClient
CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT" # Set your cluster endpoint
TOKEN="YOUR_CLUSTER_TOKEN" # Set your token
# Initialize a MilvusClient instance
# Replace uri and token with your own
client = MilvusClient(
uri=CLUSTER_ENDPOINT, # Cluster endpoint obtained from the console
token=TOKEN # API key or a colon-separated cluster username and password
)
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.client.ConnectConfig;
String CLUSTER_ENDPOINT = "YOUR_CLUSTER_ENDPOINT";
String TOKEN = "YOUR_CLUSTER_TOKEN";
// 1. Connect to Milvus server
ConnectConfig connectConfig = ConnectConfig.builder()
.uri(CLUSTER_ENDPOINT)
.token(TOKEN)
.build();
MilvusClientV2 client = new MilvusClientV2(connectConfig);
const { MilvusClient, DataType, sleep } = require("@zilliz/milvus2-sdk-node")
const address = "YOUR_CLUSTER_ENDPOINT"
const token = "YOUR_CLUSTER_TOKEN"
// 1. Connect to the cluster
const client = new MilvusClient({address, token})