
    j                         d dl m Z mZmZ d dlmZmZmZ d dl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 d	d
lmZ d_dededee         fdZd_dededee         fdZ	 d_de dedee         fdZd`dedee         fdZdefdZdefdZ	 	 	 dadedeee                  dedee         fdZ	 	 	 dadedeee                  dedee         fd Z	 	 	 dbdedeee                  dee         defd!Z	 	 	 dcded#ededee         fd$Z	 	 	 ddded#edee         defd%Zdedededee         fd&Z 	 	 deded'ededee         d(e!f
d)Z"dfdedee         defd*Z#	 	 	 ddd+ed,ed-edee         def
d.Z$dfdee         ded(e%fd/Z&	 	 	 	 dgded0ed1eee                  d2eee                  dee         defd3Z'	 	 dfdedee         defd4Z(	 	 dfdededee         defd5Z)dfdedee         defd6Z*	 	 dfdededee         defd7Z+dfdedee         defd8Z,	 	 	 dbded9ee         d'ee         dee         ded(efd:Z-	 	 dfd;edee         ded(efd<Z.	 	 	 	 dhd=edee         dee         ded(e%f
d>Z/	 	 ded?ed@edAededee         f
dBZ0	 	 ded?edCededee         fdDZ1	 	 ded?ed@edAededee         f
dEZ2ded?ededee         fdFZ3dededee         fdGZ4dedHe!dedee         fdIZ5	 	 dedJedKe!dedee         fdLZ6dedKe!dedee         fdMZ7dededee         d(efdNZ8	 dedOededee         fdPZ9	 	 dedQeee	f         dedee         fdRZ:dedOededee         fdSZ;dedOededee         fdTZ<dededee         fdUZ=	 	 dedVedWedXededee         f
dYZ>	 	 dedVedWededZededee         fd[Z?dededee         fd\Z@didefd]ZA	 	 dedededee         fd^ZBdS )j    )datetime	timedeltatimezone)ListMappingOptional)BulkInsertStateResourceGroupConfig)hybridts_to_unixtime)mkts_from_datetime)mkts_from_hybridts)mkts_from_unixtime)MilvusException   )connections        Nhybridtsmillisecondsdeltac                 &    t          | ||          S )aZ  Generate a hybrid timestamp based on an existing hybrid timestamp,
    timedelta and incremental time internval.

    :param hybridts: The original hybrid timestamp used to generate a new hybrid timestamp.
                     Non-negative interger range from 0 to 18446744073709551615.
    :type  hybridts: int

    :param milliseconds: Incremental time interval. The unit of time is milliseconds.
    :type  milliseconds: float

    :param delta: A duration expressing the difference between two date, time, or datetime instances
                  to microsecond resolution.
    :type  delta: datetime.timedelta

    :return int:
        Hybrid timetamp is a non-negative interger range from 0 to 18446744073709551615.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> _DIM = 128
        >>> field_int64 = FieldSchema("int64", DataType.INT64, description="int64", is_primary=True)
        >>> field_vector = FieldSchema("float_vector", DataType.FLOAT_VECTOR,  dim=_DIM)
        >>> schema = CollectionSchema(fields=[field_int64, field_vector])
        >>> collection = Collection(name="test_collection", schema=schema)
        >>> import pandas as pd
        >>> int64_series = pd.Series(data=list(range(10, 20)), index=list(range(10)))i
        >>> float_vector_series = [[random.random() for _ in range _DIM] for _ in range (10)]
        >>> data = pd.DataFrame({"int64" : int64_series, "float_vector": float_vector_series})
        >>> m = collection.insert(data)
        >>> ts_new = utility.mkts_from_hybridts(m.timestamp, milliseconds=1000.0)
    r   r   )_mkts_from_hybridts)r   r   r   s      ^/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/pymilvus/orm/utility.pyr   r      s    @ xl%PPPP    epochc                 &    t          | ||          S )a  
    Generate a hybrid timestamp based on Unix Epoch time, timedelta and incremental time internval.

    :param epoch: The known Unix Epoch time used to generate a hybrid timestamp.
                  The Unix Epoch time is the number of seconds that have elapsed
                  since January 1, 1970 (midnight UTC/GMT).
    :type  epoch: float

    :param milliseconds: Incremental time interval. The unit of time is milliseconds.
    :type  milliseconds: float

    :param delta: A duration expressing the difference between two date, time, or datetime instances
                  to microsecond resolution.
    :type  delta: datetime.timedelta

    :return int:
        Hybrid timetamp is a non-negative interger range from 0 to 18446744073709551615.

    :example:
        >>> import time
        >>> from pymilvus import utility
        >>> epoch_t = time.time()
        >>> ts = utility.mkts_from_unixtime(epoch_t, milliseconds=1000.0)
    r   )_mkts_from_unixtime)r   r   r   s      r   r   r   @   s    2 u<uMMMMr   d_timec                 &    t          | ||          S )a.  
    Generate a hybrid timestamp based on datetime, timedelta and incremental time internval.

    :param d_time: The known datetime used to generate a hybrid timestamp.
    :type  d_time: datetime.datetime.

    :param milliseconds: Incremental time interval. The unit of time is milliseconds.
    :type  milliseconds: float

    :param delta: A duration expressing the difference between two date, time, or datetime instances
                  to microsecond resolution.
    :type  delta:  datetime.timedelta

    :return int:
        Hybrid timetamp is a non-negative interger range from 0 to 18446744073709551615.

    :example:
        >>> import datetime
        >>> from pymilvus import utility
        >>> d = datetime.datetime.now()
        >>> ts = utility.mkts_from_datetime(d, milliseconds=1000.0)
    r   )_mkts_from_datetime)r   r   r   s      r   r   r   \   s    2 vLNNNNr   tzc                     ddl }|'t          ||j                  sd}t          |          t	          |           }|j                             ||          S )a*  
    Convert a hybrid timestamp to the datetime according to timezone.

    :param hybridts: The known hybrid timestamp to convert to datetime.
                     Non-negative interger range from 0 to 18446744073709551615.
    :type  hybridts: int
    :param tz: Timezone defined by a fixed offset from UTC. If argument tz is None or not specified,
               the hybridts is converted to the platform`s local date and time.
    :type  tz: datetime.timezone

    :return datetime:
        The datetime object.

    :raises Exception: If parameter tz is not of type datetime.timezone.

    :example:
        >>> import time
        >>> from pymilvus import utility
        >>> epoch_t = time.time()
        >>> ts = utility.mkts_from_unixtime(epoch_t)
        >>> d = utility.hybridts_to_datetime(ts)
    r   Nz0parameter tz should be type of datetime.timezone)message)r!   )r   
isinstancer   r   _hybridts_to_unixtimefromtimestamp)r   r!   r   msgr   s        r   hybridts_to_datetimer(   x   sb    . OOO	~jX->??~@c****!(++E**5R*888r   c                      t          |           S )a  
    Convert a hybrid timestamp to UNIX Epoch time ignoring the logic part.

    :param hybridts: The known hybrid timestamp to convert to UNIX Epoch time.
                     Non-negative interger range from 0 to 18446744073709551615.
    :type  hybridts: int

    :return float:
        The Unix Epoch time is the number of seconds that have elapsed since
        January 1, 1970 (midnight UTC/GMT).

    :example:
        >>> import time
        >>> from pymilvus import utility
        >>> epoch1 = time.time()
        >>> ts = utility.mkts_from_unixtime(epoch1)
        >>> epoch2 = utility.hybridts_to_unixtime(ts)
        >>> assert epoch1 == epoch2
    )r%   )r   s    r   r   r      s    ( !***r   aliasc                 *    t          j        |           S N)r   _fetch_handler)r*   s    r   _get_connectionr.      s    %e,,,r   defaultcollection_namepartition_namesusingtimeoutc                 \    t          |                              | ||          }d|ddiS )a\  Show loading progress of sealed segments in percentage.

    :param collection_name: The name of collection is loading
    :type  collection_name: str

    :param partition_names: The names of partitions is loading
    :type  partition_names: str list

    :return dict:
        {'loading_progress': '100%'}
    :raises MilvusException: If anything goes wrong.
    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> import pandas as pd
        >>> import random
        >>> fields = [
        ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
        ...     FieldSchema("films", DataType.FLOAT_VECTOR, dim=8),
        ... ]
        >>> schema = CollectionSchema(fields)
        >>> collection = Collection("test_loading_progress", schema)
        >>> data = pd.DataFrame({
        ...     "film_id" : pd.Series(data=list(range(10, 20)), index=list(range(10))),
        ...     "films": [[random.random() for _ in range(8)] for _ in range (10)],
        ... })
        >>> collection.insert(data)
        >>> collection.create_index(
        ...     "films",
        ...     {"index_type": "IVF_FLAT", "params": {"nlist": 8}, "metric_type": "L2"})
        >>> collection.load(_async=True)
        >>> utility.loading_progress("test_loading_progress")
        {'loading_progress': '100%'}
    r3   loading_progressz.0f%)r.   get_loading_progress)r0   r1   r2   r3   progresss        r   r6   r6      sK    N u%%::' ;  H 	x.... r   c                 L    t          |                              | ||          S )a  Show load state of collection or partitions.
    :param collection_name: The name of collection is loading
    :type  collection_name: str

    :param partition_names: The names of partitions is loading
    :type  partition_names: str list

    :return LoadState:
        The current state of collection or partitions.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> from pymilvus.client.types import LoadState
        >>> import pandas as pd
        >>> import random
        >>> assert utility.load_state("test_load_state") == LoadState.NotExist
        >>> fields = [
        ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
        ...     FieldSchema("films", DataType.FLOAT_VECTOR, dim=8),
        ... ]
        >>> schema = CollectionSchema(fields)
        >>> collection = Collection("test_load_state", schema)
        >>> assert utility.load_state("test_load_state") == LoadState.NotLoad
        >>> data = pd.DataFrame({
        ...     "film_id" : pd.Series(data=list(range(10, 20)), index=list(range(10))),
        ...     "films": [[random.random() for _ in range(8)] for _ in range (10)],
        ... })
        >>> collection.insert(data)
        >>> collection.create_index(
        ...     "films",
        ...     {"index_type": "IVF_FLAT", "params": {"nlist": 8}, "metric_type": "L2"})
        >>> collection.load(_async=True)
        >>> assert utility.load_state("test_load_state") == LoadState.Loaded
    r5   )r.   get_load_state)r0   r1   r2   r3   s       r   
load_stater<      s)    P 5!!00/[b0cccr   c                     |rt          |          dk    r$t          |                              | |          S t          |                              | ||          S )aa  
    Block until loading is done or Raise Exception after timeout.

    :param collection_name: The name of collection to wait for loading complete
    :type  collection_name: str

    :param partition_names: The names of partitions to wait for loading complete
    :type  partition_names: str list

    :param timeout: The timeout for this method, unit: second
    :type  timeout: int

    :raises MilvusException: If anything goes wrong.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> _DIM = 128
        >>> field_int64 = FieldSchema("int64", DataType.INT64, description="int64", is_primary=True)
        >>> field_fvec = FieldSchema("float_vector", DataType.FLOAT_VECTOR, dim=_DIM)
        >>> schema = CollectionSchema(fields=[field_int64, field_fvec])
        >>> collection = Collection(name="test_collection", schema=schema)
        >>> import pandas as pd
        >>> int64_series = pd.Series(data=list(range(10, 20)), index=list(range(10)))i
        >>> float_vector_series = [[random.random() for _ in range _DIM] for _ in range (10)]
        >>> data = pd.DataFrame({"int64" : int64_series, "float_vector": float_vector_series})
        >>> collection.insert(data)
        >>> collection.load() # load collection to memory
        >>> utility.wait_for_loading_complete("test_collection")
    r   r5   )lenr.   wait_for_loading_collectionwait_for_loading_partitions)r0   r1   r3   r2   s       r   wait_for_loading_completerA     sn    F  dc/22a77u%%AA/[bAccc5!!==' >   r    
index_namec                 L    t          |                              | ||          S )a  
    Show # indexed entities vs. # total entities.

    :param collection_name: The name of collection is building index
    :type  collection_name: str

    :param index_name: The name of index is building.
                        Default index_name is to be used if index_name is not specific.
    :type index_name: str

    :return dict:

        Index building progress is a dict contains num of indexed entities and num of total
        entities.
        {'total_rows':total_rows,'indexed_rows':indexed_rows}

    :raises CollectionNotExistException: If collection doesn't exist.
    :raises IndexNotExistException: If index doesn't exist.
    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> fields = [
        ...     FieldSchema("int64", DataType.INT64, is_primary=True, auto_id=True),
        ...     FieldSchema("float_vector", DataType.FLOAT_VECTOR, dim=128),
        ... ]
        >>> schema = CollectionSchema(fields, description="test index_building_progress")
        >>> c = Collection(name="test_index_building_progress", schema=schema)

        >>> import random
        >>> vectors = [[random.random() for _ in range(_DIM)] for _ in range(5000)]
        >>> c.insert([vectors])
        >>> c.load()
        >>> index_params = {
        ...    "metric_type": "L2",
        ...    "index_type": "IVF_FLAT",
        ...    "params": {"nlist": 1024}
        ... }
        >>> index = c.create_index(
        ...     field_name="float_vector",
        ...     index_params=index_params,
        ...     index_name="ivf_flat")
        >>> utility.index_building_progress("test_collection", c.name)
    )r0   rC   r3   )r.   get_index_build_progress)r0   rC   r2   r3   s       r   index_building_progressrF   7  s1    ` 5!!::'J ;   r   c                 X    t          |                              | ||          d         S )a"  
    Block until building is done or Raise Exception after timeout.

    :param collection_name: The name of collection to wait
    :type  collection_name: str

    :param index_name: The name of index to wait
    :type  index_name: str

    :param timeout: The timeout for this method, unit: second
    :type  timeout: int

    :raises CollectionNotExistException: If collection doesn't exist.
    :raises IndexNotExistException: If index doesn't exist.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> _DIM = 128
        >>> field_int64 = FieldSchema("int64", DataType.INT64, description="int64", is_primary=True)
        >>> field_vector = FieldSchema("float_vector", DataType.FLOAT_VECTOR, dim=_DIM)
        >>> schema = CollectionSchema(fields=[field_int64, field_vector], description="test")
        >>> collection = Collection(name="test_collection", schema=schema)
        >>> import random
        >>> import numpy as np
        >>> import pandas as pd
        >>> vectors = [[random.random() for _ in range(_DIM)] for _ in range(5000)]
        >>> int64_series = pd.Series(data=list(range(5000, 10000)), index=list(range(5000)))
        >>> vectors = [[random.random() for _ in range(_DIM)] for _ in range (5000)]
        >>> data = pd.DataFrame({"int64" : int64_series, "float_vector": vectors})
        >>> collection.insert(data)
        >>> collection.load() # load collection to memory
        >>> index_param = {
        >>>    "metric_type": "L2",
        >>>    "index_type": "IVF_FLAT",
        >>>    "params": {"nlist": 1024}
        >>> }
        >>> collection.create_index("float_vector", index_param)
        >>> utility.index_building_progress("test_collection", "")
        >>> utility.loading_progress("test_collection")

    r5   r   )r.   wait_for_creating_index)r0   rC   r3   r2   s       r    wait_for_index_building_completerI   l  s9    ^ 5!!99W :  	 	r   c                 J    t          |                              | |          S )a  
    Checks whether a specified collection exists.

    :param collection_name: The name of collection to check.
    :type  collection_name: str

    :return bool:
        Whether the collection exists.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> _DIM = 128
        >>> field_int64 = FieldSchema("int64", DataType.INT64, description="int64", is_primary=True)
        >>> field_vector = FieldSchema("float_vector", DataType.FLOAT_VECTOR,  dim=_DIM)
        >>> schema = CollectionSchema(fields=[field_int64, field_vector], description="test")
        >>> collection = Collection(name="test_collection", schema=schema)
        >>> utility.has_collection("test_collection")
    r5   )r.   has_collection)r0   r2   r3   s      r   rK   rK     s%    & 5!!00'0RRRr   partition_namereturnc                 L    t          |                              | ||          S )aS  
    Checks if a specified partition exists in a collection.

    :param collection_name: The collection name of partition to check
    :type  collection_name: str

    :param partition_name: The name of partition to check.
    :type  partition_name: str

    :return bool:
        Whether the partition exist.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> _DIM = 128
        >>> field_int64 = FieldSchema("int64", DataType.INT64, description="int64", is_primary=True)
        >>> field_vector = FieldSchema("float_vector", DataType.FLOAT_VECTOR, dim=_DIM)
        >>> schema = CollectionSchema(fields=[field_int64, field_vector], description="test")
        >>> collection = Collection(name="test_collection", schema=schema)
        >>> utility.has_partition("_default")
    r5   )r.   has_partition)r0   rL   r2   r3   s       r   rO   rO     s(    6 5!!//Y`/aaar   c                 J    t          |                              | |          S )a  
    Drop a collection by name

    :param collection_name: A string representing the collection to be deleted
    :type  collection_name: str
    :param timeout: 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.
    :type  timeout: float

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> schema = CollectionSchema(fields=[
        ...     FieldSchema("int64", DataType.INT64, description="int64", is_primary=True),
        ...     FieldSchema("float_vector", DataType.FLOAT_VECTOR, is_primary=False, dim=128),
        ... ])
        >>> collection = Collection(name="drop_collection_test", schema=schema)
        >>> utility.has_collection("drop_collection_test")
        >>> True
        >>> utility.drop_collection("drop_collection_test")
        >>> utility.has_collection("drop_collection_test")
        >>> False
    r5   )r.   drop_collectionr0   r3   r2   s      r   rQ   rQ     s%    . 5!!11/71SSSr   old_collection_namenew_collection_namenew_db_namec                 N    t          |                              | |||          S )a  
    Rename a collection to new collection name

    :param old_collection_name: A string representing old name of the renamed collection
    :type  old_collection_name: str

    :param new_collection_name: A string representing new name of the renamed collection
    :type  new_collection_name: str

    :param timeout: 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.
    :type  timeout: float

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> schema = CollectionSchema(fields=[
        ...     FieldSchema("int64", DataType.INT64, description="int64", is_primary=True),
        ...     FieldSchema("float_vector", DataType.FLOAT_VECTOR, is_primary=False, dim=128),
        ... ])
        >>> collection = Collection(name="old_collection", schema=schema)
        >>> utility.rename_collection("old_collection", "new_collection")
        >>> True
        >>> utility.drop_collection("new_collection")
        >>> utility.has_collection("new_collection")
        >>> False
    )old_namenew_namerU   r3   )r.   rename_collections)rS   rT   rU   r3   r2   s        r   rename_collectionrZ     s6    B 5!!44$$	 5   r   c                 H    t          |                              |           S )a  
    Returns a list of all collection names.

    :param timeout: 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.
    :type  timeout: float

    :param using: An optional alias for the database host. Default value is "default".
    :type using: str

    :return list[str]:
        List of collection names, return when operation is successful

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> _DIM = 128
        >>> field_int64 = FieldSchema("int64", DataType.INT64, description="int64", is_primary=True)
        >>> field_vector = FieldSchema("float_vector", DataType.FLOAT_VECTOR, dim=_DIM)
        >>> schema = CollectionSchema(fields=[field_int64, field_vector], description="test")
        >>> collection = Collection(name="test_collection", schema=schema)
        >>> utility.list_collections()
    r5   )r.   list_collections)r3   r2   s     r   r\   r\     s#    . 5!!2272CCCr   src_node_iddst_node_idssealed_segment_idsc                 `    |g }|g }t          |                              | ||||          S )a  Do load balancing operation from source query node to destination query node.

    :param collection_name: The collection to balance.
    :type  collection_name: str

    :param src_node_id: The source query node id to balance.
    :type  src_node_id: int

    :param dst_node_ids: The destination query node ids to balance.
    :type  dst_node_ids: list[int]

    :param sealed_segment_ids: Sealed segment ids to balance.
    :type  sealed_segment_ids: list[int]

    :param timeout: The timeout for this method, unit: second
    :type  timeout: int

    :raises BaseException: If query nodes not exist.
    :raises BaseException: If sealed segments not exist.

    :example:
        >>> from pymilvus import connections, utility
        >>>
        >>> connections.connect()
        >>>
        >>> src_node_id = 0
        >>> dst_node_ids = [1]
        >>> sealed_segment_ids = []
        >>> res = utility.load_balance("test", src_node_id, dst_node_ids, sealed_segment_ids)
    Nr5   )r.   load_balance)r0   r]   r^   r_   r3   r2   s         r   ra   ra   1  sN    L !5!!..l4FPW /   r   c                 J    t          |                              | |          S )a  
    Notifies Proxy to return segments information from query nodes.

    :param collection_name: A string representing the collection to get segments info.
    :param timeout: 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.
    :type  timeout: float

    :return: QuerySegmentInfo:
        QuerySegmentInfo is the growing segments's information in query cluster.
    :rtype: QuerySegmentInfo

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> _DIM = 128
        >>> field_int64 = FieldSchema("int64", DataType.INT64, description="int64", is_primary=True)
        >>> field_vector = FieldSchema("float_vector", DataType.FLOAT_VECTOR,  dim=_DIM)
        >>> schema = CollectionSchema(fields=[field_int64, field_vector])
        >>> collection = Collection(name="test_get_segment_info", schema=schema)
        >>> import pandas as pd
        >>> int64_series = pd.Series(data=list(range(10, 20)), index=list(range(10)))i
        >>> float_vector_series = [[random.random() for _ in range _DIM] for _ in range (10)]
        >>> data = pd.DataFrame({"int64" : int64_series, "float_vector": float_vector_series})
        >>> collection.insert(data)
        >>> collection.load() # load collection to memory
        >>> res = utility.get_query_segment_info("test_get_segment_info")
    r5   )r.   get_query_segment_inforR   s      r   rc   rc   `  s'    @ 5!!88RY8ZZZr   c                 L    t          |                              | ||          S )a  Specify alias for a collection.
    Alias cannot be duplicated, you can't assign the same alias to different collections.
    But you can specify multiple aliases for a collection, for example:
        before create_alias("collection_1", "bob"):
            aliases of collection_1 are ["tom"]
        after create_alias("collection_1", "bob"):
            aliases of collection_1 are ["tom", "bob"]

    :param alias: The alias of the collection.
    :type  alias: str.

    :param timeout: 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
    :type  timeout: float

    :raises CollectionNotExistException: If the collection does not exist.
    :raises BaseException: If the alias failed to create.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> schema = CollectionSchema([
        ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
        ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2)
        ... ])
        >>> collection = Collection("test_collection_create_alias", schema)
        >>> utility.create_alias(collection.name, "alias")
        Status(code=0, message='')
    r5   )r.   create_aliasr0   r*   r3   r2   s       r   re   re     s(    D 5!!..w.WWWr   c                 J    t          |                              | |          S )a  Delete the alias.
    No need to provide collection name because an alias can only be assigned to one collection
    and the server knows which collection it belongs.
    For example:
        before drop_alias("bob"):
            aliases of collection_1 are ["tom", "bob"]
        after drop_alias("bob"):
            aliases of collection_1 are = ["tom"]

    :param alias: The alias to drop.
    :type  alias: str

    :param timeout: 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
    :type  timeout: float

    :raises CollectionNotExistException: If the collection does not exist.
    :raises BaseException: If the alias doesn't exist.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> schema = CollectionSchema([
        ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
        ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2)
        ... ])
        >>> collection = Collection("test_collection_drop_alias", schema)
        >>> utility.create_alias(collection.name, "alias")
        >>> utility.drop_alias("alias")
        Status(code=0, message='')
    r5   )r.   
drop_alias)r*   r3   r2   s      r   rh   rh     s%    > 5!!,,UG,DDDr   c                 L    t          |                              | ||          S )aa  Change the alias of a collection to another collection.
    Raise error if the alias doesn't exist.
    Alias cannot be duplicated, you can't assign same alias to different collections.
    This api can change alias owner collection, for example:
        before alter_alias("collection_2", "bob"):
            collection_1's aliases = ["bob"]
            collection_2's aliases = []
        after alter_alias("collection_2", "bob"):
            collection_1's aliases = []
            collection_2's aliases = ["bob"]

    :param collection_name: The collection name to witch this alias is goting to alter.
    :type  collection_name: str.

    :param alias: The alias of the collection.
    :type  alias: str

    :param timeout: 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
    :type  timeout: float

    :raises CollectionNotExistException: If the collection does not exist.
    :raises BaseException: If the alias failed to alter.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> schema = CollectionSchema([
        ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
        ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2)
        ... ])
        >>> collection = Collection("test_collection_alter_alias", schema)
        >>> utility.alter_alias(collection.name, "alias")
        if the alias exists, return Status(code=0, message='')
        otherwise return Status(code=1, message='alias does not exist')
    r5   )r.   alter_aliasrf   s       r   rj   rj     s(    R 5!!--oug-VVVr   c                 ^    t          |          }|                    | |          }|d         S )a  Returns alias list of the collection.

    :return list of str:
        The collection aliases, returned when the operation succeeds.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> fields = [
        ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
        ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=128)
        ... ]
        >>> schema = CollectionSchema(fields)
        >>> collection = Collection("test_collection_list_aliases", schema)
        >>> utility.create_alias(collection.name, "tom")
        >>> utility.list_aliases(collection.name)
        ['tom']
    r5   aliases)r.   describe_collection)r0   r3   r2   connresps        r   list_aliasesrp     s3    $ 5!!D##OW#EED	?r   filesc                 @     t          |          j        | ||fd|i|S )a  do_bulk_insert inserts entities through files, currently supports row-based json file.
    User need to create the json file with a specified json format which is described in
    the official user guide.

    Let's say a collection has two fields: "id" and "vec"(dimension=8),
    the row-based json format is:

      {"rows": [
          {"id": "0", "vec": [0.190, 0.046, 0.143, 0.972, 0.592, 0.238, 0.266, 0.995]},
          {"id": "1", "vec": [0.149, 0.586, 0.012, 0.673, 0.588, 0.917, 0.949, 0.944]},
          ......
        ]
      }

    The json file must be uploaded to root path of MinIO/S3 storage which is
    accessed by milvus server. For example:

        the milvus.yml specify the MinIO/S3 storage bucketName as "a-bucket",
        user can upload his json file to a-bucket/xxx.json,
        then call do_bulk_insert(files=["a-bucket/xxx.json"])

    :param collection_name: the name of the collection
    :type  collection_name: str

    :param partition_name: the name of the partition
    :type  partition_name: str

    :param files: related path of the file to be imported, for row-based json file,
        only allow one file each invocation.
    :type  files: list[str]

    :param timeout: The timeout for this method, unit: second
    :type  timeout: int

    :param kwargs: other infos

    :return: id of the task
    :rtype:  int

    :raises BaseException: If collection_name doesn't exist.
    :raises BaseException: If the files input is illegal.

    :example:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> schema = CollectionSchema([
        ...     FieldSchema("film_id", DataType.INT64, is_primary=True),
        ...     FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2)
        ... ])
        >>> collection = Collection("test_collection_bulk_insert", schema)
        >>> task_id = utility.do_bulk_insert(collection_name=collection.name, files=['data.json'])
        >>> print(task_id)
    r3   )r.   do_bulk_insert)r0   rq   rL   r3   r2   kwargss         r   rs   rs     s@    x 1?5!!0 8?CI  r   task_idc                 <     t          |          j        | fd|i|S )a  get_bulk_insert_state returns state of a certain task_id

    :param task_id: the task id returned by bulk_insert
    :type  task_id: int

    :return: BulkInsertState
    :rtype:  BulkInsertState

    :example:
        >>> from pymilvus import connections, utility, BulkInsertState
        >>> connections.connect()
        >>> # the id is returned by do_bulk_insert()
        >>> state = utility.get_bulk_insert_state(task_id=id)
        >>> if state.state == BulkInsertState.ImportFailed or         ...     state.state == BulkInsertState.ImportFailedAndCleaned:
        >>>     print("task id:", state.task_id, "failed, reason:", state.failed_reason)
    r3   )r.   get_bulk_insert_state)ru   r3   r2   rt   s       r   rw   rw   N  s-    . 8?5!!7[[[TZ[[[r   limitc                 >     t          |          j        | |fd|i|S )al  list_bulk_insert_tasks lists all bulk load tasks

    :param limit: maximum number of tasks returned, list all tasks if the value is 0,
        else return the latest tasks
    :type  limit: int

    :param collection_name: target collection name, list all tasks if the name is empty
    :type  collection_name: str

    :return: list[BulkInsertState]
    :rtype:  list[BulkInsertState]

    :example:
        >>> from pymilvus import connections, utility, BulkInsertState
        >>> connections.connect()
        >>> tasks = utility.list_bulk_insert_tasks(collection_name=collection_name)
        >>> print(tasks)
    r3   )r.   list_bulk_insert_tasks)rx   r0   r3   r2   rt   s        r   rz   rz   h  s=    2 9?5!!8 (/39  r   userold_passwordnew_passwordc                 N    t          |                              | |||          S )a  
        Reset the user & password of the connection.
        You must provide the original password to check if the operation is valid.
        Note: after this operation, the connection is also ready to use.

    :param user: the user of the Milvus connection.
    :type  user: str
    :param old_password: the original password of the Milvus connection.
    :type  old_password: str
    :param new_password: the newly password of this user.
    :type  new_password: str

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> utility.reset_password(user, old_password, new_password)
        >>> users = utility.list_usernames()
        >>> print(f"users in Milvus: {users}")
    r5   )r.   reset_passwordr{   r|   r}   r2   r3   s        r   r   r     s*    4 5!!00|\[b0cccr   passwordc                 L    t          |                              | ||          S )a  Create User using the given user and password.
    :param user: the user name.
    :type  user: str
    :param password: the password.
    :type  password: str

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> utility.create_user(user, password)
        >>> connections.connect(user=user, password=password)
        >>> users = utility.list_usernames()
        >>> print(f"users in Milvus: {users}")
    r5   )r.   create_user)r{   r   r2   r3   s       r   r   r     s'    ( 5!!--dHg-NNNr   c                 N    t          |                              | |||          S )av  
        Update user password using the given user and password.
        You must provide the original password to check if the operation is valid.
        Note: after this operation, PyMilvus won't change the related header of this connection.
        So if you update credential for this connection, the connection may be invalid.

    :param user: the user name.
    :type  user: str
    :param old_password: the original password.
    :type  old_password: str
    :param new_password: the newly password of this user.
    :type  new_password: str

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> utility.update_password(user, old_password, new_password)
        >>> connections.connect(user=user, password=new_password)
        >>> users = utility.list_usernames()
        >>> print(f"users in Milvus: {users}")
    r5   )r.   update_passwordr   s        r   r   r     s*    8 5!!11$l\c1dddr   c                 J    t          |                              | |          S )aM  Delete User corresponding to the username.
    :param user: the user name.
    :type  user: str

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> utility.delete_user(user)
        >>> users = utility.list_usernames()
        >>> print(f"users in Milvus: {users}")
    r5   )r.   delete_user)r{   r2   r3   s      r   r   r     s%     5!!--dG-DDDr   c                 H    t          |                               |          S )a  List all usernames.
    :return list of str:
        The usernames in Milvus instances.

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> users = utility.list_usernames()
        >>> print(f"users in Milvus: {users}")
    r5   )r.   list_usernamesr2   r3   s     r   r   r     s#     5!!000AAAr   include_user_infoc                 J    t          |                              | |          S )ai  List All Role Info
    :param include_user_info: whether to obtain the user information associated with roles
    :type  include_user_info: bool
    :return RoleInfo

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> roles = utility.list_roles()
        >>> print(f"roles in Milvus: {roles}")
    r5   )r.   select_all_role)r   r2   r3   s      r   
list_rolesr     &     5!!112CW1UUUr   usernameinclude_role_infoc                 L    t          |                              | ||          S )a  List One User Info
    :param username: user name.
    :type  username: str
    :param include_role_info: whether to obtain the role information associated with the user
    :type  include_role_info: bool
    :return UserInfo

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> user = utility.list_user(username, include_role_info)
        >>> print(f"user info: {user}")
    r5   )r.   select_one_user)r   r   r2   r3   s       r   	list_userr     s)    & 5!!11(<MW^1___r   c                 J    t          |                              | |          S )au  List All User Info
    :param include_role_info: whether to obtain the role information associated with users
    :type  include_role_info: bool
    :return UserInfo

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> users = utility.list_users(include_role_info)
        >>> print(f"users info: {users}")
    r5   )r.   select_all_user)r   r2   r3   s      r   
list_usersr     r   r   c                 H    t          |                               |          S )zget the running server's version

    :returns: server's version
    :rtype: str

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> utility.get_server_version()
        >>> "2.2.0"
    r5   )r.   get_server_versionr   s     r   r   r   *  s#     5!!44W4EEEr   namec                 :     t          |          j        | |fi |S )a]  Create a resource group
        It will success whether or not the resource group exists.

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> utility.create_resource_group(name)
        >>> rgs = utility.list_resource_groups()
        >>> print(f"resource groups in Milvus: {rgs}")
    )r.   create_resource_group)r   r2   r3   rt   s       r   r   r   9  s)     8?5!!7gPPPPPr   configsc                 H    t          |                              | |          S )a  Update resource groups.
        This function updates the resource groups based on the provided configurations.

    :param configs: A mapping of resource group names to their configurations.
    :type configs: Mapping[str, ResourceGroupConfig]
    :param using: The name of the connection to use. Defaults to "default".
    :type using: (str, optional)
    :param timeout: The timeout value in seconds. Defaults to None.
    :type timeout: (float, optional)

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> configs = {
        ...     "resource_group_1": ResourceGroupConfig(
        ...         requests={"node_num": 1},
        ...         limits={"node_num": 5},
        ...         transfer_from=[{"resource_group": "resource_group_2"}],
        ...         transfer_to=[{"resource_group": "resource_group_2"}],
        ...     ),
        ...     "resource_group_2": ResourceGroupConfig(
        ...         requests={"node_num": 4},
        ...         limits={"node_num": 4},
        ...         transfer_from=[{"resource_group": "__default_resource_group"}],
        ...         transfer_to=[{"resource_group": "resource_group_1"}],
        ...     ),
        ... }
        >>> utility.update_resource_groups(configs)
    )r.   update_resource_groups)r   r2   r3   s      r   r   r   I  s#    D 5!!88'JJJr   c                 H    t          |                              | |          S )ak  Drop a resource group
        It will success if the resource group is existed and empty, otherwise fail.

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> utility.drop_resource_group(name)
        >>> rgs = utility.list_resource_groups()
        >>> print(f"resource groups in Milvus: {rgs}")
    )r.   drop_resource_groupr   r2   r3   s      r   r   r   n  s"     5!!55dGDDDr   c                 H    t          |                              | |          S )aA  Drop a resource group
        It will success if the resource group is existed and empty, otherwise fail.

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> rgInfo = utility.list_resource_groups(name)
        >>> print(f"resource group info: {rgInfo}")
    )r.   describe_resource_groupr   s      r   r   r   |  s"     5!!99$HHHr   c                 F    t          |                               |          S )a(  list all resource group names

    :return: all resource group names
    :rtype: list[str]
    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> rgs = utility.list_resource_groups()
        >>> print(f"resource group names: {rgs}")
    )r.   list_resource_groupsr   s     r   r   r     s      5!!66w???r   source_grouptarget_group	num_nodesc                 L    t          |                              | |||          S )a  transfer num_node from source resource group to target resource_group

    :param source_group: source resource group name
    :type source_group: str
    :param target_group: target resource group name
    :type target_group: str
    :param num_nodes: transfer node num
    :type num_nodes: int

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> rgs = utility.transfer_node(source_group, target_group, num_nodes)
    )r.   transfer_node)r   r   r   r2   r3   s        r   r   r     s'    * 5!!//lIW^___r   num_replicasc                 N    t          |                              | ||||          S )a[  transfer num_replica from source resource group to target resource group

    :param source_group: source resource group name
    :type source_group: str
    :param target_group: target resource group name
    :type target_group: str
    :param collection_name: collection name which replica belong to
    :type collection_name: str
    :param num_replicas: transfer replica num
    :type num_replicas: int

    :example:
        >>> from pymilvus import connections, utility
        >>> connections.connect()
        >>> rgs = utility.transfer_replica(source, target, collection_name, num_replica)
    )r.   transfer_replica)r   r   r0   r   r2   r3   s         r   r   r     s/    0 5!!22lO\7  r   c                 :     t          |           j        dd|i|S )a  Flush all collections. All insertions, deletions, and upserts before
        `flush_all` will be synced.

    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.
        **kwargs (``dict``, optional):
            * *db*(``string``)
                database to flush.
            * *_async*(``bool``)
                Indicate if invoke asynchronously. Default `False`.

    Examples:
        >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType, utility
        >>> 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]]])
        >>> utility.flush_all(_async=False) # synchronized flush_all
        >>> # or use `future` to flush_all asynchronously
        >>> future = utility.flush_all(_async=True)
        >>> future.done() # flush_all finished
    r3    )r.   	flush_all)r2   r3   rt   s      r   r   r     s*    8 ,?5!!+FFGFvFFFr   c                 D    t          |                                           S )aG  Get the server type. Now, it will return "zilliz" if the connection related to
        an instance on the zilliz cloud, otherwise "milvus" will be returned.

    :param using: Alias to the connection. Default connection is used if this is not specified.
    :type  using: str

    :return: The server type.
    :rtype: str
    )r.   get_server_type)r2   s    r   r   r     s     5!!11333r   c                      t          |          j        | |fi |}|                    d          }g }|D ]G}|C||                    |j                   |%|j        |k    r|                    |j                   H|S )a|  List all indexes of collection. If `field_name` is not specified,
        return all the indexes of this collection, otherwise this interface will return
        all indexes on this field of the collection.

    :param collection_name: The name of collection.
    :type  collection_name: str

    :param using: Alias to the connection. Default connection is used if this is not specified.
    :type  using: str

    :param timeout: 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
    :type  timeout: float/int

    :param kwargs:
        * *field_name* (``str``)
            The name of field. If no field name is specified, all indexes
            of this collection will be returned.
    :type  kwargs: dict

    :return: The name list of all indexes.
    :rtype: str list
    
field_name)r.   list_indexesgetappendrC   r   )r0   r2   r3   rt   indexesr   index_name_listindexs           r   r   r     s    : 2oe$$1/7UUfUUGL))JO 9 9!&&u'7888%%*:j*H*H&&u'7888r   )r   Nr,   )Nr/   N)NNr/   )rB   r/   N)rB   Nr/   )r/   N)Nr/   )NNNr/   )r   NNr/   )r/   )Cr   r   r   typingr   r   r   pymilvus.client.typesr	   r
   pymilvus.client.utilsr   r%   r   r    r   r   r   r   pymilvus.exceptionsr   r   intfloatr(   strr.   r6   r<   rA   rF   rI   rK   boolrO   rQ   rZ   listr\   ra   rc   re   rh   rj   rp   rs   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s   3 2 2 2 2 2 2 2 2 2 * * * * * * * * * *        P O O O O O K K K K K K K K K K K K K K K K K K / / / / / / $ $ $ $ $ $ Q  Q  QE  QQZH[  Q  Q  Q  QFN Ne N5 NxPYGZ N N N N: OSO OO$)O8@8KO O O O89 93 9HX,> 9 9 9 9@+3 + + + +.-3 - - - - ,0#	, ,,d3i(, , e_	, , , ,b ,0#	(d (d(dd3i((d (d e_	(d (d (d (dZ ,0#	' ''d3i(' e_' 	' ' ' 'X #	2 222 2 e_	2 2 2 2n #	1	 1	1	1	 e_1	 	1	 1	 1	 1	hS SC S S(SX/ S S S S2 #	b bbb b e_	b
 
b b b b<T TS T8E? TRU T T T T: #& &&& & e_	&
 & & & &RD Dhuo DS DQU D D D D: )-.2#, ,,, 49%, !c+	,
 e_, , , , ,b  $ [  [ [e_ [  [  [  [  [L  $	"X "X"X"X e_"X 	"X "X "X "XJE Ec EHUO E3 E E E EJ  $	)W )W)W)W e_)W 	)W )W )W )WX #  s    4 %)#> >>9> SM> e_	>
 > 	> > > >F  $\ \\e_\ \
 \ \ \ \6 %)#	 c] e_ 	 
   D #d d
dd d 	d
 e_d d d d@ #	O O
OO O e_	O O O O6 #e e
ee e 	e
 e_e e e e>E Ec E# EHUO E E E EB B# BHUO B B B BV V$ Vs VRW V V V V$ #	` ``` ` e_	` ` ` `,V V$ Vs VRW V V V VF Fc F FSV F F F F  CGQ Q
QQ08Q Q Q Q$ #"K "KS--."K"K e_"K "K "K "KJE Ec E# EHUO E E E E
I 
I# 
Ic 
IQV 
I 
I 
I 
I@ @ @(5/ @ @ @ @$ #` ``` ` 	`
 e_` ` ` `: #   	
  e_   :G GS Gx G G G G>
4 
43 
4 
4 
4 
4 #( ((( e_( ( ( ( ( (r   