AI

PyMilvus List_Connections()

When working with Milvus, you may encounter a scenario where you need to gather the list of clients that are connected to the Milvus server.

In this tutorial, we will learn how we can use the PyMilvus package and the list_connection() function to list the clients that are connected to the server.

Installing the PyMilvus Package

PyMilvus is a high-performance open-source Python library that provides an efficient and scalable data indexing and retrieval capabilities for large-scale similarity search applications.

We can install PyMilvus using pip with the following command:

$ sudo pip3 install pymilvus

The previous command should download and install the PyMilvus package on your system.

Connect to the Server in PyMilvus

We need to import the “connect” function from the PyMilvus package to connect to the server.

The function syntax is as follows:

connect(alias, **kwargs)

The function accepts the following parameters:

  • Alias – This specifies an alias that is assigned to the connection for easier identification.
  • kwargs: host – It specifies the IP address of the Milvus connection.
  • kwargs: port – It specifies the port of the Milvus connection.
  • kwargs: uri – It specifies the Milvus instance endpoint, usually in the form of <scheme>://<host>:<port>.
  • kwargs: secure – This parameter defines whether TLS/SSL is required to access the endpoint.

The function has no return value but establishes a connection to the specified Milvus server.

The following example demonstrates how to use the connect() function to establish a connection to the Milvus server that runs on the localhost and default port:

from pymilvus import connections

connections.connect(

alias="default",

host='localhost',

port='19530'

)

uri="http://localhost:19530"

connections.connect(uri=uri)

Once connected, we can use the list_connection() function to get the list of clients that are connected to the server.

Pymilvus List_Connection() Function

This function lets us list all the Milvus connections in a simple implementation. The function syntax is as follows:

list_connections()

The function accepts no parameters. It then returns a list of names of all Milvus connections.

An example code is as follows:

from pymilvus import connections

connections.connect(

alias="default",

host='192.168.100.10',

port='19530'

)

print(connections.list_connections())

The resulting output is as follows:

[('default', <pymilvus.client.grpc_handler.GrpcHandler object at 0x7fd8e66c3f70>)]

In this case, we only have one connection to the server using gRPC from PyMilvus.

Conclusion

This tutorial covered the workings of the list_connections() function to list all the connections to the Milvus server using the PyMilvus package.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list