API reference¶
Client¶
Methods¶
APIs¶
-
class
milvus.
Milvus
(host=None, port=None, handler='GRPC', pool='SingletonThread', **kwargs)¶ -
compact
(collection_name, timeout=None, **kwargs)¶ Compacts segments in a collection. This function is recommended after deleting vectors.
- Parameters
collection_name (str) -- Name of the collections to compact.
-
count_entities
(collection_name, timeout=30)¶ Returns the number of vectors in a collection.
- Parameters
collection_name (str) -- target table name.
- Returns
Status: indicate if operation is successful
res: int, table row count
-
create_collection
(param, timeout=30)¶ Creates a collection.
- Parameters
param (dict) --
Information needed to create a collection.
- `param={'collection_name': 'name',
'dimension': 16, 'index_file_size': 1024 (default), 'metric_type': Metric_type.L2 (default) }`
timeout (double) -- Timeout in seconds.
- Returns
Whether the operation is successful.
- Return type
Status
-
create_index
(collection_name, index_type=None, params=None, timeout=None, **kwargs)¶ Creates index for a collection.
- Parameters
collection_name (str) -- Collection used to create 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
Whether the operation is successful.
-
create_partition
(collection_name, partition_tag, timeout=30)¶ create a partition for a collection.
- Parameters
collection_name (str) -- Name of the collection.
partition_name (str) -- Name of the partition.
partition_tag (str) -- Name of the partition tag.
timeout (int) -- time waiting for response.
- Returns
Status: Whether the operation is successful.
-
delete_entity_by_id
(collection_name, id_array, timeout=None)¶ Deletes vectors in a collection by vector ID.
- Parameters
collection_name (str) -- Name of the collection.
id_array (list[int]) -- list of vector id
- Returns
Status: Whether the operation is successful.
-
drop_collection
(collection_name, timeout=30)¶ Deletes a collection by name.
- Parameters
collection_name (str) -- Name of the collection being deleted
- Returns
Status, indicate if operation is successful
- Return type
Status
-
drop_index
(collection_name, timeout=30)¶ Removes an index.
- Parameters
collection_name (str) -- target collection name.
- Returns
Status: Whether the operation is successful.
::rtype: Status
-
drop_partition
(collection_name, partition_tag, timeout=30)¶ Deletes a partition in a collection.
- Parameters
collection_name (str) -- Collection name.
partition_tag (str) -- Partition name.
timeout (int) -- time waiting for response.
- Returns
Status: Whether the operation is successful.
-
flush
(collection_name_array=None, timeout=None, **kwargs)¶ Flushes vector data in one collection or multiple collections to disk.
- Parameters
collection_name -- Name of one or multiple collections to flush.
-
get_collection_info
(collection_name, timeout=30)¶ Returns information of a collection.
- Parameters
collection_name (str) -- Name of the collection to describe.
- Returns
(Status, table_schema) Status: indicate if query is successful table_schema: return when operation is successful
- Return type
(Status, TableSchema)
-
get_collection_stats
(collection_name, timeout=30)¶ Returns collection statistics information
- Returns
Status: indicate if this operation is successful
statistics: statistics information
- Return type
(Status, dict)
-
get_entity_by_id
(collection_name, ids, timeout=None)¶ Returns raw vectors according to ids.
- Parameters
collection_name (str) -- Name of the collection
ids (list) -- list of vector id
- Returns
Status: indicate if invoke is successful
-
has_collection
(collection_name, timeout=30)¶ Checks whether a collection exists.
- Parameters
collection_name (str) -- Name of the collection to check.
timeout (int) -- Timeout in seconds.
- Returns
Status: indicate whether the operation is successful. bool if given collection_name exists
-
has_partition
(collection_name, partition_tag)¶ Check if specified partition exists.
- Parameters
collection_name (str) -- target table name.
partition_tag (str) -- partition tag.
- Returns
Status: Whether the operation is successful. exists: If specified partition exists
-
insert
(collection_name, records, ids=None, partition_tag=None, params=None, timeout=None, **kwargs)¶ Insert vectors to a collection.
- Parameters
ids (list[int]) -- list of id
collection_name (str) -- Name of the collection to insert vectors to.
records -- List of vectors to insert.
partition_tag (str or None. If partition_tag is None, vectors will be inserted to the collection rather than partitions.) -- Tag of a partition.
- Returns
Status: Whether vectors are inserted successfully. ids: IDs of the inserted vectors.
- Return type
(Status, list(int))
-
list_collections
(timeout=30)¶ Returns collection list.
- Returns
Status: indicate if this operation is successful
- collections: list of collection names, return when operation
is successful
- Return type
(Status, list[str])
-
list_partitions
(collection_name, timeout=30)¶ Show all partitions in a collection.
- Parameters
collection_name (str) -- target table name.
timeout (int) -- time waiting for response.
- Returns
Status: Whether the operation is successful. partition_list:
-
load_collection
(collection_name, partition_tags=None, timeout=None)¶ Loads a collection for caching.
- Parameters
collection_name (str) -- collection to load
- Returns
Status: indicate if invoke is successful
-
search
(collection_name, top_k, query_records, partition_tags=None, params=None, timeout=None, **kwargs)¶ Search vectors in a collection.
- Parameters
collection_name (str) -- Name of the collection.
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
partition_tags (list) -- tags to search
- :return
Status: Whether the operation is successful. result: query result
- Return type
(Status, TopKQueryResult)
-
search_in_segment
(collection_name, file_ids, query_records, top_k, params=None, timeout=None, **kwargs)¶ Searches for vectors in specific segments of a collection.
The Milvus server stores vector data into multiple files. Searching for vectors in specific files is a method used in Mishards. Obtain more detail about Mishards, see <a href="https://github.com/milvus-io/milvus/tree/master/shards">
- Parameters
collection_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)
-