pymilvus

Example

You can find a example script in example.py.

Module Contents

Version

Get version of pymilvus by Milvus.__version__.

Client

milvus.Milvus

alias of milvus.client.grpc_client.GrpcMilvus

class milvus.client.grpc_client.GrpcMilvus(host=None, port=None, **kwargs)[source]

Bases: milvus.client.abstract.ConnectIntf

add_vectors(table_name, records, ids=None, partition_tag=None, timeout=-1, **kwargs)

Add vectors to table

Parameters
  • ids (list[int]) -- list of id

  • table_name (str) -- table name been inserted

  • records -- list of vectors been inserted

  • partition_tag (str or None. If partition_tag is None, vectors will be inserted into table rather than partitions.) -- the tag string of table

:type

Parameters

timeout (int) -- time waiting for server response

Returns

Status: indicate if vectors inserted successfully ids: list of id, after inserted every vector is given a id

Return type

(Status, list(int))

client_version()[source]

Provide client version

Returns

version: Client version

Return type

(str)

connect(host=None, port=None, uri=None, timeout=1)[source]

Connect method should be called before any operations. Server will be connected after connect return OK

Parameters
  • host (str) -- (Optional) host of the server, default host is 127.0.0.1

  • port (str) -- (Optional) port of the server, default port is 19530

  • uri (str) --

    (Optional) only support tcp proto now, default uri is

    tcp://127.0.0.1:19530

  • timeout (float) -- (Optional) connection timeout, default timeout is 3000ms

Returns

Status, indicate if connect is successful

Return type

Status

Raises

NotConnectError

connected()[source]

Check if client is connected to the server

Returns

if client is connected

Return type

bool

count_table(table_name, timeout=30)[source]

obtain vector number in table

Parameters

table_name (str) -- target table name.

Returns

Status: indicate if operation is successful

res: int, table row count

create_index(table_name, index=None, timeout=-1)[source]

build vectors of specific table and create vector index

Parameters
  • table_name (str) -- table used to crete index.

  • index -- index params

  • timeout (int) --

    grpc request timeout.

    if timeout = -1, method invoke a synchronous call, waiting util grpc response else method invoke a asynchronous call, timeout work here

Returns

Status, indicate if operation is successful

create_partition(table_name, partition_name, partition_tag, timeout=10)[source]

create a specific partition under designated table. After done, the meta file in milvus server update partition information, you can perform actions about partitions with partition tag.

param table_name

target table name.

type table_name

str

param partition_name

name of target partition under designated table.

type partition_name

str

param partition_tag

tag name of target partition under designated table.

type partition_tag

str

param timeout

time waiting for response.

type timeout

int

Returns

Status: indicate if operation is successful

create_table(param, timeout=10)[source]

Create table

Parameters
  • param (dict or TableSchema) --

    Provide table information to be created

    `example param={'table_name': 'name',

    'dimension': 16, 'index_file_size': 1024 (default), 'metric_type': Metric_type.L2 (default) }`

    OR using Prepare.table_schema to create param

  • timeout (double) -- timeout, The unit is seconds

Returns

Status, indicate if operation is successful

Return type

Status

delete_table(table_name, timeout=20)

Delete table with table_name

Parameters

table_name (str) -- Name of the table being deleted

Returns

Status, indicate if operation is successful

Return type

Status

describe_index(table_name, timeout=10)[source]

Show index information of designated table

Parameters

table_name (str) -- table name been queried

Returns

Status: indicate if query is successful IndexSchema:

describe_table(table_name, timeout=10)[source]

Show table information

Parameters

table_name (str) -- which table to be shown

Returns

(Status, table_schema) Status: indicate if query is successful table_schema: return when operation is successful

Return type

(Status, TableSchema)

disconnect()[source]

Disconnect with the server and distroy the channel

Returns

Status, indicate if disconnect is successful

Return type

Status

drop_index(table_name, timeout=10)[source]

drop index from index file

Parameters

table_name (str) -- target table name.

Returns

Status: indicate if operation is successful

::rtype: Status

drop_partition(table_name, partition_tag, timeout=10)[source]

Drop specific partition under designated table.

Parameters
  • table_name (str) -- target table name.

  • partition_tag (str) -- tag name of specific partition

  • timeout (int) -- time waiting for response.

Returns

Status: indicate if operation is successful

drop_table(table_name, timeout=20)[source]

Delete table with table_name

Parameters

table_name (str) -- Name of the table being deleted

Returns

Status, indicate if operation is successful

Return type

Status

get_table_row_count(table_name, timeout=30)

obtain vector number in table

Parameters

table_name (str) -- target table name.

Returns

Status: indicate if operation is successful

res: int, table row count

has_table(table_name, timeout=10)[source]

This method is used to test table existence.

Parameters
  • table_name (str) -- table name is going to be tested.

  • timeout (int) -- time waiting for server response

Returns

Status: indicate if vectors inserted successfully bool if given table_name exists

insert(table_name, records, ids=None, partition_tag=None, timeout=-1, **kwargs)[source]

Add vectors to table

Parameters
  • ids (list[int]) -- list of id

  • table_name (str) -- table name been inserted

  • records -- list of vectors been inserted

  • partition_tag (str or None. If partition_tag is None, vectors will be inserted into table rather than partitions.) -- the tag string of table

:type

Parameters

timeout (int) -- time waiting for server response

Returns

Status: indicate if vectors inserted successfully ids: list of id, after inserted every vector is given a id

Return type

(Status, list(int))

preload_table(table_name, timeout=None)[source]

Load table to cache in advance

Parameters

table_name (str) -- table to preload

Returns

Status: indicate if invoke is successful

search(table_name, top_k, nprobe, query_records, query_ranges=None, partition_tags=None, **kwargs)[source]

Search similar vectors in designated table

Parameters
  • table_name (str) -- target table name

  • top_k (int) -- number of vertors which is most similar with query vectors

  • nprobe (int) -- cell number of probe

  • query_records (list[list[float32]]) -- vectors to query

  • query_ranges (list) -- query data range

  • partition_tags (list) -- tags to search

:return

Status: indicate if search successfully result: query result

Return type

(Status, TopKQueryResult)

search_in_files(table_name, file_ids, query_records, top_k, nprobe=16, query_ranges=None, **kwargs)[source]

Query vectors in a table, in specified files.

The server store vector data into multiple files if the size of vectors exceeds file size threshold. It is supported to search in several files by specifying file ids. However, these file ids are stored in db in server, and python sdk doesn't apply any APIs get them at client. It's a specific method used in shards. Obtain more detail about milvus shards, see <a href="https://github.com/milvus-io/milvus/tree/0.6.0/shards">

Parameters
  • nprobe (int) --

  • table_name (str) -- table name been queried

  • file_ids (list[str] or list[int]) -- Specified files id array

  • query_records (list[list[float]]) -- all vectors going to be queried

  • query_ranges -- Optional ranges for conditional search. If not specified, search in the whole table

  • top_k (int) -- how many similar vectors will be searched

Returns

Status: indicate if query is successful results: query result

Return type

(Status, TopKQueryResult)

search_vectors(table_name, top_k, nprobe, query_records, query_ranges=None, partition_tags=None, **kwargs)

Search similar vectors in designated table

Parameters
  • table_name (str) -- target table name

  • top_k (int) -- number of vertors which is most similar with query vectors

  • nprobe (int) -- cell number of probe

  • query_records (list[list[float32]]) -- vectors to query

  • query_ranges (list) -- query data range

  • partition_tags (list) -- tags to search

:return

Status: indicate if search successfully result: query result

Return type

(Status, TopKQueryResult)

search_vectors_in_files(table_name, file_ids, query_records, top_k, nprobe=16, query_ranges=None, **kwargs)

Query vectors in a table, in specified files.

The server store vector data into multiple files if the size of vectors exceeds file size threshold. It is supported to search in several files by specifying file ids. However, these file ids are stored in db in server, and python sdk doesn't apply any APIs get them at client. It's a specific method used in shards. Obtain more detail about milvus shards, see <a href="https://github.com/milvus-io/milvus/tree/0.6.0/shards">

Parameters
  • nprobe (int) --

  • table_name (str) -- table name been queried

  • file_ids (list[str] or list[int]) -- Specified files id array

  • query_records (list[list[float]]) -- all vectors going to be queried

  • query_ranges -- Optional ranges for conditional search. If not specified, search in the whole table

  • top_k (int) -- how many similar vectors will be searched

Returns

Status: indicate if query is successful results: query result

Return type

(Status, TopKQueryResult)

property server_address

Server network address

server_status(timeout=10)[source]

Provide server status

Returns

Status: indicate if operation is successful

str : Server version

Return type

(Status, str)

server_version(timeout=10)[source]

Provide server version

Returns

Status: indicate if operation is successful

str : Server version

Return type

(Status, str)

set_hook(**kwargs)[source]

specify client hooks. The client hooks are used in methods which interact with server. Use key-value method to set hooks. Supported hook setting currently is as follow.

search hook, search-in-file hook

show_partitions(table_name, timeout=10)[source]

Show all partitions under designated table.

Parameters
  • table_name (str) -- target table name.

  • timeout (int) -- time waiting for response.

Returns

Status: indicate if operation is successful partition_list:

show_tables(timeout=10)[source]

Show all tables information in database

Returns

Status: indicate if this operation is successful

tables: list of table names, return when operation

is successful

Return type

(Status, list[str])

class milvus.Prepare[source]

Bases: object

classmethod cmd(cmd)[source]
classmethod delete_param(table_name, start_date, end_date)[source]
classmethod index(index_type, nlist)[source]
Parameters
  • index_type (IndexType) -- index type

  • nlist --

Returns

classmethod index_param(table_name, index_param)[source]
classmethod insert_param(table_name, vectors, partition_tag, ids=None)[source]
classmethod partition_param(table_name, partition_name, tag)[source]
classmethod range(start_date, end_date)[source]

Parser a 'yyyy-mm-dd' like str or date/datetime object to Range object

Range: (start_date, end_date]

start_date : '2019-05-25'

Parameters
  • start_date (str, date, datetime) -- start date

  • end_date (str, date, datetime) -- end date

Returns

Range object

classmethod ranges(ranges)[source]

prepare query_ranges

Parameters

ranges -- prepare query_ranges

Returns

list[Range]

classmethod search_param(table_name, topk, nprobe, query_records, query_ranges, partitions)[source]
classmethod search_vector_in_files_param(table_name, query_records, query_ranges, topk, nprobe, ids)[source]
classmethod table_name(table_name)[source]
classmethod table_schema(param)[source]
Parameters

param (dict) --

(Required)

`example param={'table_name': 'name',

'dimension': 16, 'index_file_size': 1024 'metric_type': MetricType.L2 }`

Returns

ttypes.TableSchema object