Skip to main content

Python Sdk for Milvus

Project description

Milvus Python SDK

Using Milvus python sdk for Milvus

Download

$ pip install pymilvus

Import

from milvus import Milvus, Prepare, IndexType

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()
0.0.0  # this is example version, the real version may vary

Add a new table

First using Prepare to create param

>>> param = Prepare.table_schema(table_name='test01', dimension=256, index_type=IndexType.IDMAP,
                                    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 Prepare binary vectors of 256-dimension.

  • Note that random, struct and pprint we used here is for creating fake vectors data and pretty print, you may not need them in your project
>>> import random
>>> import struct
>>> from pprint import pprint

>>> dim = 256  # Dimension of the vector

# Initialize 20 binary vectors of 256-dimension
>>> vectors = [Prepare.row_record(struct.pack(str(dim)+'d', *[random.random()for _ in range(dim)]))
            for _ in range(20)]

# This is example of creating vectors, you can use your own binary data as below
# records = [Prepare.row_record(ONE_BINARY_ARRAY) for ONE_BINARY_ARRAY in YOU_OWN_BINARY_ARRAYS]

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

First create 5 binary vectors of 256-dimension

>>> q_records = [Prepare.row_record(struct.pack(str(dim) + 'd', *[random.random() for _ in range(dim)]))
                 for _ in range(5)]

# This is example of creating vectors, you can use your own binary data as below
# records = [Prepare.row_record(ONE_BINARY_ARRAY) for ONE_BINARY_ARRAY in YOU_OWN_BINARY_ARRAYS]

Then search vectors:

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

Disconnect with the server

>>> milvus.disconnect()
Status(code=0, message='Success')

There is a small example in examples/example.py, 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 add new issues

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymilvus-0.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file pymilvus-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pymilvus-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 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.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

File hashes

Hashes for pymilvus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d1dd991c2a5ae3d8a9713861a1dd7fafba2fccf0e7c1b6beec0ecd5fad95136
MD5 ea1110f1c13f692e8db98ad30e6ce254
BLAKE2b-256 774b15a8a16842560f6fc3f1332ffb14d2840aa046513203fca0d5b83a85190c

See more details on using hashes here.

Supported by

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