
    j7                    x   d dl Z d dlZd dlmZmZmZmZ d dlZd dl	m
Z
 d dlmZmZ d dlmZ d dlmZmZmZmZmZ d dlmZmZmZmZmZmZmZ d dlmZ d d	l m!Z! d
dl"m"Z" d
dl#m$Z$ d
dl%m&Z&m'Z' d
dl(m)Z) d
dl*m+Z+m,Z, d
dl-m.Z. d
dl/m0Z0 d
dl1m2Z2 d
dl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; d
dl<m=Z= d
dl>m?Z?  G d d          Z@dS )    N)DictListOptionalUnion)utils)
BaseRankerSearchResult)DEFAULT_CONSISTENCY_LEVEL)CompactionPlansCompactionStateReplicacmp_consistency_levelget_consistency_level)AutoIDExceptionDataTypeNotMatchExceptionDataTypeNotSupportExceptionExceptionsMessageIndexNotExistExceptionPartitionAlreadyExistExceptionSchemaNotReadyException)
schema_pb2)Config   )connections)	UNLIMITED)MutationFutureSearchFuture)Index)QueryIteratorSearchIterator)MutationResult)	Partition)Prepare)CollectionSchemaFieldSchemacheck_insert_schemacheck_schemacheck_upsert_schemaconstruct_fields_from_dataframeis_row_basedis_valid_insert_data)DataType)_get_connectionc                      e Zd Z	 	 dLdedee         deddfdZdefdZd	 Ze	ded
e
j        fd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            ZdMdee         fdZdMdee         fdZdMdedee         fdZ	 	 	 dNdee         dedee         fdZdMdee         fdZ 	 	 dOde!e"e
j        e#e$j%        f         dee         dee         de&fd Z'	 	 dOd!edee         dee         fd"Z(	 	 dOde!e"e
j        e#e$j%        f         dee         dee         de&fd#Z)	 	 	 	 	 dPde!e"e$j%        f         d%ed&e#d'ed!ee         dee"e                  d(ee"e                  dee         d)efd*Z*	 	 	 	 dQd+e"d,e+d'edee"e                  d(ee"e                  dee         d)efd-Z,d.e-ddddd$fde!e"e$j%        f         d%ed&e#d/ee         d'ee         d!ee         dee"e                  d(ee"e                  dee         d)efd0Z.	 	 	 dRd!ed(ee"e                  dee"e                  dee         fd1Z/d.e-ddddfd/ee         d'ee         d!ee         d(ee"e                  dee"e                  dee         fd2Z0ede"e1         fd3            Z2dede1fd4Z3dSded6ede1fd7Z4dMdedee         defd8Z5dMdedee         fd9Z6ede"e7         fd:            Z8de7fd;Z9	 	 dOd<ed=ee#         dee         fd>Z:	 dMd?ed@edee         fdAZ;dMdee         defdBZ<dMdee         fdCZ=	 dTdEee         dee         fdFZ>	 dUdee         dEee         de?fdGZ@	 	 dUdee         dEee         de?fdHZAdMdee         deBfdIZCdMdee         deDfdJZEdMdee         fdKZFdS )V
CollectionNdefaultnameschemausingreturnc                 8   || _         || _        || _        d| _        |                                 } |j        | j         fi |}|r |j        | j         fi |}|                    dt                    }|                    d|          }	t          ||	          st          t          j                  t          j        |          }
|| _        |	|
| _        nt#          |t                    st          t          j                  |
|k    rt          t          j                  || _        n|t          t          j        |z            t#          |t                    rn|                                 t-          |           t/          |                    dt                              } |j        | j         |fi | || _        || _        nt          t          j                  | j                                        | _        | j        | j        d<   dS )a  Constructs a collection by name, schema and other parameters.

        Args:
            name (``str``): the name of collection
            schema (``CollectionSchema``, optional): the schema of collection, defaults to None.
            using (``str``, optional): Milvus connection alias name, defaults to 'default'.
            **kwargs (``dict``):

                * *num_shards (``int``, optional): how many shards will the insert data be divided.
                * *shards_num (``int``, optional, deprecated):
                    how many shards will the insert data be divided.
                * *consistency_level* (``int/ str``)
                    Which consistency level to use when searching in the collection.
                    Options of consistency level: Strong, Bounded, Eventually, Session, Customized.

                    Note: can be overwritten by the same parameter specified in search.

                * *properties* (``dict``, optional)
                    Collection properties.

                * *timeout* (``float``)
                    An optional duration of time in seconds to allow for the RPCs.
                    If timeout is not set, the client keeps waiting until the server
                    responds or an error occurs.


        Raises:
            SchemaNotReadyException: if the schema is wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> fields = [
            ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
            ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=128)
            ... ]
            >>> schema = CollectionSchema(fields=fields)
            >>> prop = {"collection.ttl.seconds": 1800}
            >>> collection = Collection(name="test_collection_init", schema=schema, properties=prop)
            >>> collection.name
            'test_collection_init'
        Nconsistency_levelmessage)_name_using_kwargs_num_shardsr-   has_collectiondescribe_collectiongetr
   r   r   r   ConsistencyLevelInconsistentr$   construct_from_dict_consistency_level_schema
isinstance
SchemaTypeSchemaInconsistentCollectionNotExistNoSchemaverifyr'   r   create_collectionto_dict_schema_dict)selfr1   r2   r3   kwargsconnhasresps_consistency_levelarg_consistency_levelserver_schemar6   s               a/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/pymilvus/orm/collection.py__init__zCollection.__init__@   s=   ` 
##%%!d!$*7777 #	T+4+DJAA&AAD"&((+>@Y"Z"Z$*JJ/BDW$X$X!()<>STT --J    -@FFM&9D#~,!&*:;; X1:K:VWWWW F**1:K:^____% ~--H4O    &"233 TV$$$$9JJ24MNN% %! '&tz6DDVDDD%*;''-6G6RSSSS L0022151H-...    c                     | j         | j        | j        d}dg}d}|                                D ].\  }}|                    |                    ||                     /d                    |          S )N)r1   descriptionr2   z<Collection>:
-------------
z	<{}>: {}
 )r1   rX   rC   itemsappendformatjoin)rL   _dictrskvs         rT   __repr__zCollection.__repr__   sy    I+l
 

 ..KKMM 	% 	%DAqHHQXXa^^$$$$wwqzzrV   c                 4    t          j        | j                  S N)r   _fetch_handlerr:   rL   s    rT   r-   zCollection._get_connection   s    )$+666rV   	dataframec                 R   t          |t          j                  st          t          j                  |                    dd           }|t          t          j                  d}t          |          D ]\  }}||k    r|}|dk    rt          t          j	                  d|v rBt          |
                    d          t                    st          t          j                  |                    dd          }|r^||                                                                         r|                    |d          }nt          t          j                  |
                    dt$          j                  }	t)          |	          }
 |
j        |fi |r% |
j        |fi |}t/          j        |          }|}nt3          |          }|r/|                    |t7          d|t8          j        d	d	d
|           |D ]_}|du r|j        |k    rd	|_        d|_         |j!        t8          j"        k    r+tG          t$          j$                  |j%        t$          j&        <   `t/          |          }tO          |            | ||fi |}|                    |          }||fS )Nr7   primary_fieldauto_idFr   )axisr3   T)r1   dtype
is_primaryrl   )fields)data )(rD   pd	DataFramer   r   DataFrameTypepopNoPrimaryKey	enumeratePrimaryKeyNotExistr?   boolr   
AutoIDTypeisnullalldropAutoIDWithDatar   MILVUS_CONN_ALIASr-   r=   r>   r$   rA   r)   insertr%   r,   INT64r1   ro   rl   rn   VARCHARintMaxVarCharLengthparamsMaxVarCharLengthKeyr'   )clsr1   rh   rM   rj   pk_indexifieldrl   r3   rN   rP   rS   r2   fields_schema
collectionress                    rT   construct_from_dataframez#Collection.construct_from_dataframe   s   )R\22 	S)2C2QRRRR

?D99 )2C2PQQQQ!),, 	 	HAu%%r>>)2C2VWWWWz&**Y2G2G'N'N!*;*FGGGG**Y.. 	X'..004466 X%NN=qNAA		-6G6VWWWW

7F$<==u%%4t..v.. 	<+4+D;;F;;D,@FFM"FF;IFFM 
$$ *&n#' $	 
 ! 	 	 	 ' \ \e##
m(C(C'+E$$)EM;("222?B6CZ?[?[EL!;<%];;;FVSv0000
Y//3rV   c                     | j         S )z+CollectionSchema: schema of the collection.)rC   rg   s    rT   r2   zCollection.schema   s     |rV   c                 n    |                                  }|                    | j                  }|d         S )z-List[str]: all the aliases of the collection.aliases)r-   r>   r9   )rL   rN   rP   s      rT   r   zCollection.aliases   s4     ##%%''
33IrV   c                     | j         j        S )z*str: a text description of the collection.)r2   rX   rg   s    rT   rX   zCollection.description   s     {&&rV   c                     | j         S )z str: the name of the collection.)r9   rg   s    rT   r1   zCollection.name   s     zrV   c                     | j         dk    S )z-bool: whether the collection is empty or not.r   )num_entitiesrg   s    rT   is_emptyzCollection.is_empty   s      A%%rV   c                 v    | j         ,|                                                     d          | _         | j         S )z-int: number of shards used by the collection.N
num_shards)r<   describer?   rg   s    rT   r   zCollection.num_shards  s4     ##}}22<@@DrV   c                     |                                  }|                    | j                  }d |D             }t          |d                   |d<   |d         S )a  int: The number of entities in the collection, not real time.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
            0
            >>> collection.flush()
            >>> collection.num_entities
            2
        )collection_namec                 (    i | ]}|j         |j        S rr   keyvalue).0stats     rT   
<dictcomp>z+Collection.num_entities.<locals>.<dictcomp>  s    9994$(DJ999rV   	row_count)r-   get_collection_statsr9   r   )rL   rN   statsresults       rT   r   zCollection.num_entities  sb    ( ##%%))$*)EE995999!&"566{k""rV   c                     | j         j        S )z1FieldSchema: the primary field of the collection.)r2   rj   rg   s    rT   rj   zCollection.primary_field"  s     {((rV   timeoutc                 Z    |                                  } |j        | j        gfd|i| dS )a  Seal all segments in the collection. Inserts after flushing will be written into
            new segments. Only sealed segments can be indexed.

        Args:
            timeout (float): an optional duration of time in seconds to allow for the RPCs.
                If timeout is not set, the client keeps waiting until the server
                responds or an error occurs.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> fields = [
            ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
            ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=128)
            ... ]
            >>> schema = CollectionSchema(fields=fields)
            >>> collection = Collection(name="test_collection_flush", schema=schema)
            >>> collection.insert([[1, 2], [[1.0, 2.0], [3.0, 4.0]]])
            >>> collection.flush()
            >>> collection.num_entities
            2
        r   N)r-   flushr1   rL   r   rM   rN   s       rT   r   zCollection.flush'  s>    , ##%%
DI;:::6:::::rV   c                 X    |                                  } |j        | j        fd|i| dS )a  Drops the collection. The same as `utility.drop_collection()`

        Args:
            timeout (float, optional): an optional duration of time in seconds to allow
                for the RPCs. If timeout is not set, the client keeps waiting until the
                server responds or an error occurs.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
        r   N)r-   drop_collectionr9   r   s       rT   r~   zCollection.drop@  s=    * ##%%TZCCCFCCCCCrV   
propertiesc                 Z    |                                  } |j        | j        f||d| dS )aS  Set properties for the collection

        Args:
            properties (``dict``): collection properties.
                 support collection TTL with key `collection.ttl.seconds`
                 support collection replica number with key `collection.replica.number`
                 support collection resource groups with key `collection.resource_groups`.
            timeout (float, optional): an optional duration of time in seconds to allow
                for the RPCs. If timeout is not set, the client keeps waiting until the
                server responds or an error occurs.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> fields = [
            ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
            ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=128)
            ... ]
            >>> schema = CollectionSchema(fields=fields)
            >>> collection = Collection("test_set_properties", schema)
            >>> collection.set_properties({"collection.ttl.seconds": 60})
        )r   r   N)r-   alter_collectionr1   )rL   r   r   rM   rN   s        rT   set_propertieszCollection.set_propertiesX  sU    , ##%%I	
!	
 	
 		
 	
 	
 	
 	
rV   r   partition_namesreplica_numberc                     |                                  }| |j        d| j        |||d| dS  |j        d| j        ||d| dS )a4  Load the data into memory.

        Args:
            partition_names (``List[str]``): The specified partitions to load.
            replica_number (``int``, optional): The replica number to load, defaults to 1.
            timeout (float, optional): an optional duration of time in seconds to allow
                for the RPCs. If timeout is not set, the client keeps waiting until the
                server responds or an error occurs.
            **kwargs (``dict``, optional):

                * *_async*(``bool``)
                    Indicate if invoke asynchronously.

                * *refresh*(``bool``)
                    Whether to renew the segment list of this collection before loading
                * *resource_groups(``List[str]``)
                    Specify resource groups which can be used during loading.
                * *load_fields(``List[str]``)
                    Specify load fields list needed during this load
                * *skip_load_dynamic_field(``bool``)
                    Specify whether this load shall skip dynamic schmea field

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import 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]]])
            >>> index_param = {"index_type": "FLAT", "metric_type": "L2", "params": {}}
            >>> collection.create_index("films", index_param)
            >>> collection.load()
        N)r   r   r   r   )r   r   r   rr   )r-   load_partitionsr9   load_collection)rL   r   r   r   rM   rN   s         rT   loadzCollection.loadv  s    Z ##%%& D   $
 /-	 
      !D   $
-  	    rV   c                 X    |                                  } |j        | j        fd|i| dS )a  Releases the collection data from memory.

        Args:
            timeout (float, optional): an optional duration of time in seconds to allow
                for the RPCs. If timeout is not set, the client keeps waiting until the
                server responds or an error occurs.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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]]])
            >>> index_param = {"index_type": "FLAT", "metric_type": "L2", "params": {}}
            >>> collection.create_index("films", index_param)
            >>> collection.load()
            >>> collection.release()
        r   N)r-   release_collectionr9   r   s       rT   releasezCollection.release  s=    * ##%%
FFGFvFFFFFrV   rq   partition_namec           	      X   t          |          st          d          |                                 }t          |          r |j        d| j        |||| j        d|S t          | j        |           t          j
        || j                  } |j        | j        ||f|| j        d|S )a[  Insert data into the collection.

        Args:
            data (``list/tuple/pandas.DataFrame/sparse types``): The specified data to insert
            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 (float, optional): an optional duration of time in seconds to allow
                for the RPCs. If timeout is not set, the client keeps waiting until the
                server responds or an error occurs.
        Returns:
            MutationResult: contains 2 properties `insert_count`, and, `primary_keys`
                `insert_count`: how may entites have been inserted into Milvus,
                `primary_keys`: list of primary keys of the inserted entities
        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> import random
            >>> 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)],
            ... ]
            >>> res = collection.insert(data)
            >>> res.insert_count
            10
        5The type of data should be List, pd.DataFrame or Dictr7   )r   entitiesr   r   r2   r   r2   rr   )r+   r   r-   r*   insert_rowsr9   rK   r&   r2   r#   prepare_databatch_insert)rL   rq   r   r   rM   rN   r   s          rT   r   zCollection.insert  s    P $D)) 	-O    ##%% 	#4#  $
-(     	DK...'dk:: t J
 $
 
 
 
 	
rV   exprc                     |                                  } |j        | j        ||fd|i|}|                    dd          rt	          |          S t          |          S )aV  Delete entities with an expression condition.

        Args:
            expr (``str``): The specified data to insert.
            partition_names (``List[str]``): Name of partitions to delete entities.
            timeout (float, optional): an optional duration of time in seconds to allow
                for the RPCs. If timeout is not set, the client keeps waiting until the
                server responds or an error occurs.
            **kwargs (``dict``): Optional search params

                * *consistency_level* (``str/int``, optional)
                    Which consistency level to use when searching in the collection.

                    Options of consistency level: Strong, Bounded, Eventually, Session, Customized.

                    Note: this parameter overwrites the same one specified when creating collection,
                    if no consistency level was specified, search will use the
                    consistency level when you create the collection.

        Returns:
            MutationResult:
                contains `delete_count` properties represents how many entities might be deleted.

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> import random
            >>> 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_delete", 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)
            >>> res = collection.delete("film_id in [ 0, 1 ]")
            >>> print(f"- Deleted entities: {res}")
            - Delete results: [0, 1]
        r   _asyncF)r-   deleter9   r?   r   r!   )rL   r   r   r   rM   rN   r   s          rT   r   zCollection.delete  sl    l ##%%dk$*dNVVGVvVV::h&& 	'!#&&&c"""rV   c                    t          |          st          d          |                                 }t          |          r, |j        | j        ||f|| j        d|}t          |          S t          | j	        |           t          j        || j	        d          } |j        | j        ||f|| j        d|}|                    dd          rt          |          nt          |          S )aY  Upsert data into the collection.

        Args:
            data (``list/tuple/pandas.DataFrame/sparse types``): The specified data to upsert
            partition_name (``str``): The partition name which the data will be upserted at,
                if partition name is not passed, then the data will be upserted
                in default partition
            timeout (float, optional): an optional duration of time in seconds to allow
                for the RPCs. If timeout is not set, the client keeps waiting until the
                server responds or an error occurs.
        Returns:
            MutationResult: contains 2 properties `upsert_count`, and, `primary_keys`
                `upsert_count`: how may entites have been upserted at Milvus,
                `primary_keys`: list of primary keys of the upserted entities
        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> import random
            >>> schema = CollectionSchema([
            ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
            ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2)
            ... ])
            >>> collection = Collection("test_collection_upsert", schema)
            >>> data = [
            ...     [random.randint(1, 100) for _ in range(10)],
            ...     [[random.random() for _ in range(2)] for _ in range(10)],
            ... ]
            >>> res = collection.upsert(data)
            >>> res.upsert_count
            10
        r   r7   r   Fr   )r+   r   r-   r*   upsert_rowsr9   rK   r!   r(   r2   r#   r   upsertr?   r   )rL   rq   r   r   rM   rN   r   r   s           rT   r   zCollection.upsertK  s6   R $D)) 	-O    ##%% 		'"$"
  (   C "#&&&DK...'dk5AAdkJ
 $
 
 
 
 '-jj5&A&AZ~c"""~VYGZGZZrV   rk   
anns_fieldparamlimitoutput_fieldsround_decimalc
                    |?t          |t                    s*t          t          j        t          |          z            t          j                            |          o|j	        d         dk    }t          |t                    rt          |          dk    s|rGt          t          j                              }|
                    dd          rt!          d          n|S |                                 } |j        | j        ||||||||	f	|| j        d|
}|
                    dd          rt!          |          n|S )a  Conducts a vector similarity search with an optional boolean expression as filter.

        Args:
            data (``List[List[float]]/sparse types``): The vectors of search data.
                the length of data is number of query (nq),
                and the dim of every vector in data must be equal to the vector field of collection.
            anns_field (``str``): The name of the vector field used to search of collection.
            param (``dict[str, Any]``):
                The parameters of search. The followings are valid keys of param.
                * *metric_type* (``str``)
                    similar metricy types, the value must be of type str.
                * *offset* (``int``, optional)
                    offset for pagination.
                * *params of index: *nprobe*, *ef*, *search_k*, etc
                    Corresponding search params for a certain index.
                example for param::

                    {
                        "metric_type": "L2",
                        "offset": 10,
                        "params": {"nprobe": 12},
                    }

            limit (``int``): The max number of returned record, also known as `topk`.
            expr (``str``, Optional): The boolean expression used to filter attribute.

                example for expr::

                    "id_field >= 0", "id_field in [1, 2, 3, 4]"

            partition_names (``List[str]``, optional): The names of partitions to search on.
            output_fields (``List[str]``, optional):
                The name of fields to return in the search result.  Can only get scalar fields.
            round_decimal (``int``, optional):
                The specified number of decimal places of returned distance.
                Defaults to -1 means no round to returned distance.
            timeout (``float``, optional): A 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.
            **kwargs (``dict``): Optional search params

                *  *_async* (``bool``, optional)
                    Indicate if invoke asynchronously.
                    Returns a SearchFuture if True, else returns results from server directly.

                * *_callback* (``function``, optional)
                    The callback function which is invoked after server response successfully.
                    It functions only if _async is set to True.

                * *offset* (``int``, optinal)
                    offset for pagination.

                * *consistency_level* (``str/int``, optional)
                    Which consistency level to use when searching in the collection.

                    Options of consistency level: Strong, Bounded, Eventually, Session, Customized.

                    Note: this parameter overwrites the same one specified when creating collection,
                    if no consistency level was specified, search will use the
                    consistency level when you create the collection.

                * *guarantee_timestamp* (``int``, optional)
                    Instructs Milvus to see all operations performed before this timestamp.
                    By default Milvus will search all operations performed to date.

                    Note: only valid in Customized consistency level.

                * *graceful_time* (``int``, optional)
                    Search will use the (current_timestamp - the graceful_time) as the
                    `guarantee_timestamp`. By default with 5s.

                    Note: only valid in Bounded consistency level

        Returns:
            SearchResult:
                Returns ``SearchResult`` if `_async` is False , otherwise ``SearchFuture``

        .. _Metric type documentations:
            https://milvus.io/docs/v2.2.x/metric.md
        .. _Index documentations:
            https://milvus.io/docs/v2.2.x/index.md
        .. _How guarantee ts works:
            https://github.com/milvus-io/milvus/blob/master/docs/developer_guides/how-guarantee-ts-works.md

        Raises:
            MilvusException: If anything goes wrong

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> import random
            >>> 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)
            >>> index_param = {"index_type": "FLAT", "metric_type": "L2", "params": {}}
            >>> collection.create_index("films", index_param)
            >>> collection.load()
            >>> # search
            >>> search_param = {
            ...     "data": [[1.0, 1.0]],
            ...     "anns_field": "films",
            ...     "param": {"metric_type": "L2", "offset": 1},
            ...     "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}, score: {hits[0].score} ")
            - Top1 hit id: 8, score: 0.10143111646175385
        Nr7   r   r   Fr   )rD   strr   r   ExprTypetyper   SciPyHelperis_scipy_sparseshapelistlenr	   r   SearchResultDatar?   r   r-   searchr9   rK   )rL   rq   r   r   r   r   r   r   r   r   rM   empty_scipy_sparserP   rN   s                 rT   r   zCollection.search  sQ   L JtS$9$9+4E4NQUVZQ[Q[4[\\\\".>>tDD]$*UV-[\J\tT"" 	Os4yyA~~:L~
 ; = =>>D)/He)D)DN<%%%$N##%%t{J
 $
 
 
 
 &,ZZ%%@%@J|D!!!dJrV   reqsrerankc           	         t          |t                    rZt          |          dk    rGt          t	          j                              }	|                    dd          rt          d          n|	S |                                 }
 |
j	        | j
        ||||||f|| j        d|}	|                    dd          rt          |	          n|	S )aJ  Conducts multi vector similarity search with a rerank for rearrangement.

        Args:
            reqs (``List[AnnSearchRequest]``): The vector search requests.
            rerank (``BaseRanker``): The reranker for rearrange nummer of limit results.
            limit (``int``): The max number of returned record, also known as `topk`.

            partition_names (``List[str]``, optional): The names of partitions to search on.
            output_fields (``List[str]``, optional):
                The name of fields to return in the search result.  Can only get scalar fields.
            round_decimal (``int``, optional):
                The specified number of decimal places of returned distance.
                Defaults to -1 means no round to returned distance.
            timeout (``float``, optional): A 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.
            **kwargs (``dict``): Optional search params

                *  *_async* (``bool``, optional)
                    Indicate if invoke asynchronously.
                    Returns a SearchFuture if True, else returns results from server directly.

                * *_callback* (``function``, optional)
                    The callback function which is invoked after server response successfully.
                    It functions only if _async is set to True.

                * *offset* (``int``, optinal)
                    offset for pagination.

                * *consistency_level* (``str/int``, optional)
                    Which consistency level to use when searching in the collection.

                    Options of consistency level: Strong, Bounded, Eventually, Session, Customized.

                    Note: this parameter overwrites the same one specified when creating collection,
                    if no consistency level was specified, search will use the
                    consistency level when you create the collection.

                * *guarantee_timestamp* (``int``, optional)
                    Instructs Milvus to see all operations performed before this timestamp.
                    By default Milvus will search all operations performed to date.

                    Note: only valid in Customized consistency level.

                * *graceful_time* (``int``, optional)
                    Search will use the (current_timestamp - the graceful_time) as the
                    `guarantee_timestamp`. By default with 5s.

                    Note: only valid in Bounded consistency level

        Returns:
            SearchResult:
                Returns ``SearchResult`` if `_async` is False , otherwise ``SearchFuture``

        .. _Metric type documentations:
            https://milvus.io/docs/v2.2.x/metric.md
        .. _Index documentations:
            https://milvus.io/docs/v2.2.x/index.md
        .. _How guarantee ts works:
            https://github.com/milvus-io/milvus/blob/master/docs/developer_guides/how-guarantee-ts-works.md

        Raises:
            MilvusException: If anything goes wrong

        Examples:
            >>> from pymilvus import (Collection, FieldSchema, CollectionSchema, DataType,
            >>>     AnnSearchRequest, RRFRanker, WeightedRanker)
            >>> import random
            >>> schema = CollectionSchema([
            ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
            ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2),
            ...     FieldSchema("poster", 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)],
            ...     [[random.random() for _ in range(2)] for _ in range(10)],
            ... ]
            >>> collection.insert(data)
            >>> index_param = {"index_type": "FLAT", "metric_type": "L2", "params": {}}
            >>> collection.create_index("films", index_param)
            >>> collection.create_index("poster", index_param)
            >>> collection.load()
            >>> # search
            >>> search_param1 = {
            ...     "data": [[1.0, 1.0]],
            ...     "anns_field": "films",
            ...     "param": {"metric_type": "L2", "offset": 1},
            ...     "limit": 2,
            ...     "expr": "film_id > 0",
            ... }
            >>> req1 = AnnSearchRequest(**search_param1)
            >>> search_param2 = {
            ...     "data": [[2.0, 2.0]],
            ...     "anns_field": "poster",
            ...     "param": {"metric_type": "L2", "offset": 1},
            ...     "limit": 2,
            ...     "expr": "film_id > 0",
            ... }
            >>> req2 = AnnSearchRequest(**search_param2)
            >>> res = collection.hybrid_search([req1, req2], WeightedRanker(0.9, 0.1), 2)
            >>> 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}, score: {hits[0].score} ")
            - Top1 hit id: 8, score: 0.10143111646175385
        r   r   FNr   )rD   r   r   r	   r   r   r?   r   r-   hybrid_searchr9   rK   )rL   r   r   r   r   r   r   r   rM   rP   rN   s              rT   r   zCollection.hybrid_search2  s    t dD!! 	Oc$ii1nn
 ; = =>>D)/He)D)DN<%%%$N##%%!t!J
 $
 
 
 
 &,ZZ%%@%@J|D!!!dJrV   i  
batch_sizec                     |?t          |t                    s*t          t          j        t          |          z            t          d|                                 | j        |||||||||	|
| j	        d|S )Nr7   )
connectionr   rq   	ann_fieldr   r   r   r   r   r   r   r   r2   rr   )
rD   r   r   r   r   r   r    r-   r9   rK   )rL   rq   r   r   r   r   r   r   r   r   r   rM   s               rT   search_iteratorzCollection.search_iterator  s     JtS$9$9+4E4NQUVZQ[Q[4[\\\\ 
++-- J !+''$
 
 
 
 	
rV   c                     t          |t                    s*t          t          j        t          |          z            |                                 } |j        | j        |||f|| j	        d|S )a  Query with expressions

        Args:
            expr (``str``): The query expression.
            output_fields(``List[str]``): A list of field names to return. Defaults to None.
            partition_names: (``List[str]``, optional): A list of partition names to query in.
            timeout (``float``, optional): A 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.
            **kwargs (``dict``, optional):

                * *consistency_level* (``str/int``, optional)
                    Which consistency level to use when searching in the collection.

                    Options of consistency level: Strong, Bounded, Eventually, Session, Customized.

                    Note: this parameter overwrites the same one specified when creating collection,
                    if no consistency level was specified, search will use the
                    consistency level when you create the collection.


                * *guarantee_timestamp* (``int``, optional)
                    Instructs Milvus to see all operations performed before this timestamp.
                    By default Milvus will search all operations performed to date.

                    Note: only valid in Customized consistency level.

                * *graceful_time* (``int``, optional)
                    Search will use the (current_timestamp - the graceful_time) as the
                    `guarantee_timestamp`. By default with 5s.

                    Note: only valid in Bounded consistency level

                * *offset* (``int``)
                    Combined with limit to enable pagination

                * *limit* (``int``)
                    Combined with limit to enable pagination

        Returns:
            List, contains all results

        Raises:
            MilvusException: If anything goes wrong

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> import random
            >>> 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)
            >>> index_param = {"index_type": "FLAT", "metric_type": "L2", "params": {}}
            >>> collection.create_index("films", index_param)
            >>> collection.load()
            >>> # query
            >>> expr = "film_id <= 1"
            >>> res = collection.query(expr, output_fields=["film_date"], offset=1, limit=1)
            >>> assert len(res) == 1
            >>> print(f"- Query results: {res}")
            - Query results: [{'film_id': 1, 'film_date': 2001}]
        r7   r   )
rD   r   r   r   r   r   r-   queryr9   rK   )rL   r   r   r   r   rM   rN   s          rT   r   zCollection.query  s    ^ $$$ 	]+4E4NQUVZQ[Q[4[\\\\##%%tzJ	

 $
 
 
 
 	
rV   c                     |?t          |t                    s*t          t          j        t          |          z            t          d|                                 | j        |||||| j	        |d	|S )Nr7   )	r   r   r   r   r   r   r   r2   r   rr   )
rD   r   r   r   r   r   r   r-   r9   rK   )rL   r   r   r   r   r   r   rM   s           rT   query_iteratorzCollection.query_iterator>  s     JtS$9$9+4E4NQUVZQ[Q[4[\\\\ 
++-- J!'+$
 
 
 
 	
rV   c                     |                                  }|                    | j                  }g }|D ]'}|                    t	          | |d                     (|S )a{  List[Partition]: List of Partition object.

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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}]
        T)construct_only)r-   list_partitionsr9   r[   r"   )rL   rN   partition_strs
partitions	partitions        rT   r   zCollection.partitionsW  sl    " ##%%--dj99
' 	O 	OIiiMMMNNNNrV   c                 B     | j         |fi |sdS t          | |fddi|S )a[  Get the existing partition object according to name. Return None if not existed.

        Args:
            partition_name (``str``): The name of the partition to get.

        Returns:
            Partition: Partition object corresponding to partition_name.

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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}
        Nr   T)has_partitionr"   )rL   r   rM   s      rT   r   zCollection.partitiono  sC    , "t!.;;F;; 	4~MMdMfMMMrV   rY   rX   c                 v     | j         |fi |du rt          t          j                  t	          | |fd|i|S )a[  Create a new partition corresponding to name if not existed.

        Args:
            partition_name (``str``): The name of the partition to create.
            description (``str``, optional): The description of this partition.

        Returns:
            Partition: Partition object corresponding to partition_name.

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> schema = CollectionSchema([
            ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
            ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2)
            ... ])
            >>> collection = Collection("test_create_partition", schema)
            >>> collection.create_partition("comedy", description="comedy films")
            {"name": "comedy", "collection_name": "test_create_partition", "description": ""}
            >>> collection.partition("comedy")
            {"name": "comedy", "collection_name": "test_create_partition", "description": ""}
        Tr7   rX   )r   r   r   PartitionAlreadyExistr"   )rL   r   rX   rM   s       rT   create_partitionzCollection.create_partition  sV    2 4n77774??09J9`aaaa~QQ;Q&QQQrV   c                 V    |                                  } |j        | j        |fd|i|S )a  Checks if a specified partition exists.

        Args:
            partition_name (``str``): The name of the partition to check.
            timeout (``float``, optional): 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:
            bool: True if exists, otherwise false.

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
        r   )r-   r   r9   rL   r   r   rM   rN   s        rT   r   zCollection.has_partition  s:    : ##%%!t!$*nXXgXQWXXXrV   c                 V    |                                  } |j        | j        |fd|i|S )a  Drop the partition in this collection.

        Args:
            partition_name (``str``): The name of the partition to drop.
            timeout (``float``, optional): 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:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
        r   )r-   drop_partitionr9   r   s        rT   r   zCollection.drop_partition  s:    6 ##%%"t"4:~YYwYRXYYYrV   c                 `   |                                  }g }|                    | j                  }|D ]z}|vd |j        D             }|                    d          rt          j        |d                   |d<   t          | |j        ||j	        d          }|
                    |           {|S )a  List[Index]: list of indexes of this collection.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
            []
        Nc                 (    i | ]}|j         |j        S rr   r   )r   kvs     rT   r   z&Collection.indexes.<locals>.<dictcomp>  s    EEE"RVRXEEErV   r   T)r   
field_nameindex_params
index_namer   )r-   list_indexesr9   r   r?   jsonloadsr   r   r   r[   )rL   rN   indexes	tmp_indexindex	info_dict
index_infos          rT   r  zCollection.indexes  s     ##%%%%dj11	 	+ 	+E EEEEE	==** J*.*Yx5H*I*IIh'"#$/!*$/#'  
 z***rV   c                    t          j        |          }|                    dt          j                  }|                                 } |j        | j        |fi |}||                    dd          }|                    d|          }|                    d           |                    d           |                    d           |                    d           t          | ||d|	          S t          t          j        
          )a  Get the index object of index name.

        Args:
            **kwargs (``dict``):
                * *index_name* (``str``)
                    The name of index. If no index is specified, the default index name is used.

        Returns:
            Index: Index object corresponding to index_name.

        Raises:
            IndexNotExistException: If the index doesn't exists.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
            [<pymilvus.index.Index object at 0x7f4435587e20>]
            >>> collection.index()
            <pymilvus.index.Index object at 0x7f44355a1460>
        r   Nr   
total_rowsindexed_rowspending_index_rowsstateT)r   r   r7   )copydeepcopyrv   r   	IndexNamer-   describe_indexr9   r   r   r   IndexNotExist)rL   rM   copy_kwargsr   rN   r  r   s          rT   r  zCollection.index  s    : mF++ __\63CDD
##%%'D'
JNN+NN	 "|T::J"|Z@@JMM,'''MM.)))MM.///MM'"""z9TV`aaaa$->-LMMMMrV   r   r   c                 X    |                                  } |j        | j        ||fd|i|S )a  Creates index for a specified field, with a index name.

        Args:
            field_name (``str``): The name of the field to create index
            index_params (``dict``, optional): The parameters to index
                * *index_type* (``str``)
                    "index_type" as the key, example values: "FLAT", "IVF_FLAT", etc.

                * *metric_type* (``str``)
                    "metric_type" as the key, examples values: "L2", "IP", "JACCARD".

                * *params* (``dict``)
                    "params" as the key, corresponding index params.

            timeout (``float``, optional): 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.
            index_name (``str``): The name of index which will be created, must be unique.
                If no index name is specified, the default index name will be used.

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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_params = {
            ...     "index_type": "IVF_FLAT",
            ...     "params": {"nlist": 128},
            ...     "metric_type": "L2"}
            >>> collection.create_index("films", index_params, index_name="idx")
            Status(code=0, message='')
        r   )r-   create_indexr9   )rL   r   r   r   rM   rN   s         rT   r  zCollection.create_index0  s=    X ##%% t ZaawaZ`aaarV   r   extra_paramsc                 f    |                                  }|                    | j        |||          S )a  Alter index for a specified field, with a index name.

        Args:
            index_name (``str``): The name of the index to alter
            extra_params (``dict``): The parameters to index
                * *mmap.enabled* (``str``)
                    "mmap.enabled" as the key, example values: True or False.

            timeout (``float``, optional): 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:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> from pymilvus import IndexType, MetricType
            >>> schema = CollectionSchema([
            ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
            ...     FieldSchema("title", DataType.STRING),
            ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2)
            ... ])
            >>> collection = Collection("test_collection_alter_index", schema)
            >>> index_params = {
            ...     "index_type": IndexType.IVF_FLAT,
            ...     "metric_type": MetricType.L2,
            ...     "params": {"nlist": 128}
            ... }
            >>> collection.create_index("films", index_params, index_name="idx")
            Status(code=0, message='')
            >>> collection.alter_index("idx", {"mmap.enabled": True})
        r   )r-   alter_indexr9   )rL   r   r  r   rN   s        rT   r  zCollection.alter_index_  s5    N ##%%
JgVVVrV   c                     |                                  }t          j        |          }|                    dt          j                  } |j        | j        |fd|i|duS )as  Check whether a specified index exists.

        Args:
            timeout (``float``, optional): 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 (``dict``):
                * *index_name* (``str``)
                  The name of index. If no index is specified, the default index name will be used.

        Returns:
            bool: Whether the specified index exists.

        Examples:
            >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
        r   r   N)r-   r  r  rv   r   r  r  r9   )rL   r   rM   rN   r  r   s         rT   	has_indexzCollection.has_index  sh    6 ##%%mF++ __\63CDD
  D
JWWW;WW_cc	
rV   c                    t          j        |          }|                    dt          j                  }|                                 } |j        | j        |fd|i|}| |j        d| j        |d         ||d| dS dS )a  Drop index and its corresponding index files.
        Args:
            timeout (``float``, optional): 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 (``dict``):
                * *index_name* (``str``)
                  The name of index. If no index is specified, the default index name will be used.

        Raises:
            MilvusException: If anything goes wrong.

        Examples:
            >>> from pymilvus Collection, FieldSchema, CollectionSchema, DataType
            >>> 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
        r   r   Nr   )r   r   r   r   rr   )	r  r  rv   r   r  r-   r  r9   
drop_index)rL   r   rM   r  r   rN   r  s          rT   r  zCollection.drop_index  s    : mF++ __\63CDD
##%%'D'
J___S^__	 DO  $
$\2%	 
      ! rV   Fis_clusteringc                     |                                  }|r |j        | j        f||d|| _        dS  |j        | j        f||d|| _        dS )a  Compact merge the small segments in a collection

        Args:
            timeout (``float``, optional): 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.

            is_clustering (``bool``, optional): Option to trigger clustering compaction.

        Raises:
            MilvusException: If anything goes wrong.
        )r  r   N)r-   compactr9   clustering_compaction_idcompaction_id)rL   r  r   rM   rN   s        rT   r  zCollection.compact  s     ##%% 	,8DL
-*7- -LR- -D))) ".
"*7" "LR" "DrV   c                     |                                  }|r |j        | j        fd|i|S  |j        | j        fd|i|S )a  Get the current compaction state

        Args:
            timeout (``float``, optional): 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.

            is_clustering (``bool``, optional): Option to get clustering compaction state.

        Raises:
            MilvusException: If anything goes wrong.
        r   )r-   get_compaction_stater  r  rL   r   r  rM   rN   s        rT   r!  zCollection.get_compaction_state  su     ##%% 	,4,- 7>BH   )t();WWWWPVWWWrV   c                     |                                  }|r |j        | j        fd|i|S  |j        | j        fd|i|S )a  Block until the current collection's compaction completed

        Args:
            timeout (``float``, optional): 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.

            is_clustering (``bool``, optional): Option to get clustering compaction state.

        Raises:
            MilvusException: If anything goes wrong.
        r   )r-   wait_for_compaction_completedr  r  r"  s        rT   r$  z(Collection.wait_for_compaction_completed  su    $ ##%% 	545- 7>BH   2t1$2D``g`Y_```rV   c                 T    |                                  } |j        | j        fd|i|S )ai  Get the current compaction plans

        Args:
            timeout (``float``, optional): 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:
            CompactionPlans: All the plans' states of this compaction.
        r   )r-   get_compaction_plansr  r   s       rT   r&  zCollection.get_compaction_plans  s9     ##%%(t();WWWWPVWWWrV   c                 T    |                                  } |j        | j        fd|i|S )a^  Get the current loaded replica information

        Args:
            timeout (``float``, optional): 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:
            Replica: All the replica information.
        r   )r-   get_replicasr1   r   s       rT   r(  zCollection.get_replicas+  s7     ##%% t FFGFvFFFrV   c                 b    |                                  }|                    | j        |          S )Nr  )r-   r>   r1   )rL   r   rN   s      rT   r   zCollection.describe8  s.    ##%%''	7'CCCrV   )Nr0   re   )Nr   N)NN)NNNNrk   )NNNrk   )NNN)rY   )FN)NF)G__name__
__module____qualname__r   r   r$   rU   rc   r-   classmethodrs   rt   r   propertyr2   r   r   rX   r1   rz   r   r   r   r   r%   rj   floatr   r~   dictr   r   r   r   r   r   r   SparseMatrixInputTyper!   r   r   r   r   r   r   r   r   r   r   r"   r   r   r   r   r   r   r  r  r  r  r  r  r  r   r!  r$  r   r&  r   r(  r   rr   rV   rT   r/   r/   ?   s
        .2	]I ]I]I )*]I 	]I 
]I ]I ]I ]I~
# 
 
 
 
7 7 7 4C 4BL 4 4 4 [4l (    X     X 'S ' ' ' X' c    X &$ & & & X&  C       X  #c # # # X#2 ){ ) ) ) X); ;Xe_ ; ; ; ;2D DHUO D D D D0
 
 
 
 
 
 
@ +/#'	< <!$< < %	< < < <|G Gx G G G G6 )-#'	A
 A
D",e.IIJA
 !A
 %	A
 
A
 A
 A
 A
L )-#'	:# :#:# !:# %	:# :# :# :#~ )-#'	E[ E[D",e.IIJE[ !E[ %	E[ 
E[ E[ E[ E[Z #/3-1#'^K ^KD%556^K ^K 	^K
 ^K sm^K "$s),^K  S	*^K %^K ^K ^K ^K ^KJ 04-1#'LK LKLK LK 	LK
 "$s),LK  S	*LK %LK LK LK LK LKf %)("/3-1#'
 
D%556
 
 	

 SM
 }
 sm
 "$s),
  S	*
 %
 
 
 
 
H .2/3#'[
 [
[
  S	*[
 "$s),	[

 %[
 [
 [
 [
~ %)("-1/3#'
 
SM
 }
 sm	

  S	*
 "$s),
 %
 
 
 
2 DO    X.N N) N N N N4R Rs R RXa R R R R:Y YC Y(5/ Y_c Y Y Y Y@Z ZS Z8E? Z Z Z Z< e    X@)N )N )N )N )N\ (,#'	-b -b-b tn-b %	-b -b -b -bf $(	(W (W(W (W %	(W (W (W (WT!
 !
% !
d !
 !
 !
 !
F( ((5/ ( ( ( (V QU %d^>Fuo   4 PUX XX>FtnX	X X X X0 $((-a a%a  ~a
 
a a a a2X XHUO XQ` X X X XG GHUO G G G G GD D D D D D D DrV   r/   )Ar  r   typingr   r   r   r   pandasrs   pymilvus.clientr   pymilvus.client.abstractr   r	   pymilvus.client.constantsr
   pymilvus.client.typesr   r   r   r   r   pymilvus.exceptionsr   r   r   r   r   r   r   pymilvus.grpc_genr   pymilvus.settingsr   r   	constantsr   futurer   r   r  r   iteratorr   r    mutationr!   r   r"   preparer#   r2   r$   r%   r&   r'   r(   r)   r*   r+   typesr,   utilityr-   r/   rr   rV   rT   <module>rB     s     . . . . . . . . . . . .     ! ! ! ! ! ! = = = = = = = = ? ? ? ? ? ?                               ) ( ( ( ( ( $ $ $ $ $ $ $ $ $ $ $ $             0 0 0 0 0 0 0 0       3 3 3 3 3 3 3 3 $ $ $ $ $ $                  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	       $ $ $ $ $ ${D {D {D {D {D {D {D {D {D {DrV   