Connections

Connections .

Constructor

Constructor

Description

Connections()

Connections is a class which is used to manage all connections of milvus.

Methods

API

Description

configure()

Configure the milvus connections and then create milvus connections by the passed parameters.

remove_connection()

Remove connection from the registry.

create_connection()

Construct a milvus connection and register it under given alias.

get_connection()

Retrieve a milvus connection by alias.

list_connections()

List all connections.

get_connection_addr()

Get connection configure by alias.

APIs

class pymilvus_orm.Connections

Connections is a class which is used to manage all connections of milvus. Used as a singleton in this module.

configure(**kwargs)

Configure the milvus connections and then create milvus connections by the passed parameters.

Example:

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

This will create two milvus connections named default and dev.

remove_connection(alias)

Remove connection from the registry. Raises KeyError if connection wasn't found.

Parameters

alias (str) -- The name of milvus connection

Raises

KeyError -- If there is no connection with alias.

create_connection(alias='default', **kwargs) → milvus.client.stub.Milvus

Construct a milvus connection and register it under given alias.

Parameters

alias (str) -- The name of milvus connection

Return Milvus

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 specific in parameters is not ready, we cannot connect to server.

Example

>>> from pymilvus_orm import connections
>>> connections.create_connection("test", host="localhost", port="19530")
<milvus.client.stub.Milvus object at 0x7f4045335f10>
get_connection(alias='default') → milvus.client.stub.Milvus

Retrieve a milvus connection by alias.

Parameters

alias (str) -- The name of milvus connection

Return Milvus

A milvus connection which of the name is alias.

Raises
  • KeyError -- If there is no connection with alias.

  • NotImplementedError -- If handler in connection parameters is not GRPC.

  • ParamError -- If pool in connection parameters is not supported.

  • Exception -- If server specific in parameters is not ready, we cannot connect to server.

list_connections() → list

List all connections.

Return list

Names of all connections.

Example

>>> from pymilvus_orm import connections
>>> connections.create_connection("test", host="localhost", port="19530")
<milvus.client.stub.Milvus object at 0x7f4045335f10>
>>> connections.list_connections()
['test']
get_connection_addr(alias)

Get 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_orm import connections
>>> connections.create_connection("test", host="localhost", port="19530")
<milvus.client.stub.Milvus object at 0x7f4045335f10>
>>> connections.list_connections()
['test']
>>> connections.get_connection_addr('test')
{'host': 'localhost', 'port': '19530'}