milvus.
Milvus
(host=None, port=None, handler='GRPC', pool='SingletonThread', **kwargs)¶create_collection
(param, timeout=30)¶Creates a collection.
param (dict) --
Information needed to create a collection. It contains items:
collection_name (str
) -- Collection name.
dimension (int
) -- Dimension of embeddings stored in collection.
index_file_size (int
) -- Segment size. See
Storage Concepts.
metric_type (MetricType
) -- Distance Metrics type. Valued form
MetricType
. See
Distance Metrics.
A demo is as follow:
param={'collection_name': 'name',
'dimension': 16,
'index_file_size': 1024 # Optional, default 1024,
'metric_type': MetricType.L2 # Optional, default MetricType.L2
}
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status. Succeed if Status.OK() is True.
Status
has_collection
(collection_name, timeout=30)¶Checks whether a collection exists.
collection_name (str) -- Name of the collection to check.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and the flag indicating if collection exists. Succeed if Status.OK() is True. If status is not OK, the flag is always False.
Status, bool
get_collection_info
(collection_name, timeout=30)¶Returns information of a collection.
collection_name (str) -- Name of the collection to describe.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and collection information. Succeed if Status.OK() is True. If status is not OK, the returned information is always None.
Status, CollectionSchema
count_entities
(collection_name, timeout=30)¶Returns the number of vectors in a collection.
collection_name (str) -- target table name.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and row count. Succeed if Status.OK() is True. If status is not OK, the returned value of is always None.
Status, int
list_collections
(timeout=30)¶Returns collection list.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and collection name list. Succeed if Status.OK() is True. If status is not OK, the returned name list is always [].
Status, list[str]
get_collection_stats
(collection_name, timeout=30)¶Returns collection statistics information.
collection_name (str) -- target table name.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and collection statistics information. Succeed if Status.OK() is True. If status is not OK, the returned information is always [].
Status, dict
load_collection
(collection_name, partition_tags=None, timeout=None)¶Loads a collection for caching.
collection_name (str) -- collection to load
partition_tags -- partition tag list. None indicates to load whole collection, otherwise to load specified partitions.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status. Succeed if Status.OK() is True.
Status
release_collection
(collection_name, partition_tags=None, timeout=None)¶Release a collection from memory and cache.
collection_name (str) -- collection to release
partition_tags -- partition tag list. None indicates to release whole collection, otherwise to release specified partitions.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status. Succeed if Status.OK() is True.
Status
drop_collection
(collection_name, timeout=30)¶Deletes a collection by name.
collection_name (str) -- Name of the collection being deleted
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status. Succeed if Status.OK() is True.
Status
insert
(collection_name, records, ids=None, partition_tag=None, params=None, timeout=None, **kwargs)¶Insert vectors to a collection.
collection_name (str) -- Name of the collection to insert vectors to.
ids (list[int]) -- ID list. None indicates ID is generated by server system. Note that if the first time when insert() is invoked ids is not passed into this method, each of the rest time when inset() is invoked ids is not permitted to pass, otherwise server will return an error and the insertion process will fail. And vice versa.
records (list[list[float]]) -- List of vectors to insert.
partition_tag (str or None. If partition_tag is None, vectors will be inserted to the default partition _default.) -- Tag of a partition.
params (dict) -- Insert param. Reserved.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
kwargs --
_async (bool
) --
Indicate if invoke asynchronously. When value is true, method returns a InsertFuture
object; otherwise, method returns results from server.
_callback (function
) --
The callback function which is invoked after server response successfully. It only
takes effect when _async is set to True.
The operation status and IDs of inserted entities. Succeed if Status.OK() is True. If status is not OK, the returned IDs is always [].
Status, list[int]
get_entity_by_id
(collection_name, ids, timeout=None, partition_tag=None)¶Returns raw vectors according to ids.
collection_name (str) -- Name of the collection
ids (list) -- list of vector id
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
partition_tag (str) -- The partition tag of entity
The operation status and entities. Succeed if Status.OK() is True. If status is not OK, the returned entities is always [].
Status, list[list[float]]
list_id_in_segment
(collection_name, segment_name, timeout=None)¶Get IDs of entity stored in the specified segment.
collection_name (str) -- Collection the segment belongs to.
segment_name (str) -- Segment name.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and entity IDs. Succeed if Status.OK() is True. If status is not OK, the returned IDs is always [].
Status, list[int]
create_index
(collection_name, index_type=None, params=None, timeout=None, **kwargs)¶Creates index for a collection.
collection_name (str) -- Collection used to create index.
index_type (IndexType) -- index params. See index params for supported indexes.
params (dict) --
Index param. See index params for detailed index param of supported indexes.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
kwargs --
_async (bool
) --
Indicate if invoke asynchronously. When value is true, method returns a IndexFuture
object; otherwise, method returns results from server.
_callback (function
) --
The callback function which is invoked after server response successfully. It only
takes effect when _async is set to True.
The operation status. Succeed if Status.OK() is True.
Status
get_index_info
(collection_name, timeout=30)¶Show index information of a collection.
collection_name (str) -- table name been queried
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and index info. Succeed if Status.OK() is True. If status is not OK, the returned index info is always None.
Status, IndexParam
drop_index
(collection_name, timeout=30)¶Removes an index.
collection_name (str) -- target collection name.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status. Succeed if Status.OK() is True.
Status
create_partition
(collection_name, partition_tag, timeout=30)¶create a partition for a collection.
collection_name (str) -- Name of the collection.
partition_tag (str) -- Name of the partition tag.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status. Succeed if Status.OK() is True.
Status
has_partition
(collection_name, partition_tag, timeout=30)¶Check if specified partition exists.
collection_name (str) -- target table name.
partition_tag (str) -- partition tag.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and a flag indicating if partition exists. Succeed if Status.OK() is True. If status is not ok, the flag is always False.
Status, bool
list_partitions
(collection_name, timeout=30)¶Show all partitions in a collection.
collection_name (str) -- target table name.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status and partition list. Succeed if Status.OK() is True. If status is not OK, returned partition list is [].
Status, list[PartitionParam]
drop_partition
(collection_name, partition_tag, timeout=30)¶Deletes a partition in a collection.
collection_name (str) -- Collection name.
partition_tag (str) -- Partition name.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
The operation status. Succeed if Status.OK() is True.
Status
search
(collection_name, top_k, query_records, partition_tags=None, params=None, timeout=None, **kwargs)¶Search vectors in a collection.
collection_name (str) -- Name of the collection.
top_k (int) -- number of vectors which is most similar with query vectors
query_records (list[list[float32]]) -- vectors to query
partition_tags (list) -- tags to search. None indicates to search in whole collection.
params (dict) --
Search params. The params is related to index type the collection is built. See index params for more detailed information.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
kwargs --
_async (bool
) --
Indicate if invoke asynchronously. When value is true, method returns a SearchFuture
object; otherwise, method returns results from server.
_callback (function
) --
The callback function which is invoked after server response successfully. It only
takes effect when _async is set to True.
The operation status and search result. See <a>here</a> to find how to handle search result. Succeed if Status.OK() is True. If status is not OK, results is always None.
Status, TopKQueryResult
delete_entity_by_id
(collection_name, id_array, timeout=None, partition_tag=None)¶Deletes vectors in a collection by vector ID.
collection_name (str) -- Name of the collection.
id_array (list[int]) -- list of vector id
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
partition_tag (str) -- The partition tag of entity
The operation status. If the specified ID doesn't exist, Milvus server skip it and try to delete next entities, which is regard as one successful operation. Succeed if Status.OK() is True.
Status
flush
(collection_name_array=None, timeout=None, **kwargs)¶Flushes vector data in one collection or multiple collections to disk.
collection_name_array (list) -- Name of one or multiple collections to flush.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
kwargs --
_async (bool
) --
Indicate if invoke asynchronously. When value is true, method returns a FlushFuture
object; otherwise, method returns results from server.
_callback (function
) --
The callback function which is invoked after server response successfully. It only
takes effect when _async is set to True.
The operation status. Succeed if Status.OK() is True.
Status
compact
(collection_name, timeout=None, **kwargs)¶Compacts segments in a collection. This function is recommended after deleting vectors.
collection_name (str) -- Name of the collections to compact.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server responses or error occurs.
kwargs --
_async (bool
) --
Indicate if invoke asynchronously. When value is true, method returns a CompactFuture
object; otherwise, method returns results from server.
_callback (function
) --
The callback function which is invoked after server response successfully. It only
takes effect when _async is set to True.
The operation status. Succeed if Status.OK() is True.
Status
milvus.
MetricType
¶Metric type enum.
INVALID
= 0¶Invalid metric type.
L2
= 1¶Euclidean distance. A metric for float vectors. See Euclidean distance.
IP
= 2¶Inner product. A metric for float vectors. See Inner Product.
HAMMING
= 3¶Hamming distance. A metric for binary vectors. See Hamming distance.
JACCARD
= 4¶Jaccard distance. A metric for binary vectors. See Jaccard distance.
TANIMOTO
= 5¶Tanimoto distance. A metric for binary vectors. See Tanimoto distance.
SUBSTRUCTURE
= 6¶Superstructure. A metric for binary vectors,
only support FLAT
index.
See Superstructure.
SUPERSTRUCTURE
= 7¶Substructure. A metric for binary vectors, only support FLAT
index.
See Substructure.