milvus-cli安装部署
环境:
OS:Centos 7
milvus:2.3.5
milvus-cli:1.0.0
1.在线安装
你可以使用 Python 包管理在线安装,注意 Python 版本要在 3.9 以上。在线安装只需要一条命令即可:
[root@host134 bin]# pip -V
pip 23.0.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
[root@host134 bin]# pip install milvus-cli
ERROR: Ignored the following versions that require a different python version: 2.1.0 Requires-Python >=3.9; 2.1.0rc0 Requires-Python >=3.9; 2.1.1 Requires-Python >=3.9; 2.1.2 Requires-Python >=3.9; 2.1.3 Requires-Python >=3.9; 2.1.4 Requires-Python >=3.9; 2.2.0 Requires-Python >=3.9; 2.2.0rc0 Requires-Python >=3.9; 2.2.1 Requires-Python >=3.9; 2.2.2 Requires-Python >=3.9
ERROR: Could not find a version that satisfies the requirement grpcio==1.37.1 (from pymilvus) (from versions: none)
ERROR: No matching distribution found for grpcio==1.37.1
这里需要安装python 3.9以上版本
[root@host134 Python-3.9.19]# python -V
Python 3.9.19
[root@host134 Python-3.9.19]# which milvus_cli
/usr/local/bin/milvus_cli
2.登录milvus
[root@host134 Python-3.9.19]# milvus_cli
__ __ _ _ ____ _ ___
| \/ (_) |_ ___ _ ___ / ___| | |_ _|
| |\/| | | \ \ / / | | / __| | | | | | |
| | | | | |\ V /| |_| \__ \ | |___| |___ | |
|_| |_|_|_| \_/ \__,_|___/ \____|_____|___|
Milvus cli version: 1.0.0
Pymilvus version: 2.4.3
Learn more: https://github.com/zilliztech/milvus_cli.
milvus_cli >
连接到服务器
milvus_cli > connect -uri http://192.168.1.134:19530 -t root:Milvus
Connect Milvus successfully.
+---------+---------------------+
| Address | 192.168.1.134:19530 |
| Alias | default |
+---------+---------------------+
milvus_cli > list databases
+---------+
| db_name |
+---------+
| default |
| db_test |
+---------+
milvus_cli > use database -db db_test
Using database db_test successfully!
milvus_cli > use database -db default
Using database default successfully!
milvus_cli > list collections
['mytest', 'hello_milvus']
##创建数据库
milvus_cli > create database -db db_hxl
Create database db_hxl successfully!
milvus_cli > list databases
+---------+
| db_name |
+---------+
| db_test |
| db_hxl |
| default |
+---------+
3.创建集合
milvus_cli > use database -db db_hxl
Using database db_hxl successfully!
milvus_cli > create collection --help
Usage: milvus_cli create collection [OPTIONS]
Create collection.
Example:
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'
Options:
-c, --collection-name TEXT Collection name to specify alias.
-p, --schema-primary-field TEXT
Primary field name.
-A, --schema-auto-id [Optional, Flag] - Enable auto id.
-desc, --schema-description TEXT
[Optional] - Description details.
-d, --is-dynamic TEXT [Optional] - Collection schema supports
dynamic fields or not.
-level, --consistency-level TEXT
[Optional] - Consistency level:
Bounded,Session,Strong, Eventual .
-f, --schema-field TEXT [Multiple] - FieldSchema. Usage is
"<Name>:<DataType>:<Dim(if vector) or
Description>", Array Type is <Name>:<DataTyp
e>:<MaxCapacity>:<ElementDataType>(:<MaxLeng
th>if Varchar)
-s, --shards-num INTEGER [Optional] - Shards number
--help Show this message and exit.
-c:集合名称
-f:自动名称,多个字段指定多个-f
-p:指定主键字段
-A:启用自增长ID
-desc:集合描述
-d: --is-dynamic TEXT
create collection -c tb_car01 -f id01:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:INT64:brand -p id01 -d 'aaaa'
create collection -c tb_car02 -f id01:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:INT64:brand -p id01 -A -d 'bbbb'
create collection -c tb_car03 -f id01:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:INT64:brand -p id01 -A -desc 'kkkkk'
######################################常用命令##################################
0.查看集合
milvus_cli > list collections
1.查看某个集合下的分区
milvus_cli > list partitions -c xdm_vacc_code_v2
2.查看某个集合下的索引
milvus_cli > list indexes -c xdm_vacc_code
4.查看集合的加载进度
milvus_cli > show loading_progress -c xdm_vacc_code
5.查看索引的进度
milvus_cli > show index_progress -c xdm_vacc_code
{'total_rows': 132, 'indexed_rows': 132, 'pending_index_rows': 0}
6.释放某个集合
release collection -c xdm_vacc_code
7.加载某个集合
load collection -c xdm_vacc_code
8.query
milvus_cli > query
Collection name (CEC_Corpus, CEC_Corpus_bak): CEC_Corpus
The query expression:id==0 ##表达式,这里的表达式只能是如下的几种
The query expression only accepts "<field_name> <oprator in ['<', '<=', '>', '>=', '==', '!=', 'in']> [<value>, ...]"!
Fields to return(split by "," if multiple) ['id', 'text', 'embedding'] []: id,text,embedding ##查询的字段,字段不要带单引号
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]: