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:
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:
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:
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:
The function accepts no parameters. It then returns a list of names of all Milvus connections.
An example code is as follows:
connections.connect(
alias="default",
host='192.168.100.10',
port='19530'
)
print(connections.list_connections())
The resulting output is as follows:
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.