Skip to main content

Python Sdk for Milvus; Test version

Project description

Milvus Python SDK -- pymilvus

version 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

[Note] It's NOT recommended to upgrade to higher version if you are still using milvus-0.3.0

If you want to upgrade pymilvus to newest version

$ pip install --upgrade pymilvus

Import

from milvus import Milvus, IndexType, Status

Getting started

Initial a Milvus instance and connect to the sever

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

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

>>> param = {'table_name':'test01', 'dimension':256, 'index_type':IndexType.FLAT, 'store_raw_vector':False}

Then create table

>>> milvus.create_table(param)
Status(message='Table test01 created!', code=0)

Describe the table we just created

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

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

# create 5 vectors of 256-dimension
>>> q_records = [[random.random() for _ in range(dim)] for _ in range(5)]

Then get results

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

>>> milvus.delete_table(table_name='test01')
Status(code=0, message='Success')

Disconnect with the server

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

milvus-test-0.1.1.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

milvus_test-0.1.1-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file milvus-test-0.1.1.tar.gz.

File metadata

  • Download URL: milvus-test-0.1.1.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.9

File hashes

Hashes for milvus-test-0.1.1.tar.gz
Algorithm Hash digest
SHA256 85f9ebc1bfabd58f0fee6466fe156be784c86d9bca754d7e8b4ad38117623e81
MD5 aae0f74fb400bef63208b8c3465d5c8d
BLAKE2b-256 bd374f9722fa70549077ffd30273af98ebfce5de2beaf03bd27aabda72869d68

See more details on using hashes here.

File details

Details for the file milvus_test-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: milvus_test-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.9

File hashes

Hashes for milvus_test-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0ddd03b3ba30f198acd32e3c2896171e384fe8694f704d439cd9bac23da2a6c
MD5 7f02861c2a9331371fb6ad8a2b1e9d67
BLAKE2b-256 d1e4fdf16bebdb9117b5f1c5a37b0bc463719bbf006618f462ffb4dd4de742d1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page