milvus.client package

Submodules

milvus.client.abstract module

class milvus.client.abstract.ConnectIntf[source]

Bases: object

SDK client abstract class

Connection is a abstract class

add_vectors(table_name, records, ids, timeout, **kwargs)[source]

Add vectors to table Should be implemented

Parameters
  • table_name (str) -- table name been inserted

  • records (list[RowRecord]) -- list of vectors been inserted

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

  • timeout (int) --

Returns

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

client_version()[source]

Provide client version should be implemented

Returns

Status: indicate if operation is successful

str : Client version

Return type

(Status, str)

connect(host, port, uri, timeout)[source]

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

Parameters
  • host (str) -- host

  • port (str) -- port

  • uri (str) -- (Optional) uri

  • timeout (int) --

Returns

Status, indicate if connect is successful

connected()[source]

connected, connection status Should be implemented

Returns

Status, indicate if connect is successful

create_index(table_name, index, timeout)[source]

Create specified index in a table should be implemented

Parameters
  • table_name (str) --

    table name

    type index

    dict

  • index --

    index information dict

    example: index = {

    "index_type": IndexType.FLAT, "nlist": 18384

    }

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

Returns

Status: indicate if this operation is successful

Return type

Status

create_table(param, timeout)[source]

Create table Should be implemented

Parameters
  • param (TableSchema) -- provide table information to be created

  • timeout (int) --

Returns

Status, indicate if connect is successful

delete_table(table_name, timeout)[source]

Delete table Should be implemented

Parameters
  • table_name (str) -- table_name of the deleting table

  • timeout (int) --

Returns

Status, indicate if connect is successful

describe_index(table_name, timeout)[source]

Show index information should be implemented

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

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

Returns

Status: indicate if operation is successful

TableSchema: table detail information

Return type

(Status, TableSchema)

describe_table(table_name, timeout)[source]

Show table information Should be implemented

Parameters
  • table_name (str) -- which table to be shown

  • timeout (int) --

Returns

Status: indicate if query is successful table_schema: TableSchema, given when operation is successful

disconnect()[source]

Disconnect, server will be disconnected after disconnect return SUCCESS Should be implemented

Returns

Status, indicate if connect is successful

drop_index(table_name, timeout)[source]

Show index information should be implemented

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

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

Returns

Status: indicate if operation is successful

::rtype: Status

get_table_row_count(table_name, timeout)[source]

Get table row count Should be implemented

:type table_name, str :param table_name, target table name.

Parameters

timeout (int) -- how many similar vectors will be searched

Returns

Status: indicate if operation is successful count: int, table row count

has_table(table_name, timeout)[source]

This method is used to test table existence. Should be implemented

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

  • timeout (int) --

Returns

has_table: bool, if given table_name exists

preload_table(table_name, timeout)[source]

load table to memory cache in advance should be implemented

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

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

Returns

Status: indicate if operation is successful

::rtype: Status

search_vectors(table_name, top_k, nprobe, query_records, query_ranges, **kwargs)[source]

Query vectors in a table Should be implemented

Parameters
  • table_name (str) -- table name been queried

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

  • query_ranges (list[Range]) -- Optional ranges for conditional search. If not specified, search whole table

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

Returns

Status: indicate if query is successful query_results: list[TopKQueryResult]

search_vectors_in_files(table_name, file_ids, query_records, top_k, nprobe, query_ranges, **kwargs)[source]

Query vectors in a table, query vector in specified files Should be implemented

Parameters
  • table_name (str) -- table name been queried

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

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

  • query_ranges (list[Range]) -- Optional ranges for conditional search. If not specified, search whole table

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

Returns

Status: indicate if query is successful query_results: list[TopKQueryResult]

server_status(timeout)[source]

Provide server status. When cmd !='version', provide 'OK' should be implemented

Parameters

timeout (int) -- how many similar vectors will be searched

Returns

Status: indicate if operation is successful

str : Server version

Return type

(Status, str)

server_version(timeout)[source]

Provide server version should be implemented

Parameters

timeout (int) -- how many similar vectors will be searched

Returns

Status: indicate if operation is successful

str : Server version

Return type

(Status, str)

show_tables(timeout)[source]

Show all tables in database should be implemented

Parameters

timeout (int) -- how many similar vectors will be searched

Returns

Status: indicate if this operation is successful tables: list[str], list of table names

class milvus.client.abstract.IndexParam(table_name, index_type, nlist)[source]

Bases: object

Index Param

Parameters
  • table_name (str) -- (Required) name of table

  • index_type (IndexType) --

    (Required) index type, default = IndexType.INVALID

    IndexType: 0-invalid, 1-flat, 2-ivflat, 3-IVF_SQ8, 4-MIX_NSG

  • nlist (int64) -- (Required) num of cell

class milvus.client.abstract.QueryResult(_id, _distance)[source]

Bases: object

class milvus.client.abstract.Range(start_date, end_date)[source]

Bases: object

Range information

Parameters
  • start_date -- Range start date

  • end_date -- Range end date

class milvus.client.abstract.RowQueryResult(_id_list, _dis_list)[source]

Bases: object

class milvus.client.abstract.TableSchema(table_name, dimension, index_file_size, metric_type)[source]

Bases: object

class milvus.client.abstract.TopKQueryResult(raw_source, **kwargs)[source]

Bases: object

TopK query results, shown as 2-D array

This Class unpack response from server, store ids and distances separately.

property distance_array

Distance array, it's a 2-D array

property id_array

Id array, it's a 2-D array.

property raw

getter. return the raw result response

property shape

getter. return result shape, format as (row, column).

milvus.client.exceptions module

exception milvus.client.exceptions.ConnectError[source]

Bases: ValueError

Connect server failed

exception milvus.client.exceptions.NotConnectError[source]

Bases: milvus.client.exceptions.ConnectError

Disconnect error

exception milvus.client.exceptions.ParamError[source]

Bases: ValueError

Param of interface is illegal

exception milvus.client.exceptions.RepeatingConnectError[source]

Bases: milvus.client.exceptions.ConnectError

Try to connect repeatedly

milvus.client.grpc_client module

class milvus.client.grpc_client.GrpcMilvus[source]

Bases: milvus.client.abstract.ConnectIntf

add_vectors(table_name, records, ids=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

  • 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=3)[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

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

  • 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=300)[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, **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 -- query data range

: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

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, **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 -- query data range

: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

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)

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

milvus.client.types module

class milvus.client.types.IndexType[source]

Bases: enum.IntEnum

An enumeration.

FLAT = 1
INVALID = 0
IVFLAT = 2
IVF_FLAT = 2
IVF_SQ8 = 3
IVF_SQ8H = 5
IVF_SQ8_H = 5
MIX_NSG = 4
class milvus.client.types.MetricType[source]

Bases: enum.IntEnum

An enumeration.

IP = 2
L2 = 1
class milvus.client.types.Status(code=0, message='Success')[source]

Bases: object

Attribute code

int (optional) default as ok

Attribute message

str (optional) current status message

BUILD_INDEX_ERROR = 21
CACHE_FAILED = 16
CANNOT_CREATE_FILE = 18
CANNOT_CREATE_FOLDER = 17
CANNOT_DELETE_FILE = 20
CANNOT_DELETE_FOLDER = 19
CONNECT_FAILED = 2
FILE_NOT_FOUND = 14
ILLEGAL_ARGUMENT = 5
ILLEGAL_DIMENSION = 7
ILLEGAL_INDEX_TYPE = 8
ILLEGAL_METRIC_TYPE = 23
ILLEGAL_NLIST = 22
ILLEGAL_RANGE = 6
ILLEGAL_ROWRECORD = 11
ILLEGAL_SEARCH_RESULT = 13
ILLEGAL_TABLE_NAME = 9
ILLEGAL_TOPK = 10
ILLEGAL_VECTOR_ID = 12
META_FAILED = 15
OK()[source]
OUT_OF_MEMORY = 24
PERMISSION_DENIED = 3
SUCCESS = 0
TABLE_NOT_EXISTS = 4
UNEXPECTED_ERROR = 1

milvus.client.utils module

milvus.client.utils.check_pass_param(*args, **kwargs)[source]
milvus.client.utils.int_or_str(item)[source]
milvus.client.utils.is_correct_date_str(param)[source]
milvus.client.utils.parser_range_date(date)[source]

Module contents

client module