AI

PyMilvus Reset_Password()

In this tutorial, we will learn how to use the PyMilvus SDK, the create_user function to create a new user, and the reset_password() function to reset the password of an existing user.

Requirements:

Ensure that you have the following:

  1. Access to a Milvus cluster, local or remote
  2. Python 3.10+ and above
  3. Pip package manager

Installing PyMilvus

Before using this function, ensure that you have the PyMilvus package installed. PyMilvus is a Python SDK that provides a convenient way to interact with the Milvus vector database.

It is an open-source library that is developed by the Milvus community and provides a high-level interface to perform the operations such as inserting, querying, and managing the vector data.

You can install it with the following command:

python3 -m pip install pymilvus==2.2.12

Once installed, you can verify the PyMilvus package availability with the following code block:

python3 -c "from pymilvus import Collection"

If the previous code does not return an error, it means that you have successfully installed the PyMilvus package.

PyMilvus Create_User() Function

This method creates a user. You have to specify a username and a password. The user name must be unique globally.

The method invocation is as follows:

create_user(user, password, using="default")

The method parameters are as follows:

  • User – It sets the name of the user to be created.
  • password ­– It defines the password of the user to be created as a string value.
  • Using – This sets the alias of the Milvus connection to be attached to.

The method has no return value.

Example Demonstration:

The following code shows how to use the create_user() method to create a username with the password in the Milvus cluster:

from pymilvus import connections, utility

connections.connect()

utility.create_user(linuxhint, password)

connections.connect(user=user, password=password)

users = utility.list_usernames()

print(f"users in Milvus: {users}")

The previous code uses the create_user() function to create a new user with the “linuxhint” username and the password of password.

Finally, we use the list_usernames function to get all the users in the Milvus cluster and print them.

PyMilvus Reset_Password() Function

The reset_password() allows us to reset the specified user’s password. The method invocation is as follows:

reset_password(user, old_password, new_password)

The method requires you to specify the username, old password, and new password. The following example code demonstrates how to use the “reset password” function.

from pymilvus import connections, utility

connections.connect()

utility.reset_password(linuxhint, password, _password)

The previous code resets the password of the “linuxhint” username.

Conclusion

We explored how we can use the reset_password() function to reset the password of an existing username in the Milvus server.

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