milvus-logo

Connections

Before connecting to Milvus, the user needs to configure the address and port of the service, and an alias can be assigned to the configuration. The role of Connections is to manage the configuration content of each connection and the corresponding connection object. Using the Connections object, users can either configure a single connection to a single service instance, or configure multiple connections to multiple different service instances. In PyMilvus-ORM, Connections is implemented as a singleton class.

Constructor

Constructor

Description

Connections()

A singleton class used to manage connections and correspoinding configurations.

Methods

API

Description

add_connection()

Configures a connection, including address and port.

remove_connection(alias)

Delete a connection configuration.

connect([alias])

Create a connection object to connect to Milvus.

disconnect([alias])

Disconnect from Milvus and close the connection object.

list_connections()

List all connections.

get_connection_addr([alias])

Retrieves connection's configuration by alias.

APIs

class pymilvus.Connections

Class for managing all connections of milvus. Used as a singleton in this module.

add_connection(**kwargs)

Configures a milvus connection.

Example:

connections.add_connection(
    default={"host": "localhost", "port": "19530"},
    dev={"host": "localhost", "port": "19531"},
)

The above example creates two milvus connections named default and dev.

disconnect(alias: str)

Disconnects connection from the registry.

Parameters

alias (str) -- The name of milvus connection

remove_connection(alias: str)

Removes connection from the registry.

Parameters

alias (str) -- The name of milvus connection

connect(alias='default', **kwargs)

Constructs a milvus connection and register it under given alias.

Parameters

alias (str) -- The name of milvus connection

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.

Example
>>> from pymilvus import connections
>>> connections.connect("test", host="localhost", port="19530")
list_connections() → list

List names of all connections.

Return list

Names of all connections.

Example
>>> from pymilvus import connections
>>> connections.connect("test", host="localhost", port="19530")
>>> connections.list_connections()
// TODO [('default', None), ('test', )]
get_connection_addr(alias: str)

Retrieves connection configure by alias.

Parameters

alias (str) -- The name of milvus connection

Return dict

The connection configure which of the name is alias. If alias does not exist, return empty dict.

Example
>>> from pymilvus import connections
>>> connections.connect("test", host="localhost", port="19530")
>>> connections.list_connections()
[('default', None), ('test', )]
>>> connections.get_connection_addr('test')
{'host': 'localhost', 'port': '19530'}