milvus-logo
LFAI
Home
  • User Guide

Manage Milvus Connections

This topic describes how to connect to and disconnect from a Milvus server.

Ensure to connect to a Milvus server before any operations.

Milvus supports two ports, port 19530 and port 9091:

  • Port 19530 is for gRPC and RESTful API. It is the default port when you connect to a Milvus server with different Milvus SDKs or HTTP clients.

  • Port 9091 is for metrics collection, pprof profiling, and health probes within Kubernetes. It serves as a management port.

The example below demonstrates how to establish a connection to the Milvus server using localhost as the host and 19530 as the port, and then how to properly disconnect from it. If the connection is refused, try unblocking the corresponding port.

When interacting with Milvus using Python code, you have the flexibility to choose between PyMilvus and MilvusClient (new). For more information, refer to Python SDK.

Connect to a Milvus server

Construct a Milvus connection. Ensure to connect to Milvus server before any operations.

The following code snippets assume that you have enabled authentication and need to set up a connection using the root account with the default password Milvus. The token parameter is a string in the format of username:password. If you have not set up authentication, you can omit this parameter.

# Run `python3` in your terminal to operate in the Python interactive mode.
from pymilvus import connections
connections.connect(
  alias="default",
  uri="localhost:19530",
  token="root:Milvus",
)
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
const address = "localhost:19530";
const token = "root:Milvus"
const ssl = false;
const milvusClient = new MilvusClient({address, ssl, token});
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()
    .withUri("localhost:19530")
    .withToken("root:Milvus")
    .build()
);
connect -h localhost -p 19530 -a default
curl --request GET \
    --url 'localhost:19530/v1/vector/collections'

{"code":200,"data":["fouram_sLmXoqnw"]}
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.
Option Description
-h (Optional) The host name. The default is "127.0.0.1".
-p (Optional) The port number. The default is "19530".
-a (Optional) The alias name of the Milvus link. The default is "default".
-D (Optional) 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.

Disconnect from a Milvus server

Disconnect from a Milvus server.

connections.disconnect("default")
await milvusClient.closeConnection();
milvusClient.Close()
milvusClient.close()
connect -D
# Close your HTTP client connection.
Parameter Description
alias Alias of the Milvus server to disconnect from.

Limits

The maximum number of connections is 65,536.

What’s next

Having connected to a Milvus server, you can:

Feedback

Was this page helpful?