AI

Create a Collection Using Milvus CLI

In Milvus, a collection refers to the primary storage structure for the data that is stored in the Milvus database. It is similar to a table in relational databases.

In Milvus, each collection is designed to store a set of vectors along with some scalar fields. Vectors are typically high-dimensional data points such as embeddings that are generated by machine learning models.

In simple terms, you can think of a Milvus collection as a complex table where each row contains a unique identifier, various scalar fields, and one vector field.

What Is Milvus CLI

Milvus CLI is a command-line tool that allows us to connect and interact with the Milvus database server. It allows us to connect, manage the database, and import or export the data from the server.

In this tutorial, we will learn how to configure the Milvus CLI and use it to create a Milvus collection.

NOTE: We will demonstrate the installation of the Milvus CLI on Ubuntu 22.04. However, the instructions works on any system with the pip package manager installed.

Install Milvus CLI – PIP on Ubuntu

The simplest method to install Milvus CLI is using the pip package manager. For example, we can run the command as follows:

$ sudo pip install milvus-cli

If you don’t have pip installed, you can run the following command:

$ sudo apt-get install python3-pip -y

Once completed, you can verify by checking the CLI version with the following command:

$ milvus_cli --version

Output:

Milvus_CLI v0.3.3

Milvus Create Collection Command

The “create-collection” command in the Milvus CLI allows us to create a new Milvus collection. The command syntax is as follows:

  • -c, –collection-name TEXT – The collection name to specify the alias.
  • -p, –schema-primary-field TEXT – The primary field name.
  • -a, –schema-auto-id – It enables the auto id.
  • -d, –schema-description TEXT – The description details.
  • -f, –schema-field TEXT – The FieldSchema. Usage is “<Name>:<DataType>:<Dim(if vector) or Description>”.

Create a Collection Using Milvus CLI

Let us demonstrate a basic example on how we create a collection using the Milvus CLI.

Start by connecting to the Milvus server with the following command:

$ milvus_cli connect -h <host> -p <port> -a <alias>

For Example:

milvus_cli > connect -h 127.0.0.1 -p 19530 -a default

This should connect to the Milvus instance on localhost and the default port.

Create a Collection in Milvus

To create a collection, we can run the following command:

milvus_cli > create collection -c <collection_name> -f <schema_field> -p <schema-primary-field> -d <schema_description>

For Example:

milvus_cli > create collection -c books -f id:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f title:STRING:title -f author:STRING:author -p id -a -d 'books_collection'

The previous command creates a book collection with the defined schema fields.

Conclusion

We explored the concept of collections in the Milvus database. We also learned how to install the Milvus CLI and how to use it to create a simple Milvus collection.

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