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 |
---|---|
A singleton class used to manage connections and correspoinding configurations. |
Methods¶
API |
Description |
---|---|
Configures a connection, including address and port. |
|
Delete a connection configuration. |
|
Create a connection object to connect to Milvus. |
|
Disconnect from Milvus and close the connection object. |
|
List all connections. |
|
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'}
-