Milvus CLI 命令参考
Milvus 命令行界面(CLI)是一个命令行工具,支持数据库连接、数据操作和数据导入导出。
本主题介绍所有支持的命令和相应的选项。还包括一些示例供您参考。
clear
清除屏幕。
语法
clear
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
connect
连接 Milvus。
语法
connect [-uri (text)] [-t (text)]
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -uri | --uri | (可选)uri 名称。默认为 "http://127.0.0.1:19530"。 |
| -t | --token | (可选)Zilliz Cloud Apikey 或 username:password。默认为 "无"。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > connect -uri http://127.0.0.1:19530
create database
在 Milvus 中创建数据库
语法
create database -db (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -db | --database | [必填] Milvus 中的数据库名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
下面的示例在 milvus 中创建了数据库 testdb。
milvus_cli > create database -db testdb
use database
在 Milvus 中使用数据库
语法
use database -db (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -db | --database | [必填] Milvus 中的数据库名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
下面的示例使用 milvus 中的数据库 testdb。
milvus_cli > use database -db testdb
list databases
列出 Milvus 中的数据库
语法
list databases
示例
示例 1
下面的示例列出了 milvus 中的数据库。
milvus_cli > list databases
delete database
删除 Milvus 中的数据库
语法
delete database -db (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -db | --database | [必填] Milvus 中的数据库名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
下面的示例删除了 milvus 中的数据库 testdb。
milvus_cli > delete database -db testdb
create user
在 Milvus 中创建用户
语法
create user -u (text) -p (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -p | --password | Milvus 中的用户密码。默认为 "无"。 |
| -u | --username | Milvus 中的用户名。默认为 "无"。 |
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
下面的示例在 milvus 中创建了用户 zilliz 和密码 zilliz。
milvus_cli > create user -u zilliz -p zilliz
create role
在 Milvus 中创建角色
语法
create role -r (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -r | --roleName | milvus 角色的角色名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
下面的示例在 milvus 中创建了角色 role1。
milvus_cli > create role -r role1
create alias
为 Collection 指定唯一的别名。
一个 Collection 可以有多个别名。不过,一个别名最多对应一个 Collection。
语法
create alias -c (text) -a (text) [-A]
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| -a | --alias-name | 别名。 |
| -A | --alter | (可选)将别名转移到指定 Collection 的标志。 |
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
下面的示例为 car Collection 创建了 carAlias1 和 carAlias2 别名。
milvus_cli > create alias -c car -a carAlias1
例 2
例 2 基于例 1。
下面的示例将 carAlias1 别名从 car Collection 转移到 car2 Collection。
milvus_cli > create alias -c car2 -A -a carAlias1
create collection
创建一个 Collection。
语法
create collection -c (text) -f (text) -p (text) [-a] [-d (text)]
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| -f | --schema-field | (多个) <fieldName>:<dataType>:<dimOfVector/desc> 格式的字段 Schema。 |
| -p | --schema-primary-field | 主键字段的名称。 |
| -a | --schema-auto-id | (可选)自动生成 ID 的标志。 |
| -desc | --schema-description | (可选) Collection 的描述。 |
| -level | --consistency-level | (可选)Consistency Level:Bounded、Session、Strong、Eventually。 |
| -d | --is-dynamic | (可选) Collection Schema 是否支持动态字段。 |
| -s | --shards-num | (可选)Partition 编号 |
| --help | n/a | 显示命令使用帮助。 |
示例
## For array field: --schema-field support <fieldName>:<dataType>:<maxCapacity>:<elementDataType>(:<maxLength>if Varchar)
milvus_cli > create collection -c car -f id:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:ARRAY:64:VARCHAR:128 -p id -A -d 'car_collection'
创建 Partition
创建 Partition。
语法
create partition -c (text) -p (text) [-d (text)]
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| -p | --partition | Partition 名称。 |
| -d | --description | (可选)Partition 描述。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > create partition -c car -p new_partition -d test_add_partition
create partition
为字段创建索引。
目前,一个 Collection 最多支持一个索引。
语法
create index
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
示例
为字段创建索引并提示输入所需内容:
milvus_cli > create index
Collection name (car, car2): car2
The name of the field to create an index for (vector): vector
Index name: vectorIndex
# Default is ''
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
# Default is ''
Index metric type (L2, IP, HAMMING, TANIMOTO, COSINE, ) []:
Timeout []:
create index
删除用户
语法
delete user -u (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -u | --username | 用户名。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > delete user -u zilliz
delete user
删除 Milvus 中的角色
语法
delete role -r (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -r | --roleName | milvus 角色的角色名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
下面的示例删除了 milvus 中的角色 role1。
milvus_cli > delete role -r role1
delete role
删除别名。
语法
delete alias -a (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -a | --alias-name | 别名。 |
| --help | n/a | 显示命令使用帮助。 |
delete alias
删除一个 Collection。
语法
delete collection -c (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | 要删除的 Collection 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > delete collection -c car
delete collection
删除实体。
语法
delete entities -c (text) -p (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | 要删除的实体所属的 Collection 名称。 |
| -p | --partition | (可选)要删除的 Partition 名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > delete entities -c car
The expression to specify entities to be deleted, such as "film_id in [ 0, 1 ]": film_id in [ 0, 1 ]
You are trying to delete the entities of collection. This action cannot be undone!
Do you want to continue? [y/N]: y
delete entities
删除 Partition。
语法
delete partition -c (text) -p (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | 要删除的 Partition 所属的 Collection 名称。 |
| -p | --partition | 要删除的 Partition 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > delete partition -c car -p new_partition
delete partition
删除索引和相应的索引文件。
目前,一个 Collection 最多支持一个索引。
语法
delete index -c (text) -in (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| -in | --index-name | 索引名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > delete index -c car -in indexName
delete index
授予用户角色
语法
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| -r | --roleName | milvus 角色的角色名称。 |
| -u | --username | milvus 用户的用户名。 |
| --help | n/a | 显示命令使用帮助。 |
示例
grant role -r role1 -u user1
grant role
为角色分配权限。
语法
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
示例
grant privilege
grant privilege
撤销分配给用户的角色。
语法
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| -r | --roleName | milvus 角色的角色名称。 |
| -u | --username | milvus 用户的用户名。 |
| --help | n/a | 显示命令使用帮助。 |
示例
grant role -r role1 -u user1
revoke role
撤销已分配给角色的权限。
语法
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
示例
revoke privilege
revoke privilege
显示 Collection 的详细信息。
语法
show collection -c (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > show collection -c test_collection_insert
show collection
显示 Partition 的详细信息。
语法
show partition -c (text) -p (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Partition 所属 Collection 的名称。 |
| -p | --partition | Partition 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > show partition -c test_collection_insert -p _default
show partition
显示索引的详细信息。
语法
show index -c (text) -in (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| -in | --index-name | 索引名称。 |
| --help | n/a | 显示命令使用帮助。|
示例
milvus_cli > show index -c test_collection -in index_name
show index
关闭命令行窗口。
语法
exit
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
exit
显示使用命令的帮助。
语法
help <command>
命令
| 命令 | 说明 |
|---|---|
| clear | 清除屏幕。 |
| connect | 连接 Milvus。 |
| create | 创建 Collection、数据库、Partition、用户、角色和索引。 |
| grant | 授予角色、权限。 |
| revoke | 撤销角色、权限。 |
| delete | 删除 Collection、数据库、Partition、别名、用户、角色或索引。 |
| exit | 关闭命令行窗口。 |
| help | 显示命令使用帮助。 |
| insert | 将数据导入 Partition。 |
| list | 列出 Collection、数据库、Partition、用户、角色、授权或索引。 |
| load | 加载一个 Collection 或 Partition。 |
| query | 显示符合所有输入条件的查询结果。 |
| release | 释放一个 Collection 或 Partition。 |
| search | 执行向量相似性搜索或混合搜索。 |
| show | 显示连接、数据库、Collection、加载进度或索引进度。 |
| rename | 重命名 Collection |
| use | 使用数据库 |
| version | 显示 Milvus_CLI 的版本。 |
help
将本地或远程数据导入 Partition。
语法
import -c (text)[-p (text)] <file_path>
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | 插入数据的 Collection 名称。 |
| -p | --partition | (可选)插入数据的 Partition 名称。不通过此 Partition 选项表示选择"_默认 "Partition。 |
| --help | n/a | 显示命令使用帮助。 |
示例 1
下面的示例导入了一个本地 CSV 文件。
milvus_cli > import -c car 'examples/import_csv/vectors.csv'
Reading csv file... [####################################] 100%
Column names are ['vector', 'color', 'brand']
Processed 50001 lines.
Inserting ...
Insert successfully.
-------------------------- ------------------
Total insert entities: 50000
Total collection entities: 150000
Milvus timestamp: 428849214449254403
-------------------------- ------------------
示例 2
下面的示例导入了一个远程 CSV 文件。
milvus_cli > import -c car 'https://raw.githubusercontent.com/milvus-
io/milvus_cli/main/examples/import_csv/vectors.csv'
Reading file from remote URL.
Reading csv file... [####################################] 100%
Column names are ['vector', 'color', 'brand']
Processed 50001 lines.
Inserting ...
Insert successfully.
-------------------------- ------------------
Total insert entities: 50000
Total collection entities: 150000
Milvus timestamp: 428849214449254403
-------------------------- ------------------
import
列出所有用户。
语法
list users
选项
| 选项 | 全名 | 说明 | | --help | n/a | 显示命令使用帮助。|
list users
列出 Milvus 中的角色
语法
list roles
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > list roles
List roles
列出 Milvus 中的授权
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| -r | --roleName | milvus 角色的角色名称。 |
| -o | --objectName | milvus 对象的对象名称。 |
| -t | --objectType | 全局、Collection 或用户。 |
| --help | n/a | 显示命令使用帮助。 |
示例
milvus_cli > list grants -r role1 -o object1 -t Collection
List grants
列出所有 Collection。
语法
list collections
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
list collections
列出 Collection 的所有索引。
目前,一个 Collection 最多支持一个索引。
语法
list indexes -c (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
list indexes
列出 Collection 的所有 Partition。
语法
list partitions -c (text)
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Collection 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
list partitions
将一个 Collection 或 Partition 从硬盘空间加载到 RAM。
语法
load -c (text) [-p (text)]
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Partition 所属 Collection 的名称。 |
| -p | --partition | (可选/多个)Partition 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
load
显示符合所有输入条件的查询结果。
语法
query
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
执行查询并提示输入所需内容:
milvus_cli > query
Collection name: car
The query expression: id in [ 428960801420883491, 428960801420883492,
428960801420883493 ]
Name of partitions that contain entities(split by "," if multiple) []:
default
A list of fields to return(split by "," if multiple) []: color, brand
timeout []:
Guarantee timestamp. This instructs Milvus to see all operations performed before a provided timestamp. If no such timestamp is provided, then Milvus will search all operations performed to date. [0]:
Graceful time. Only used in bounded consistency level. If graceful_time is set, PyMilvus will use current timestamp minus the graceful_time as the guarantee_timestamp. This option is 5s by default if not set. [5]:
例 2
执行查询并提示输入所需内容:
milvus_cli > query
Collection name: car
The query expression: id > 428960801420883491
Name of partitions that contain entities(split by "," if multiple) []:
default
A list of fields to return(split by "," if multiple) []: id, color,
brand
timeout []:
Guarantee timestamp. This instructs Milvus to see all operations performed before a provided timestamp. If no such timestamp is provided, then Milvus will search all operations performed to date. [0]:
Graceful time. Only used in bounded consistency level. If graceful_time is set, PyMilvus will use current timestamp minus the graceful_time as the guarantee_timestamp. This option is 5s by default if not set. [5]:
query
从 RAM 中释放一个 Collection 或 Partition。
语法
release -c (text) [-p (text)]
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | Partition 所属 Collection 的名称。 |
| -p | --partition | (可选/多个)Partition 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
release
执行向量相似性搜索或混合搜索。
语法
search
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
示例
示例 1
对 csv 文件执行搜索,并提示输入所需内容:
milvus_cli > search
Collection name (car, test_collection): car
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
out headers): examples/import_csv/search_vectors.csv
The vector field used to search of collection (vector): vector
Search parameter nprobe's value: 10
The max number of returned record, also known as topk: 2
The boolean expression used to filter attribute []: id > 0
The names of partitions to search (split by "," if multiple) ['_default'] []: _default
timeout []:
Guarantee Timestamp(It instructs Milvus to see all operations performed before a provided timestamp. If no such timestamp is provided, then Milvus will search all operations performed to date) [0]:
例 2
对索引 Collection 执行搜索,并提示输入所需内容:
milvus_cli > search
Collection name (car, test_collection): car
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):
[[0.71, 0.76, 0.17, 0.13, 0.42, 0.07, 0.15, 0.67, 0.58, 0.02, 0.39, 0.47, 0.58, 0.88, 0.73, 0.31, 0.23, 0.57, 0.33, 0.2, 0.03, 0.43, 0.78, 0.49, 0.17, 0.56, 0.76, 0.54, 0.45, 0.46, 0.05, 0.1, 0.43, 0.63, 0.29, 0.44, 0.65, 0.01, 0.35, 0.46, 0.66, 0.7, 0.88, 0.07, 0.49, 0.92, 0.57, 0.5, 0.16, 0.77, 0.98, 0.1, 0.44, 0.88, 0.82, 0.16, 0.67, 0.63, 0.57, 0.55, 0.95, 0.13, 0.64, 0.43, 0.71, 0.81, 0.43, 0.65, 0.76, 0.7, 0.05, 0.24, 0.03, 0.9, 0.46, 0.28, 0.92, 0.25, 0.97, 0.79, 0.73, 0.97, 0.49, 0.28, 0.64, 0.19, 0.23, 0.51, 0.09, 0.1, 0.53, 0.03, 0.23, 0.94, 0.87, 0.14, 0.42, 0.82, 0.91, 0.11, 0.91, 0.37, 0.26, 0.6, 0.89, 0.6, 0.32, 0.11, 0.98, 0.67, 0.12, 0.66, 0.47, 0.02, 0.15, 0.6, 0.64, 0.57, 0.14, 0.81, 0.75, 0.11, 0.49, 0.78, 0.16, 0.63, 0.57, 0.18]]
The vector field used to search of collection (vector): vector
Search parameter nprobe's value: 10
The specified number of decimal places of returned distance [-1]: 5
The max number of returned record, also known as topk: 2
The boolean expression used to filter attribute []: id > 0
The names of partitions to search (split by "," if multiple) ['_default'] []: _default
timeout []:
Guarantee Timestamp(It instructs Milvus to see all operations performed before a provided timestamp. If no such timestamp is provided, then Milvus will search all operations performed to date) [0]:
例 3
在非索引 Collection 上执行搜索,并提示输入所需内容:
milvus_cli > search
Collection name (car, car2): car
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): examples/import_csv/search_vectors.csv
The vector field used to search of collection (vector): vector
The specified number of decimal places of returned distance [-1]: 5
The max number of returned record, also known as topk: 2
The boolean expression used to filter attribute []:
The names of partitions to search (split by "," if multiple) ['_default'] []:
timeout []:
Guarantee Timestamp(It instructs Milvus to see all operations performed before a provided timestamp. If no such timestamp is provided, then Milvus will search all operations performed to date) [0]:
search
列出连接。
语法
list connections
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
list connection
显示实体索引的进度。
语法
show index_progress -c (text) [-i (text)]
选项
| 选项 | 全名 | 说明 |
|---|---|---|
| -c | --collection-name | 实体所属 Collection 的名称。 |
| -i | --index | (可选)索引名称。 |
| --help | n/a | 显示命令使用帮助。 |
show index_progress
显示 Collection 的加载进度。
语法
show loading_progress -c (text) [-p (text)]
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| -c | --collection-name | 实体所属 Collection 的名称。 |
| -p | --partition | (可选/多个)加载 Partition 的名称。 |
| --help | n/a | 显示命令使用帮助。 |
show loading_progress
显示 Milvus CLI 的版本。
语法
version
选项
| 选项 | 全称 | 说明 |
|---|---|---|
| --help | n/a | 显示命令使用帮助。 |
也可以在 shell 中检查 Milvus CLI 的版本,如下例所示。在这种情况下,milvus_cli --version 充当命令。
示例
milvus_cli --version
Milvus_CLI v0.4.0