# Milvus Python SDK -- pymilvus
[![version](https://img.shields.io/pypi/v/pymilvus.svg?color=blue)](https://pypi.org/project/pymilvus/)
[![license](https://img.shields.io/hexpm/l/plug.svg?color=green)](https://github.com/milvus-io/pymilvus/blob/master/LICENSE)
Using Milvus python sdk for Milvus
Download
---
Pymilvus only supports `python >= 3.4`, is fully tested under 3.4, 3.5, 3.6, 3.7.
Pymilvus can be downloaded using `pip`. If no use, try `pip3`
```$
$ pip install pymilvus
```
If you are using `milvus-0.3.0`, last version that supports `milvus-0.3.0` is `0.1.13`, you can download by:
```$
$ pip install pymilvus==0.1.13
```
<span style="color:red">**[Note]** It's NOT recommended to upgrade to higher version if you are still using `milvus-0.3.0`</span>
If you want to upgrade `pymilvus` to newest version
```$
$ pip install --upgrade pymilvus
```
## Import
```python
from milvus import Milvus, IndexType, Status
```
## Getting started
Initial a `Milvus` instance and `connect` to the sever
```python
>>> milvus = Milvus()
>>> milvus.connect(host='SERVER-HOST', port='SERVER-PORT')
Status(code=0, message="Success")
```
Once successfully connected, you can get the version of server
```python
>>> milvus.server_version()
(Status(code=0, message='Success'), 0.3.1) # this is example version, the real version may vary
```
---
Add a new `table`
First set param
```python
>>> param = {'table_name':'test01', 'dimension':256, 'index_type':IndexType.FLAT, 'store_raw_vector':False}
```
Then `create table`
```python
>>> milvus.create_table(param)
Status(message='Table test01 created!', code=0)
```
Describe the table we just created
```python
>>> milvus.describe_table('test01')
(Status(code=0, message='Success!'), TableSchema(table_name='test01',dimension=256, index_type=1, store_raw_vector=False))
```
---
Add vectors into table `test01`
First create 20 vectors of 256-dimension.
- Note that `random` and `pprint` we used here is for creating fake vectors data and pretty print, you may not need them in your project
```python
>>> import random
>>> from pprint import pprint
>>> dim = 256 # Dimension of the vector
# Initialize 20 vectors of 256-dimension
>>> fake_vectors = [[random.random() for _ in range(dim)] for _ in range(20)]
```
Then add vectors into table `test01`
```python
>>> status, ids = milvus.add_vectors(table_name='test01', records=vectors)
>>> print(status)
Status(code=0, message='Success')
>>> pprint(ids) # List of ids returned
23455321135511233
12245748929023489
...
```
---
Search vectors
```python
# create 5 vectors of 256-dimension
>>> q_records = [[random.random() for _ in range(dim)] for _ in range(5)]
```
Then get results
```python
>>> status, results = milvus.search_vectors(table_name='test01', query_records=q_records, top_k=10)
>>> print(status)
Status(code=0, message='Success')
>>> pprint(results) # Searched top_k vectors
```
---
Delet the table we just created
```python
>>> milvus.delete_table(table_name='test01')
Status(code=0, message='Success')
```
Disconnect with the server
```python
>>> milvus.disconnect()
Status(code=0, message='Success')
```
---
## Example python
There are some small examples in `examples/`, you can find more guide there.
Build docs
```$
$ sphinx-build -b html doc/en/ doc/en/build
```
If you encounter any problems or bugs, please open new issues
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共21个文件
py:13个
txt:4个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:milvus-test-0.1.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
milvus-test-0.1.0.tar.gz (21个子文件)
milvus-test-0.1.0
PKG-INFO 5KB
milvus_test.egg-info
PKG-INFO 5KB
requires.txt 7B
SOURCES.txt 489B
top_level.txt 7B
dependency_links.txt 1B
milvus
client
utils.py 1KB
Exceptions.py 250B
Client.py 27KB
__init__.py 20B
Status.py 1KB
Abstract.py 10KB
__init__.py 157B
settings.py 2KB
thrift
constants.py 366B
ttypes.py 21KB
__init__.py 51B
MilvusService.py 97KB
setup.cfg 38B
setup.py 764B
README.md 3KB
共 21 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功