Managing Milvus Connections

This topic explains how to connect to and disconnect from the Milvus server.

Before performing any operations, make sure you are connected to the Milvus server.

Milvus supports two ports, port 19530 and port 9091:

  • Port 19530 is used for gRPC and is the default port when connecting to the Milvus server using different Milvus SDKs.
  • Port 9091 is used for the RESTful API. Use this port when connecting to the Milvus server using an HTTP client.

The following example connects to the Milvus server with the host set to localhost and the port set to 19530 or 9091, and then disconnects. If the connection is refused, try unblocking the corresponding port.

Connecting to the Milvus Server

Establish a connection to the Milvus server. Make sure you are connected to the Milvus server before performing any operations.

from pymilvus import connections
connections.connect(
  alias="default",
  user='username',
  password='password',
  host='localhost',
  port='19530'
)
Parameter Description
alias The alias for the Milvus connection to be established.
user The username of the Milvus server.
password The password for the username of the Milvus server.
host The IP address of the Milvus server.
port The port of the Milvus server.

Return Value

The Milvus connection created with the provided parameters.

Exceptions

  • NotImplementedError: If the handler in the connection parameters is not gRPC.
  • ParamError: If the pool in the connection parameters is not supported.
  • Exception: If the specified server in the parameters is not ready and we cannot connect to the server.

Disconnecting from the Milvus Server

Disconnect from the Milvus server.

connections.disconnect("default")
Parameter Description
alias The alias of the Milvus server to disconnect from.

Limitations

The maximum number of connections is 65,536.