Collection¶
The scheme of a collection is fixed when collection created. Collection scheme consists of many fields, and must contain a vector field. A field to collection is like a column to RDBMS table. Data type are the same in one field.
A collection is a set of entities, which are also called rows. An entity contains data of all fields. Each entity can be labeled, a group of entities with the same label is called a partition. Entity without a label will be tagged a default label by Milvus.
Constructor¶
Constructor |
Description |
---|---|
Milvus client |
Attributes¶
Attributes |
Description |
---|---|
Return the schema of collection. |
|
Return the description text about the collection. |
|
Return the collection name. |
|
Return whether the collection is empty. |
|
Return the number of entities. |
|
Return the primary field of collection. |
|
Return all partitions of the collection. |
|
Return all indexes of the collection. |
Methods¶
API |
Description |
---|---|
Drop the collection, as well as its corresponding index files. |
|
Load the collection from disk to memory. |
|
Release the collection from memory. |
|
Insert data into collection. |
|
Delete entities with an expression condition. |
|
Vector similarity search with an optional boolean expression as filters. |
|
Query with a set of criteria. |
|
Return the partition corresponding to name. |
|
Create the partition for the collection. |
|
Checks if a specified partition exists. |
|
Drop the partition and its corresponding index files. |
|
Return the index corresponding to name. |
|
Create index on a specified column according to the index parameters. |
|
Checks whether a specified index exists. |
|
Drop index and its corresponding index files. |
APIs References¶
-
class
pymilvus.
Collection
(name, schema=None, using='default', shards_num=2, **kwargs)¶ This is a class corresponding to collection in milvus.
-
__init__
(name, schema=None, using='default', shards_num=2, **kwargs)¶ Constructs a collection by name, schema and other parameters. Connection information is contained in kwargs.
- Parameters
name (str) -- the name of collection
schema (class schema.CollectionSchema) -- the schema of collection
using (str) -- Milvus link of create collection
shards_num (int) -- How wide to scale collection. Corresponds to how many active datanodes can be used on insert.
kwargs --
consistency_level (
str/int
) --
Which consistency level to use when searching in the collection. For details, see https://github.com/milvus-io/milvus/blob/master/docs/developer_guides/how-guarantee-ts-works.md. Note: this parameter can be overwritten by the same parameter specified in search.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect()
>>> fields = [ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=128) ... ] >>> description="This is a new collection description." >>> schema = CollectionSchema(fields=fields, description=description) >>> collection = Collection(name="test_collection_init", schema=schema) >>> collection.name 'test_collection_init' >>> collection.description 'This is a new collection description.' >>> collection.is_empty True >>> collection.num_entities 0
-
property
schema
¶ Returns the schema of the collection.
- Return schema.CollectionSchema
Schema of the collection.
-
property
description
¶ Returns a text description of the collection.
- Return str
Collection description text, returned when the operation succeeds.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> fields = [ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=128) ... ] >>> description="This is an example text description." >>> schema = CollectionSchema(fields=fields, description=description) >>> collection = Collection(name="test_collection_description", schema=schema) >>> collection.description 'This is an example text description.'
-
property
name
¶ Returns the collection name.
- Return str
The collection name, returned when the operation succeeds.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> fields = [ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=128) ... ] >>> schema = CollectionSchema(fields) >>> collection = Collection("test_collection_name", schema) >>> collection.name 'test_collection_name'
-
property
is_empty
¶ Whether the collection is empty. This method need to call num_entities.
- Return bool
True: The collection is empty.
False: The collection is gfghnot empty.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_is_empty", schema) >>> collection.is_empty True >>> collection.insert([[1], [[1.0, 2.0]]])
>>> collection.is_empty False
-
property
num_entities
¶ Returns the number of entities in the collection.
- Return int
Number of entities in the collection.
- Raises
CollectionNotExistException -- If the collection does not exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_num_entities", schema) >>> collection.num_entities 0 >>> collection.insert([[1, 2], [[1.0, 2.0], [3.0, 4.0]]]) >>> collection.num_entities 2
-
property
primary_field
¶ Returns the primary field of the collection.
- Return schema.FieldSchema
The primary field of the collection.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("film_length", DataType.INT64, description="length in miniute"), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_primary_field", schema) >>> collection.primary_field.name 'film_id'
-
drop
(timeout=None, **kwargs)¶ Drops the collection together with its index files.
- Parameters
timeout --
- timeout (
float
) -- An optional duration of time in seconds to allow for the RPC. If timeout is set to None, the client keeps waiting until the server responds or an error occurs.
- timeout (
- Raises
CollectionNotExistException -- If the collection does not exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_drop", schema) >>> utility.has_collection("test_collection_drop") True >>> collection.drop() >>> utility.has_collection("test_collection_drop") False
-
load
(partition_names=None, timeout=None, **kwargs)¶ Load the collection from disk to memory.
- Parameters
partition_names (list[str]) -- The specified partitions to load.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. If timeout is set to None, the client keeps waiting until the server responds or error occurs.
kwargs --
_async (
bool
) -- Indicate if invoke asynchronously.
- Raises
CollectionNotExistException -- If the collection does not exist.
ParamError -- If the parameters are invalid.
BaseException -- If the specified field, index or partition does not exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_load", schema) >>> collection.insert([[1, 2], [[1.0, 2.0], [3.0, 4.0]]]) >>> collection.load()
-
release
(timeout=None, **kwargs)¶ Releases the collection from memory.
- Parameters
timeout --
timeout (
float
) -- An optional duration of time in seconds to allow for the RPC. If timeout is set to None, the client keeps waiting until the server responds or an error occurs.
- Raises
CollectionNotExistException -- If collection does not exist.
BaseException -- If collection has not been loaded to memory.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_release", schema) >>> collection.insert([[1, 2], [[1.0, 2.0], [3.0, 4.0]]]) >>> collection.load() >>> collection.release()
-
insert
(data, partition_name=None, timeout=None, **kwargs)¶ Insert data into the collection.
- Parameters
data (list-like(list, tuple) object or pandas.DataFrame) -- The specified data to insert, the dimension of data needs to align with column number
partition_name (str) -- The partition name which the data will be inserted to, if partition name is not passed, then the data will be inserted to "_default" partition
timeout --
timeout (
float
) -- An optional duration of time in seconds to allow for the RPC. If timeout is set to None, the client keeps waiting until the server responds or an error occurs.
- Returns
A MutationResult object contains a property named insert_count represents how many
entities have been inserted into milvus and a property named primary_keys is a list of primary keys of the inserted entities. :rtype: MutationResult
- Raises
CollectionNotExistException -- If the specified collection does not exist.
ParamError -- If input parameters are invalid.
BaseException -- If the specified partition does not exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> import random >>> connections.connect()
>>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_insert", schema) >>> data = [ ... [random.randint(1, 100) for _ in range(10)], ... [[random.random() for _ in range(2)] for _ in range(10)], ... ] >>> collection.insert(data) >>> collection.num_entities 10
-
delete
(expr, partition_name=None, timeout=None, **kwargs)¶ Delete entities with an expression condition. And return results to show how many entities will be deleted.
- Parameters
expr (str) -- The expression to specify entities to be deleted
partition_name (str) -- Name of partitions that contain entities
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server response or error occur
- Returns
A MutationResult object contains a property named delete_count represents how many entities will be deleted.
- Return type
MutationResult
- Raises
RpcError -- If gRPC encounter an error
ParamError -- If parameters are invalid
BaseException -- If the return result from server is not ok
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> import random >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("film_date", DataType.INT64), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_query", schema) >>> # insert >>> data = [ ... [i for i in range(10)], ... [i + 2000 for i in range(10)], ... [[random.random() for _ in range(2)] for _ in range(10)], ... ] >>> collection.insert(data) >>> collection.num_entities
>>> expr = "film_id in [ 0, 1 ]" >>> res = collection.delete(expr) >>> assert len(res) == 2 >>> print(f"- Deleted entities: {res}") - Delete results: [0, 1]
-
search
(data, anns_field, param, limit, expr=None, partition_names=None, output_fields=None, timeout=None, round_decimal=-1, **kwargs)¶ Conducts a vector similarity search with an optional boolean expression as filter.
- Parameters
data (list[list[float]]) -- The vectors of search data, the length of data is number of query (nq), the dim of every vector in data must be equal to vector field's of collection.
anns_field (str) -- The vector field used to search of collection.
param (dict) -- The parameters of search, such as
nprobe
.limit (int) -- The max number of returned record, also known as
topk
.expr (str) -- The boolean expression used to filter attribute.
partition_names (list[str]) -- The names of partitions to search.
output_fields (list[str]) -- The fields to return in the search result, not supported now.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server response or error occur.
round_decimal (int) -- The specified number of decimal places of returned distance
kwargs --
_async (
bool
) -- Indicate if invoke asynchronously. When value is true, method returns a SearchFuture object; otherwise, method returns results from server directly._callback (
function
) -- The callback function which is invoked after server response successfully. It functions only if _async is set to True.consistency_level (
str/int
) -- Which consistency level to use when searching in the collection. See details in https://github.com/milvus-io/milvus/blob/master/docs/developer_guides/how-guarantee-ts-works.md. Note: this parameter will overwrite the same parameter specified when user created the collection, if no consistency level was specified, search will use the consistency level when you create the collection.guarantee_timestamp (
int
) -- This function instructs Milvus to see all operations performed before a provided timestamp. If no such timestamp is provided, then Milvus will search all operations performed to date. Note: only used in Customized consistency level.graceful_time (
int
) -- Only used in bounded consistency level. If graceful_time is set, PyMilvus will use current timestamp minus the graceful_time as the guarantee_timestamp. This option is 5s by default if not set.travel_timestamp (
int
) -- Users can specify a timestamp in a search to get results based on a data view at a specified point in time.
- Returns
SearchResult: SearchResult is iterable and is a 2d-array-like class, the first dimension is the number of vectors to query (nq), the second dimension is the number of limit(topk).
- Return type
- Raises
RpcError -- If gRPC encounter an error.
ParamError -- If parameters are invalid.
DataTypeNotMatchException -- If wrong type of param is passed.
BaseException -- If the return result from server is not ok.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> import random >>> connections.connect()
>>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_search", schema) >>> # insert >>> data = [ ... [i for i in range(10)], ... [[random.random() for _ in range(2)] for _ in range(10)], ... ] >>> collection.insert(data) >>> collection.num_entities 10 >>> collection.load() >>> # search >>> search_param = { ... "data": [[1.0, 1.0]], ... "anns_field": "films", ... "param": {"metric_type": "L2"}, ... "limit": 2, ... "expr": "film_id > 0", ... } >>> res = collection.search(**search_param) >>> assert len(res) == 1 >>> hits = res[0] >>> assert len(hits) == 2 >>> print(f"- Total hits: {len(hits)}, hits ids: {hits.ids} ") - Total hits: 2, hits ids: [8, 5] >>> print(f"- Top1 hit id: {hits[0].id}, distance: {hits[0].distance}, score: {hits[0].score} ") - Top1 hit id: 8, distance: 0.10143111646175385, score: 0.10143111646175385
-
query
(expr, output_fields=None, partition_names=None, timeout=None, **kwargs)¶ Query with a set of criteria, and results in a list of records that match the query exactly.
- Parameters
expr (str) -- The query expression
output_fields (list[str]) -- A list of fields to return
partition_names (list[str]) -- Name of partitions that contain entities
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server response or error occur
kwargs --
consistency_level (
str/int
) -- Which consistency level to use during a query on the collection. For details, see https://github.com/milvus-io/milvus/blob/master/docs/developer_guides/how-guarantee-ts-works.md. Note: this parameter will overwrite the same parameter specified when user created the collection, if no consistency level was specified, query will use the consistency level when you create the collection.guarantee_timestamp (
int
) -- This function instructs Milvus to see all operations performed before a provided timestamp. If no such timestamp is specified, Milvus queries all operations performed to date. Note: only used in Customized consistency level.graceful_time (
int
) -- Only used in bounded consistency level. If graceful_time is set, PyMilvus will use current timestamp minus the graceful_time as the guarantee_timestamp. This option is 5s by default if not set.travel_timestamp (
int
) -- Users can specify a timestamp in a search to get results based on a data view at a specified point in time.
- Returns
A list that contains all results
- Return type
list
- Raises
RpcError -- If gRPC encounter an error
ParamError -- If parameters are invalid
DataTypeNotMatchException -- If wrong type of param is passed
BaseException -- If the return result from server is not ok
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> import random >>> connections.connect()
>>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("film_date", DataType.INT64), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_query", schema) >>> # insert >>> data = [ ... [i for i in range(10)], ... [i + 2000 for i in range(10)], ... [[random.random() for _ in range(2)] for _ in range(10)], ... ] >>> collection.insert(data) >>> collection.num_entities 10 >>> collection.load() >>> # query >>> expr = "film_id in [ 0, 1 ]" >>> res = collection.query(expr, output_fields=["film_date"]) >>> assert len(res) == 2 >>> print(f"- Query results: {res}") - Query results: [{'film_id': 0, 'film_date': 2000}, {'film_id': 1, 'film_date': 2001}]
-
property
partitions
¶ Return all partitions of the collection.
- Return list[Partition]
List of Partition object, return when operation is successful.
- Raises
CollectionNotExistException -- If collection doesn't exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect()
>>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_partitions", schema) >>> collection.partitions [{"name": "_default", "description": "", "num_entities": 0}]
-
partition
(partition_name) → pymilvus.orm.partition.Partition¶ Return the partition corresponding to name. Return None if not existed.
- Parameters
partition_name (str) -- The name of the partition to get.
- Return Partition
Partition object corresponding to partition_name.
- Raises
CollectionNotExistException -- If collection doesn't exist.
BaseException -- If partition doesn't exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect()
>>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_partition", schema) >>> collection.partition("_default") {"name": "_default", "description": "", "num_entities": 0} >>> collection.partition("partition")
-
create_partition
(partition_name, description='')¶ Create the partition corresponding to name if not existed.
- Parameters
partition_name (str) -- The name of the partition to create.
description (str) -- The description of the partition corresponding to name.
- Return Partition
Partition object corresponding to partition_name.
- Raises
CollectionNotExistException -- If collection doesn't exist.
BaseException -- If partition doesn't exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_create_partition", schema) >>> collection.create_partition("comedy", description="comedy films") {"name": "comedy", "collection_name": "test_collection_create_partition", "description": ""} >>> collection.partition("comedy") {"name": "comedy", "collection_name": "test_collection_create_partition", "description": ""}
-
has_partition
(partition_name, timeout=None) → bool¶ Checks if a specified partition exists.
- Parameters
partition_name (str) -- The name of the partition 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 response or error occur
- Return bool
Whether a specified partition exists.
- Raises
CollectionNotExistException -- If collection doesn't exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_has_partition", schema) >>> collection.create_partition("comedy", description="comedy films") {"name": "comedy", "description": "comedy films", "num_entities": 0} >>> collection.has_partition("comedy") True >>> collection.has_partition("science_fiction") False
-
drop_partition
(partition_name, timeout=None, **kwargs)¶ Drop the partition and its corresponding index files.
- Parameters
partition_name (str) -- The name of the partition to drop.
timeout --
timeout (
float
) -- An optional duration of time in seconds to allow for the RPC. If timeout is set to None, the client keeps waiting until the server responds or an error occurs.
- Raises
CollectionNotExistException -- If collection doesn't exist.
BaseException -- If partition doesn't exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_drop_partition", schema) >>> collection.create_partition("comedy", description="comedy films") {"name": "comedy", "description": "comedy films", "num_entities": 0} >>> collection.has_partition("comedy") True >>> collection.drop_partition("comedy") >>> collection.has_partition("comedy") False
-
property
indexes
¶ Returns all indexes of the collection.
- Return list[Index]
List of Index objects, returned when this operation is successful.
- Raises
CollectionNotExistException -- If the collection does not exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_indexes", schema) >>> collection.indexes []
-
index
() → pymilvus.orm.index.Index¶ Fetches the index object of the of the specified name.
- Return Index
Index object corresponding to index_name.
- Raises
CollectionNotExistException -- If the collection does not exist.
BaseException -- If the specified index does not exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_index", schema) >>> index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"} >>> collection.create_index("films", index) Status(code=0, message='') >>> collection.indexes [
] >>> collection.index()
-
create_index
(field_name, index_params, timeout=None, **kwargs) → pymilvus.orm.index.Index¶ Creates index for a specified field. Return Index Object.
- Parameters
field_name (str) -- The name of the field to create an index for.
index_params (dict) -- The indexing parameters.
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server response or error occur
- Raises
CollectionNotExistException -- If the collection does not exist.
ParamError -- If the index parameters are invalid.
BaseException -- If field does not exist.
BaseException -- If the index has been created.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_create_index", schema) >>> index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"} >>> collection.create_index("films", index) Status(code=0, message='') >>> collection.index()
-
has_index
(timeout=None) → bool¶ Checks whether a specified index exists.
- Parameters
timeout (float) -- An optional duration of time in seconds to allow for the RPC. When timeout is set to None, client waits until server response or error occur
- Return bool
Whether the specified index exists.
- Raises
CollectionNotExistException -- If the collection does not exist.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_has_index", schema) >>> index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"} >>> collection.create_index("films", index) >>> collection.has_index() True
-
drop_index
(timeout=None, **kwargs)¶ Drop index and its corresponding index files.
- Parameters
timeout --
timeout (
float
) -- An optional duration of time in seconds to allow for the RPC. If timeout is set to None, the client keeps waiting until the server responds or an error occurs. Optional. A duration of time in seconds.
- Raises
CollectionNotExistException -- If the collection does not exist.
BaseException -- If the index does not exist or has been dropped.
- Example
>>> from pymilvus import connections, Collection, FieldSchema, CollectionSchema, DataType >>> connections.connect() >>> schema = CollectionSchema([ ... FieldSchema("film_id", DataType.INT64, is_primary=True), ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) ... ]) >>> collection = Collection("test_collection_has_index", schema) >>> index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"} >>> collection.create_index("films", index) >>> collection.has_index() True >>> collection.drop_index() >>> collection.has_index() False
-