From the course: LLM Foundations: Vector Databases for Caching and Retrieval Augmented Generation (RAG)

Create databases and users

Having created a connection to Milvus in the previous video, let's now create a database through the SDK and then check the list of current databases. We first import the DB package from PyMilvus. This package has a list_database method that can be used to list all the databases that a given connection has access to. We get that list and print it. We don't see any databases at this point. We set the database name to course_db. If this database is not in the list of current databases, we then proceed to create the database. For this, we use the create_database method and also pass the connection ID. When a connection starts, it is usually in the context of the default database. To switch to the newly created database as the current one, we will use the using_database method. Going forward, all actions on this connection will be on the course_db database. Let's run this code now. Next, we will create a new user. We begin by using the utility package in pymilvus. The list_usernames method returns the list of all existing users for this database. This list is printed. If the user called course_admin is not in the list, we proceed to create the new user. There is already a public role available for this database by default. To add the new user to the role, we first create a role object for this role and check if it exists. Then we add the new user to this role. Let's run this code now. Let's now switch to the Attu UI. It's running on Port 8000 on localhost. On the Home page, we get to pick the database we want to look at. Let's pick course_db. It shows the summary information about the database. It shows the total number of collections and those that are loaded into memory. The system info on the right side shows the Milvus version number, deployment mode, total users, and roles. Let's click on the "User" page. Here again, we get to choose the database we want to work with. We see the course admin user already created. We can add new roles here and set permissions for the role too. We can also assign these roles to users. Users can be created and managed here for each database.

Contents