跳到主要内容

Milvus_CLI 命令参考

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

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

命令组

Milvus CLI 命令组织成以下几组:

  • create:创建 collection、database、partition、user、role 或 index
  • delete:删除 collection、database、partition、alias、user、role 或 index
  • list:列出 collection、database、partition、user、role、grant 或 index
  • show:显示连接、database、collection、loading_progress 或 index_progress
  • grant:授予 role 或权限
  • revoke:撤销 role 或权限
  • load:加载 collection 或 partition
  • release:释放 collection 或 partition
  • use:使用 database
  • rename:重命名 collection
  • insert:插入实体(文件或行)

clear

清除屏幕。

语法

clear

选项

选项全名描述
--helpn/a显示使用命令的帮助信息。

connect

连接到 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--token(可选)Zilliz Cloud API 密钥或 username:password。默认为 None。
-tls--tlsmode(可选)设置 TLS 模式:0(无加密)、1(单向加密)、2(双向加密,暂不支持)。默认为 0
-cert--cert(可选)客户端证书文件的路径。与单向加密配合使用
--helpn/a显示使用命令的帮助信息。

示例

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

create Database

在 Milvus 中创建 Database

语法

create database -db (text)

选项

选项全名描述
-db--db_name[必需] Milvus 中的 database 名称。
--helpn/a显示使用命令的帮助信息。

示例

示例 1

以下示例在 Milvus 中创建 database testdb

milvus_cli > create database -db testdb

use Database

在 Milvus 中使用 Database

语法

use database -db (text)

选项

选项全名描述
-db--db_name[必需] Milvus 中的 database 名称。
--helpn/a显示使用命令的帮助信息。

示例

示例 1

以下示例在 Milvus 中使用 database testdb

milvus_cli > use database -db testdb

list Databases

列出 Milvus 中的 Database

语法

list databases

示例

示例 1

以下示例列出 Milvus 中的 database。

milvus_cli > list databases

delete Database

在 Milvus 中删除 Database

语法

delete database -db (text)

选项

选项全名描述
-db--db_name[必需] Milvus 中的 database 名称。
--helpn/a显示使用命令的帮助信息。

示例

示例 1

以下示例删除 Milvus 中的 database 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

create user

在 Milvus 中创建用户

语法

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

选项

选项全名描述
-p--passwordMilvus 中的用户密码。默认为 "None"。
-u--usernameMilvus 中的用户名。默认为 "None"。
--helpn/a显示使用命令的帮助信息。

示例

示例 1

以下示例在 Milvus 中创建用户 zilliz 和密码 zilliz

milvus_cli > create user -u zilliz -p zilliz

create role

在 Milvus 中创建 role

语法

create role -r (text)

选项

选项全名描述
-r--roleNameMilvus role 的 role 名称。
--helpn/a显示使用命令的帮助信息。

示例

示例 1

以下示例在 Milvus 中创建 role role1

milvus_cli > create role -r role1

create alias

为 collection 指定唯一的别名。

一个 collection 可以有多个别名。但是,一个别名最多对应一个 collection。

语法

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

选项

选项全名描述
-c--collection-nameCollection 的名称。
-a--alias-name别名。
-A--alter(可选)将别名转移到指定 collection 的标志。
--helpn/a显示使用命令的帮助信息。

示例

示例 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

create 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

create partition

创建 partition。

语法

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

选项

选项全名描述
-c--collection-nameCollection 的名称。
-p--partitionPartition 名称。
-d--description(可选)Partition 的描述。
--helpn/a显示使用命令的帮助信息。

示例

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

create index

为字段创建索引。

目前,一个 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

删除用户

语法

delete user -u (text)

选项

选项全名描述
-u--username用户名。
--helpn/a显示使用命令的帮助信息。

示例

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

delete role

在 Milvus 中删除 role

语法

delete role -r (text)

选项

选项全名描述
-r--roleNameMilvus role 的 role 名称。
--helpn/a显示使用命令的帮助信息。

示例

以下示例删除 Milvus 中的 role role1

milvus_cli > delete role -r role1

delete alias

删除别名。

语法

delete alias -a (text)

选项

选项全名描述
-a--alias-name别名。
--helpn/a显示使用命令的帮助信息。

delete collection

删除 collection。

语法

delete collection -c (text)

选项

选项全名描述
-c--collection-name要删除的 collection 名称。
--helpn/a显示使用命令的帮助信息。

示例

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

删除实体。

语法

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

选项

选项全名描述
-c--collection-name要删除实体所属的 collection 名称。
-p--partition(可选)要删除的 partition 名称。
--helpn/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 ]

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

delete partition

删除 partition。

语法

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

选项

选项全名描述
-c--collection-name要删除的 partition 所属的 collection 名称。
-p--partition要删除的 partition 名称。
--helpn/a显示使用命令的帮助信息。

示例

milvus_cli > delete partition -c car -p new_partition

delete index

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

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

语法

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

选项

选项全名描述
-c--collection-nameCollection 的名称。
-in--index-name索引名称。
--helpn/a显示使用命令的帮助信息。

示例

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

向用户授予 role

语法

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

选项

选项全名描述
-r--roleNameMilvus role 的 role 名称。
-u--usernameMilvus 用户的用户名。
--helpn/a显示使用命令的帮助信息。

示例

milvus_cli > grant role -r role1 -u user1

grant privilege

向 role 分配权限。

语法

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

撤销分配给用户的 role。

语法

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

选项

选项全名描述
-r--roleNameMilvus role 的 role 名称。
-u--usernameMilvus 用户的用户名。
--helpn/a显示使用命令的帮助信息。

示例

milvus_cli > revoke role -r role1 -u user1

revoke privilege

撤销已分配给 role 的权限。

语法

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

show collection

显示 collection 的详细信息。

语法

show collection -c (text)

选项

选项全名描述
-c--collection-nameCollection 的名称。
--helpn/a显示使用命令的帮助信息。

示例

milvus_cli > show collection -c test_collection_insert

show partition

显示 partition 的详细信息。

语法

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

选项

选项全名描述
-c--collection-namePartition 所属的 collection 名称。
-p--partitionPartition 的名称。
--helpn/a显示使用命令的帮助信息。

示例

milvus_cli > show partition -c test_collection_insert -p _default

show index

显示索引的详细信息。

语法

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

选项

选项全名描述
-c--collection-nameCollection 的名称。
-in--index-name索引的名称。
--helpn/a显示使用命令的帮助信息。

示例

milvus_cli > show index -c test_collection -in index_name

exit

关闭命令行窗口。

语法

exit

选项

选项全名描述
--helpn/a显示使用命令的帮助信息。

help

显示使用命令的帮助信息。

语法

help <command>

命令

命令描述
clear清除屏幕。
connect连接到 Milvus。
create创建 collection、database、partition、user、role 和 index。
grant授予 role、权限。
revoke撤销 role、权限。
delete删除 collection、database、partition、alias、user、role 或 index。
exit关闭命令行窗口。
help显示使用命令的帮助信息。
insert将数据导入 partition。
list列出 collection、database、partition、user、role、grant 或 index。
load加载 collection 或 partition。
query显示符合您输入的所有条件的查询结果。
release释放 collection 或 partition。
search执行向量相似性搜索或混合搜索。
show显示连接、database、collection、loading_progress 或 index_progress。
rename重命名 collection
use使用 database
version显示 Milvus_CLI 的版本。

insert

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

语法

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

选项

选项全名描述
-c--collection-name数据要插入的 collection 名称。
-p--partition(可选)数据要插入的 partition 名称。不传递此 partition 选项表示选择 "_default" partition。
-t--timeout(可选)允许 RPC 的可选持续时间(秒)。如果未设置超时,客户端将持续等待直到服务器响应或发生错误。
--helpn/a显示使用命令的帮助信息。

示例 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
-------------------------- ------------------

insert row

向 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

列出所有用户。

语法

list users

选项

| 选项 | 全名 | 描述 | | --help | n/a | 显示使用命令的帮助信息。 |

List roles

列出 Milvus 中的 role

语法

list roles

选项

选项全名描述
--helpn/a显示使用命令的帮助信息。

示例

milvus_cli > list roles

List grants

列出 Milvus 中的授权

选项

选项全名描述
-r--roleNameMilvus role 的 role 名称。
-o--objectNameMilvus 对象的对象名称。
-t--objectTypeGlobal、Collection 或 User。
--helpn/a显示使用命令的帮助信息。

示例

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

list collections

列出所有 collection。

语法

list collections

选项

选项全名描述
--helpn/a显示使用命令的帮助信息。

list indexes

列出一个 collection 的所有索引。

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

语法

list indexes -c (text)

选项

选项全名描述
-c--collection-nameCollection 的名称。
--helpn/a显示使用命令的帮助信息。

list partitions

列出一个 collection 的所有 partition。

语法

list partitions -c (text)

选项

选项全名描述
-c--collection-nameCollection 的名称。
--helpn/a显示使用命令的帮助信息。

load

将 collection 或 partition 从硬盘空间加载到内存中。

语法

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

选项

选项全名描述
-c--collection-namePartition 所属的 collection 名称。
-p--partition(可选/多个)Partition 名称。
--helpn/a显示使用命令的帮助信息。

query

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

语法

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

release

从内存中释放 collection 或 partition。

语法

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

选项

选项全名描述
-c--collection-namePartition 所属的 collection 名称。
-p--partition(可选/多个)Partition 名称。
--helpn/a显示使用命令的帮助信息。

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

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

列出连接。

语法

list connections

选项

选项全名描述
--helpn/a显示使用命令的帮助信息。

show index_progress

显示实体索引的进度。

语法

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

选项

选项全名描述
-c--collection-name实体所属的 collection 名称。
-i--index(可选)索引名称。
--helpn/a显示使用命令的帮助信息。

show loading_progress

显示加载 collection 的进度。

语法

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

选项

选项全名描述
-c--collection-name实体所属的 collection 名称。
-p--partition(可选/多个)加载的 partition 名称。
--helpn/a显示使用命令的帮助信息。

version

显示 Milvus_CLI 的版本。

语法

version

选项

选项全名描述
--helpn/a显示使用命令的帮助信息。
您也可以在 shell 中检查 Milvus_CLI 的版本,如下面的示例所示。在这种情况下,milvus_cli --version 作为命令。

示例

$ milvus_cli --version
Milvus_CLI v0.4.0