Manage Milvus Connections
This topic describes how to connect to and disconnect from a Milvus server.
Milvus supports two ports, port 19530 and port 9091:
Port
19530is for gRPC. It is the default port when you connect to a Milvus server with different Milvus SDKs.Port
9091is for RESTful API. It is used when you connect to a Milvus server with an HTTP client.
The example below connects to the Milvus server with host as localhost and port as 19530 or 9091, and disconnects from it. If the connection is refused, try unblocking the corresponding port.
Connect to a Milvus server
Construct a Milvus connection. Ensure to connect to Milvus server before any operations.
# Run `python3` in your terminal to operate in the Python interactive mode.
from pymilvus import connections
connections.connect(
alias="default",
user='username',
password='password',
host='localhost',
port='19530'
)
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
const address = "localhost:19530";
const username = "username";
const password = "password";
const ssl = false;
const milvusClient = new MilvusClient({address, ssl, username, password});
milvusClient, err := client.NewGrpcClient(
context.Background(), // ctx
"localhost:19530", // addr
)
if err != nil {
log.Fatal("failed to connect to Milvus:", err.Error())
}
final MilvusServiceClient milvusClient = new MilvusServiceClient(
ConnectParam.newBuilder()
.withHost("localhost")
.withPort(19530)
.build()
);
var milvusClient = new MilvusClient("localhost", username: "username", password: "password");
| Parameter | Description |
|---|---|
alias |
Alias of the Milvus connection to construct. |
user |
Username of the Milvus server. |
password |
Password of the username of the Milvus server. |
host |
IP address of the Milvus server. |
port |
Port of the Milvus server. |
| Parameter | Description |
|---|---|
address |
Address of the Milvus connection to construct. |
username |
The username used to connect to Milvus. |
password |
The password used to connect to Milvus. |
ssl |
SSL connection. It is false by default. |
| Parameter | Description |
|---|---|
ctx |
Context to control API invocation process. |
addr |
Address of the Milvus connection to construct. |
| Parameter | Description |
|---|---|
Host |
IP address of the Milvus server. |
Port |
Port of the Milvus server. |
| Parameter | Description |
|---|---|
| host | The host name. The default is "127.0.0.1". |
| port | The port number. The default is 19530. |
| username | The alias name of the Milvus link. The default is "default". |
| password | Flag to disconnect from the Milvus server specified by an alias. The default alias is "default". |
Return
A Milvus connection created by the passed parameters.
Raises
- NotImplementedError: If handler in connection parameters is not GRPC.
- ParamError: If pool in connection parameters is not supported.
- Exception: If server specified in parameters is not ready, we cannot connect to server.