AI

Create a User in Milvus Using Node.js

Milvus is a vector database that is built for AI applications, and its Node.js SDK is designed for connecting and operating Milvus with Node.js. This includes creating collections, inserting vectors, searching, etc.

In this tutorial, we will explore how to create a new user in the Milvus server using the Node.js Milvus SDK.

Dependencies:

  • Milvus server
  • Node: v12+

Install the Milvus Node.js SDK

The first step is downloading and installing the Milvus SDK for Node.js. You can do this using NPM or YARN as shown in the following command:

npm install @zilliz/milvus2-sdk-node

yarn add @zilliz/milvus2-sdk-node

This donwloads the Milvus Node.js client and adds a dependency entry in your “package.json” file.

Connect to Milvus

Once you have the package installed in your project, create a new “JavaScript” file to store the source code for your project.

Next, add the code as shown in the following to connect to the Milvus server:

import { MilvusClient, DataType } from '@zilliz/milvus2-sdk-node';

const address = 'your-milvus-ip-with-port';

const username = 'your-milvus-username'; // optional username

const password = 'your-milvus-password'; // optional password

// connect to milvus

const client = new MilvusClient({ address, username, password });

If you have not enabled the authentication for your Milvus cluster, you can skip the username and password combination as they are not required by default.

Create a User

However, if you enabled the authentication for your server, you can use the CreateUser() method to configure a new Milvus user.

An example method usage is as follows:

import { MilvusClient } from "@zilliz/milvus2-sdk-node";

new milvusClient(MILUVS_ADDRESS).createUser({

username: "milvus",

password: "milvus",

});

The username and password parameters are used to specify the user and password combination that you wish to create. Upon success, the method should return a JSON response as follows:

{ error_code: 'Success', reason: '' }

Delete the User

Once you are done, you can remove the user using the DeleteUser() method. An example usage is as follows:

import { MilvusClient } from "@zilliz/milvus2-sdk-node";

new milvusClient(MILUVS_ADDRESS).deleteUser({

username: "milvus",

});

This should drop the user with the specified username and return the corresponding JSON response. If the removal is successful, the method should return an output as follows:

{ error_code: 'Success', reason: '' }

Conclusion

In this tutorial, we explored how to create a new Milvus user using the CreateUser() method provided by the Node.js SDK. You can explore the official documentation to gather more information.

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