跳到主要内容
版本:v2.5.x

Milvus_CLI 命令参考

Milvus 命令行界面(CLI)是一个命令行工具,支持数据库连接、数据操作和数据导入导出。

本主题介绍所有支持的命令和相应的选项。还包括一些示例供您参考。

命令组

Milvus CLI 命令分为以下几组:

  • create:创建 Collection、数据库、Partition、用户、角色或索引
  • delete:删除 Collection、数据库、Partition、别名、用户、角色或索引
  • list:列出 Collection、数据库、Partition、用户、角色、授权或索引
  • show:显示连接、数据库、Collection、加载进度或索引进度
  • grant:授予角色或权限
  • revoke:撤销角色或权限
  • load:加载 Collection 或 Partition
  • release:释放 Collection 或 Partition
  • use:使用数据库
  • rename:重新命名 Collection
  • insert:插入实体(文件或行)

清除

清除屏幕。

语法

clear

选项

选项全称说明
-帮助不适用显示命令使用帮助。

连接

连接 Milvus。

语法

connect [-uri (text)] [-t (text)]
connect [-uri (text)] [-t (text)] [-tls (0|1)] [-cert (text)]

选项

选项全名说明
-uri-uri(可选)uri 名称。默认为 "http://127.0.0.1:19530"。
-t-令牌(可选)Zilliz Cloud apikey 或username:password 。默认为 "无"。
-tls-tlsmode(可选)设置 TLS 模式:0(无加密)、1(单向加密)、2(暂不支持双向加密)。默认为 0
-证书-证书(可选)客户端证书文件的路径。使用单向加密
-帮助不适用显示命令使用帮助。

示例

milvus_cli > connect -uri http://127.0.0.1:19530

创建数据库

在 Milvus 中创建数据库

语法

create database -db (text)

选项

选项全名说明
-db-db_name[必填] Milvus 中的数据库名称。
-help不适用显示命令使用帮助。

示例

示例 1

下面的示例在 milvus 中创建了数据库testdb

milvus_cli > create database -db testdb

使用数据库

在 Milvus 中使用数据库

语法

use database -db (text)

选项

选项全名说明
-db-db_name[必填] Milvus 中的数据库名称。
-help不适用显示命令使用帮助。

示例

示例 1

下面的示例使用 milvus 中的数据库testdb

milvus_cli > use database -db testdb

列出数据库

列出 Milvus 中的数据库

语法

list databases

示例

示例 1

下面的示例列出了 milvus 中的数据库。

milvus_cli > list databases

删除数据库

删除 Milvus 中的数据库

语法

delete database -db (text)

选项

选项全名说明
-db-db_name[必填] Milvus 中的数据库名称。
-help不适用显示命令使用帮助。

示例

示例 1

下面的示例删除了 milvus 中的数据库testdb

milvus_cli > delete database -db testdb

Warning! You are trying to delete the database. This action cannot be undone!
Do you want to continue? [y/N]: y

创建用户

在 Milvus 中创建用户

语法

create user -u (text) -p (text)

选项

选项全名说明
-p-密码Milvus 中的用户密码。默认为 "无"。
-u-用户名Milvus 中的用户名。默认为 "无"。
-help不适用显示命令使用帮助。

示例

示例 1

下面的示例在 milvus 中创建了用户zilliz 和密码zilliz

milvus_cli > create user -u zilliz -p zilliz

创建角色

在 Milvus 中创建角色

语法

create role -r (text)

选项

选项全名说明
-r-角色名称milvus 角色的角色名称。
-帮助不适用显示命令使用帮助。

示例

示例 1

下面的示例在 milvus 中创建了角色role1

milvus_cli > create role -r role1

创建别名

为 Collection 指定唯一的别名。

说明

一个 Collection 可以有多个别名。不过,一个别名最多对应一个 Collection。

语法

create alias -c (text) -a (text) [-A]

选项

选项全名说明
-c-Collection-名称Collection 的名称。
-a-别名别名。
-A-alter(可选)将别名转移到指定 Collection 的标志。
-help不适用显示命令使用帮助。

示例

示例 1

下面的示例为car Collection 创建了carAlias1carAlias2 别名。

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

创建 Collection

创建一个 Collection。

语法

create collection

交互式示例

milvus_cli > create collection

Please input collection name: car
Please input auto id [False]: False
Please input description []: car collection
Is support dynamic field [False]: False
Please input consistency level(Strong(0),Bounded(1), Session(2), and Eventually(3)) [1]: 1
Please input shards number [1]: 1

Field name: id
Field type (INT64, VARCHAR, FLOAT_VECTOR, etc.): INT64
Field description []: primary key
Is id the primary key? [y/N]: y

Field name: vector
Field type (INT64, VARCHAR, FLOAT_VECTOR, etc.): FLOAT_VECTOR
Field description []: vector field
Dimension: 128

Field name: color
Field type (INT64, VARCHAR, FLOAT_VECTOR, etc.): INT64
Field description []: color field
Nullable [False]: False
Default value (type: INT64) [Not set]: 0

Do you want to add embedding function? [y/N]: n

创建 Partition

创建 Partition。

语法

create partition -c (text) -p (text) [-d (text)]

选项

选项全名说明
-c-Collection-名称Collection 的名称。
-p-PartitionPartition 名称。
-d-Partition 描述(可选)Partition 描述。
-help不适用显示命令使用帮助。

示例

milvus_cli > create partition -c car -p new_partition -d test_add_partition

创建索引

为字段创建索引。

说明

目前,一个 Collection 最多支持一个索引。

语法

create index

交互示例

milvus_cli > create index

Collection name (car, car2): car2
The name of the field to create an index for (vector): vector
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, SCANN, STL_SORT, Trie, INVERTED): IVF_FLAT
Vector Index metric type (L2, IP, HAMMING, TANIMOTO, COSINE): L2
Index params nlist: 2
Timeout []:

删除用户

删除用户

语法

delete user -u (text)

选项

选项全名说明
-u-用户名用户名。
-help不适用显示命令使用帮助。

示例

milvus_cli > delete user -u zilliz

Warning! You are trying to delete the user in milvus. This action cannot be undone!
Do you want to continue? [y/N]: y

删除角色

删除 Milvus 中的角色

语法

delete role -r (text)

选项

选项全名说明
-r-角色名称milvus 角色的角色名称。
-帮助不适用显示命令使用帮助。

示例

下面的示例删除了 milvus 中的角色role1

milvus_cli > delete role -r role1

删除别名

删除别名。

语法

delete alias -a (text)

选项

选项全名说明
-a-别名别名。
-帮助不适用显示命令使用帮助。

delete Collection

删除一个 Collection。

语法

delete collection -c (text)

选项

选项全名说明
-c-collection-名称要删除的 Collection 的名称。
-帮助不适用显示命令使用帮助。

示例

milvus_cli > delete collection -c car

Warning! You are trying to delete the collection. This action cannot be undone!
Do you want to continue? [y/N]: y

删除实体

删除实体。

语法

delete entities -c (text) -p (text)

选项

选项全名说明
-c-Collection-名称要删除的实体所属的 Collection 名称。
-p-Partition(可选)要删除的 Partition 名称。
-help不适用显示命令使用帮助。

示例

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 ]

Warning! You are trying to delete the entities of collection. This action cannot be undone!
Do you want to continue? [y/N]: y

删除 Partition

删除 Partition。

语法

delete partition -c (text) -p (text)

选项

选项全名说明
-c-Collection-名称要删除的 Partition 所属的 Collection 名称。
-p-Partition要删除的 Partition 的名称。
-help不适用显示命令使用帮助。

示例

milvus_cli > delete partition -c car -p new_partition

删除索引

删除索引和相应的索引文件。

说明

目前,一个 Collection 最多支持一个索引。

语法

delete index -c (text) -in (text)

选项

选项全名说明
-c-Collection-名称Collection 的名称。
-在-索引名称索引名称。
-帮助显示命令使用帮助。

示例

milvus_cli > delete index -c car -in indexName

Warning! You are trying to delete the index of collection. This action cannot be undone!
Do you want to continue? [y/N]: y

授予角色

授予用户角色

语法

grant role -r (text) -u (text)

选项

选项全称说明
-r-角色名称milvus 角色的角色名称。
-u-用户名milvus 用户的用户名。
-help不适用显示命令使用帮助。

示例

milvus_cli > grant role -r role1 -u user1

授予权限

为角色分配权限。

语法

grant privilege

交互式 示例

milvus_cli > grant privilege

Role name: role1
The type of object for which the privilege is to be assigned. (Global, Collection, User): Collection
The name of the object to control access for: object1
The name of the privilege to assign. (CreateCollection, DropCollection, etc.): CreateCollection
The name of the database to which the object belongs. [default]: default

撤销角色

撤销分配给用户的角色。

语法

revoke role -r (text) -u (text)

选项

选项全称说明
-r-角色名称milvus 角色的角色名称。
-u-用户名milvus 用户的用户名。
-help不适用显示命令使用帮助。

示例

milvus_cli > revoke role -r role1 -u user1

撤销权限

撤销已分配给角色的权限。

语法

revoke privilege

交互式 示例

milvus_cli > revoke privilege

Role name: role1
The type of object for which the privilege is to be assigned. (Global, Collection, User): Collection
The name of the object to control access for: object1
The name of the privilege to assign. (CreateCollection, DropCollection, etc.): CreateCollection
The name of the database to which the object belongs. [default]: default

显示 Collection

显示 Collection 的详细信息。

语法

show collection -c (text)

选项

选项全名说明
-c-Collection-名称Collection 的名称。
-帮助不适用显示命令使用帮助。

示例

milvus_cli > show collection -c test_collection_insert

show partition

显示 Partition 的详细信息。

语法

show partition -c (text) -p (text)

选项

选项全名说明
-c-Collection-名称Partition 所属 Collection 的名称。
-p-PartitionPartition 的名称。
-help不适用显示命令使用帮助。

示例

milvus_cli > show partition -c test_collection_insert -p _default

show index

显示索引的详细信息。

语法

show index -c (text) -in (text)

选项

选项全名说明
-c-Collection-名称Collection 的名称。
-在-索引名称索引名称。

| --help | n/a | 显示命令使用帮助。|

示例

milvus_cli > show index -c test_collection -in index_name

退出

关闭命令行窗口。

语法

exit

选项

选项全名说明
-帮助不适用显示命令使用帮助。

帮助

显示使用命令的帮助。

语法

help <command>

命令

命令说明
清除清除屏幕。
连接连接 Milvus。
创建创建 Collection、数据库、Partition、用户、角色和索引。
授予授予角色、权限。
撤销撤销角色、权限。
删除删除 Collection、数据库、Partition、别名、用户、角色或索引。
退出关闭命令行窗口。
帮助显示命令使用帮助。
插入将数据导入 Partition。
列表列出 Collection、数据库、Partition、用户、角色、授权或索引。
加载加载一个 Collection 或 Partition。
查询显示符合所有输入条件的查询结果。
释放释放一个 Collection 或 Partition。
搜索执行向量相似性搜索或混合搜索。
显示显示连接、数据库、Collection、加载进度或索引进度。
重命名重命名 Collection
使用使用数据库
版本显示 Milvus_CLI 的版本。

插入

将本地或远程数据导入 Partition。

语法

insert file -c (text) [-p (text)] [-t (text)] <file_path>

选项

选项全名说明
-c-collection-名称插入数据的 Collection 名称。
-p-Partition(可选)插入数据的 Partition 名称。不通过此 Partition 选项表示选择"_默认 "Partition。
-t-超时(可选)可选的 RPC 时长(以秒为单位)。如果未设置超时,客户端将一直等待,直到服务器做出响应或发生错误。
-help不适用显示命令使用帮助。

示例 1

下面的示例导入了一个本地 CSV 文件。

milvus_cli > insert file -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 > insert file -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
-------------------------- ------------------

插入行

向 Collection 插入一行数据。

语法

insert row

交互式示例

milvus_cli > insert row

Collection name: car
Partition name [_default]: _default
Enter value for id (INT64): 1
Enter value for vector (FLOAT_VECTOR): [1.0, 2.0, 3.0]
Enter value for color (INT64): 100
Enter value for brand (VARCHAR): Toyota

Inserted successfully.

列出用户

列出所有用户。

语法

list users

选项

| Option | Full name | Description | | --help | n/a | 显示命令使用帮助。|

列出角色

列出 Milvus 中的角色

语法

list roles

选项

选项全名说明
-帮助不适用显示命令使用帮助。

示例

milvus_cli > list roles

列出拨款

列出 Milvus 中的授权

选项

选项全称说明
-r-角色名称milvus 角色的角色名称。
-o-对象名称milvus 对象的对象名称。
-t-对象类型全局、Collection 或用户。
-帮助不适用显示命令使用帮助。

示例

milvus_cli > list grants -r role1 -o object1 -t Collection

list Collection

列出所有 Collection。

语法

shell list collections

选项

| 选项 | 全名 | 说明 | | --- | --- | --- | | -帮助 | 不适用 | 显示命令使用帮助。 |

列出索引

列出 Collection 的所有索引。

说明

目前,一个 Collection 最多支持一个索引。

语法

list indexes -c (text)

选项

选项全名说明
-c-Collection-名称Collection 的名称。
-帮助不适用显示命令使用帮助。

列出 Partition

列出 Collection 的所有 Partition。

语法

list partitions -c (text)

选项

选项全名说明
-c-Collection-名称Collection 的名称。
-帮助不适用显示命令使用帮助。

加载

将一个 Collection 或 Partition 从硬盘空间加载到 RAM。

语法

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

选项

选项全名说明
-c-Collection-名称Partition 所属 Collection 的名称。
-p-Partition(可选/多个)Partition 的名称。
-help不适用显示命令使用帮助。

查询

显示符合所有输入条件的查询结果。

语法

query

交互式 示例

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]:

释放

从 RAM 中释放一个 Collection 或 Partition。

语法

release collection -c (text) [-p (text)]

选项

选项全名说明
-c-Collection-名称Partition 所属 Collection 的名称。
-p-Partition(可选/多个)Partition 的名称。
-help不适用显示命令使用帮助。

执行向量相似性搜索或混合搜索。

search
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): 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]:

列出连接

列出连接。

语法

list connections

选项

选项全名说明
-帮助不适用显示命令使用帮助。

show index_progress

显示实体索引的进度。

语法

show index_progress -c (text) [-i (text)]

选项

选项全名说明
-c-Collection-名称实体所属 Collection 的名称。
-i-索引(可选)索引名称。
-help不适用显示命令使用帮助。

显示加载进度

显示 Collection 的加载进度。

语法

show loading_progress -c (text) [-p (text)]

选项

选项全称说明
-c-Collection-名称实体所属 Collection 的名称。
-p-Partition(可选/多个)加载 Partition 的名称。
-help不适用显示命令使用帮助。

版本

显示 Milvus_CLI 的版本。

语法

version

选项

选项全称说明
-帮助不适用显示命令使用帮助。
说明

也可以在 shell 中检查 Milvus_CLI 的版本,如下例所示。在这种情况下,milvus_cli --version 充当命令。

示例

$ milvus_cli --version
Milvus_CLI v0.4.0