Introduction
This blog explores the Milvus CLI, Milvus Command-Line Interface (CLI) enables users to connect to Milvus, execute various data operations, and handle data import and export efficiently. It offers a guide to its commands and functionalities to help you effectively manage your vector database — including tasks such as creating collections, inserting data, performing searches, and running queries.
Here’s a step-by-step guide to connect to a Milvus service using milvus_cli
in a python environment.
Prerequisites
- Python >= 3.8.5
- Install Pymilvus → pip install pymilvus==2.5.0
- milvus_cli==1.0.2
Set Up Milvus: Ensure that the Milvus server is up and running in watsonx.data.
Obtain Connection Details: Get the necessary connection details for your Milvus service. This typically includes the host, port, and any authentication information if required.
Example-
If you have an Milvus service running in watsonx.data, you can get Milvus host
and port
details from Infrastructure manager (Navigate to Infrastructure manager → click on Milvus service → obtain the host
and port
information from the GRPC host).
fig-1
Create a virtual environment using python -m venv myenv
, then activate the virtual environment source myenv/bin/activate
Getting Started with Milvus CLI
Make sure you have milvus_cli
installed. You can install it via pip:
pip install milvus-cli==1.0.2
Usage
In a Python environment, run milvus_cli command . If successful, milvus_cli<version>
will display as shown in the following figure and we are good to run all the supported commands.
milvus_cli
__ __ _ _ ____ _ ___
| \/ (_) |_ ___ _ ___ / ___| | |_ _|
| |\/| | | \ \ / / | | / __| | | | | | |
| | | | | |\ V /| |_| \__ \ | |___| |___ | |
|_| |_|_|_| \_/ \__,_|___/ \____|_____|___|
Milvus cli version: 1.0.2
Pymilvus version: 2.5.6
Milvus-CLI Commands
1.connect → To connect to Milvus service, run the below command
Syntax-
- If Milvus service is running on SaaS instance, use the syntax below
connect -uri https://host:port -t user:password
Note- Provide the host & port details obtained from fig-1.
- If you are trying to connect to the Milvus server on Cloud Pak for Data (CPD), you also need to include the self-signed certificate from the Milvus server .
command to generate certificate-
echo QUIT | openssl s_client -showcerts -connect <host>:443 | awk '/-----BEGIN CERTIFICATE-----/ {p=1}; p; /-----END CERTIFICATE-----/ {p=0}' > tsl.cert
syntax to connect to Milvus server-
connect -uri https://host:port -t user:password --tlsmode 1 --cert /root/tsl.cert
.

2. Create Database —To Create Database in Milvus
Syntax
create database -db databaseName
Ex.
3. Use database- To use the created database
Syntax
use database -db databaseName
Ex.
4. list databases → To list all the databases
Syntax
list databases
Ex.
5. create collection → To Create a collection
Syntax
create collection -c collection_name -f schema-field -p primary-field -a
Syntax description
To define field name
-f <fieldname>:<datatype>:<dimofvector/primary_field/desc>
To define multiple field name
-f <fieldname>:<datatype>:<dimofvector/primary_field/desc> -f <fieldname>:<datatype>:<dimofvector/primary_field/desc>
-a Flag to generate IDs automatically
Ex.
6. show collection → To show the collections
Syntax
show collection -c collection_name
Ex.
7. create partition → Creates a partition.
Syntax
create partition -c collection_name -p partition_name -d descr
Ex.
8. Create Index → To create Index
Syntax
create index
Example-
milvus_cli > create index
Collection name (employee): employee
The name of the field to create an index for (id, vectorfield, phone): vectorfield
Index name: vectorIndex
Index type (FLAT, IVF_FLAT, IVF_SQ8, IVF_PQ, RNSG, HNSW, ANNOY, AUTOINDEX, DISKANN, GPU_IVF_FLAT, GPU_IVF_PQ, SPARSE_INVERTED_INDEX, SPARSE_WAND, SCANN, STL_SORT, Trie, INVERTED, ) []: IVF_FLAT
Vector Index metric type (L2, IP, HAMMING, TANIMOTO, COSINE, ) []: L2
Index params nlist: 10
Status(code=0, message=)
Create index successfully!
9. Show Index
show index -c collection_name -in index_name
Ex.
10. Insert Data → Insert data into a collection
Syntax
insert -c collection_name -p parition_name <file_path>
Example-
insert -c employee -p QA /<<file_path>>/data5.csv
Reading file from local path.
Opening csv file(26076 bytes)...
Reading csv rows... [####################################] 100%
Column names are ['vectorfield', 'phone']
Processed 11 lines.
Inserted successfully.
(insert count: 10, delete count: 0, upsert count: 0, timestamp: 451571464455323651, success count: 10, err count: 0, cost: 0)
Note- if we have provided -a flag while creating the collection then it will generate IDs automatically.
11. Load → to load the collection
Syntax
load collection -c collection_name
Ex.
12. Search → Performs a vector similarity search or hybrid search.
Syntax
milvus_cli > search
Collection name (employee): employee
The vectors of search data (the length of data is number of query (nq), the dim of every vector in data must be equal to vector field’s of collection. You can also import a CSV file without headers): /<<file_path>>/search1.csv
The vector field used to search of collection (id, vectorfield, phone): vectorfield
Metric type: L2
Search parameter nprobe's value: 10
Groups search by Field []:
The specified number of decimal places of returned distance [-1]:
The max number of returned record, also known as topk: 1
The boolean expression used to filter attribute []:
Timeout []:
Syntax description
Collection name (employee): <Enter the collection name>
The vectors of search data: <provide the file path of search vector data>
The vector field used to search of collection: <Enter the vector field>
Ex.
13. query → Shows query results that match the query expression
Ex.
14. Release Collection → To Releases a collection
Syntax
release collection -c collection_name
15. Delete partition → To delete the partition
Syntax
delete partition -c collection_name -p partition_name
16. Delete Collection → To delete a collection
Syntax
delete collection -c collection_name
Ex.
#watsonx.data