AI

Load a Collection in Milvus

In the Milvus vector database, the collection loading refers to making a given collection available for querying. In Milvus, a collection refers to a logical container that holds the vector data where each vector represents a data point in a high-dimensional space.

Before we can query the data that is stored in the collection, we need to ensure that the collection is loaded into the memory. Once we create a collection in the database, it is stored in the system’s storage, but it is not readily available for querying or other operations.

Therefore, before we can query the data that is stored in the collection, we need to load the collection into the memory.

In this tutorial, we will learn how to load a collection into the memory to allows us to query it using the Milvus CLI or Attu Manager.

How Does the Collection Loading Works?

Before we get to the commands on loading the Milvus collection, let us explore what exactly happens during the collection load.

Loading a collection involves loading the metadata that is associated with the collection such as the schema, indexing configurations, and other settings. In addition, it involves loading the vector data from the storage system into the memory for quick and efficient data query and processing.

Creating a Milvus Collection

Before learning how to load a Milvus collection, let us start by setting up a sample Milvus collection for demonstration purposes.

Start by opening the Milvus CLI with the following command:

$ milvus_cli

Next, login to your Milvus instance with the following command:

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

For example, the following command logs into a locally hosted Milvus instance on the default port and alias.

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

Output:

Connect Milvus successfully.
+---------+---------------------+
| Address | 192.168.100.2:19530 |
| User | |
| Alias | default |

Once logged in, we can create a sample Milvus collection as shown in the following command:

milvus_cli > create collection -c film -f id:INT64:primary_field -f film_name:VARCHAR:100 -f release_year:INT64:release_year -f vector:FLOAT_VECTOR:8 -p id -d 'fiml_collection'

We call the “create collection” command to create a new collection in Milvus.

Next, we use the -c parameter to specify the collection’s name. In this case, the collection name is “film.”

The -f parameter allows us to specify the fields of the collection and their corresponding types within the collection. In this collection, the fields are defined as follows:

id:INT64:primary_field – This specifies the field named “id” of type INT64, and it is marked as the primary field. The primary field is used to uniquely identify the records in the collection.

film_name VARCHAR:100 – This specifies the field named “film_name” of type VARCHAR with a maximum length of 100 characters.

release_year:INT64:release_year – This specifies the field named “release_year” of type INT64.

vector:FLOAT_VECTOR:8 – This specifies the field named “vector” as a vector field of type FLOAT_VECTOR with a dimension of 8.

The -p id parameter allows us to specify the primary key for the collection. In this case, we specify the primary key as the “id” field.

Finally, we use the -d parameter to specify the description for the collection.

Load a Collection in Milvus Using CLI

The first and most common method to load a collection from the hard disk into the memory is using the Milvus CLI.

The CLI provides us with a set of commands that are easy to use which allows us to quickly and efficiently manage the database from a CLI interface.

To load a database in Milvus, we can use the “load” command as shown in the following syntax:

$ load -c (text) [-p (text)]

Where -c denotes the collection name and -p denotes the partition name.

NOTE: The load command allows us to load a collection or a partition to the memory.

For example, we can run the following query to load the film collection into the memory.

milvus_cli > load -c film

The previous command should load the film collection into the memory and allow you to search the stored data.

Load Collection film successfully
+-------------------+----------+---------+
| Collection Name | Loaded | Total |
+===================+==========+=========+
| film | | |
+-------------------+----------+---------+

NOTE: The command may require you to create an index on your target collection.

Load Collection in Milvus Using Attu

The second method that we can use to load the collection is the Attu manager. This graphical interface allows you to interact with and manage your Milvus database from a GUI interface.

Start by launching the Attu manager and connect to your Milvus server.

Once connected, select the “Collections” pane from the left-hand pane.

This should list all the available collections on the server. Next, select the collection that you wish to load and choose the upload icon from the left pane.

This should prompt you to confirm whether you wish to load the selected collection into the memory. Click “load” to proceed.

This should load the selected collection into the database and allow you to query or perform any actions on the database.

You can view the loaded database by selecting the first option on the left-hand pane.

Conclusion

We explored the two main ways to use the Milvus CLI and the Attu manager to load a given collection from the system storage into the system memory.

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