
    ?h                         d Z ddlZddlZddlmZ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mZ dd
lmZ ddlmZm Z m!Z!m"Z"m#Z#  G d d      Z$deee%      de&de'fdZ(y)z
DataObject class definition.
    N)AnyDictListOptionalSequenceTupleUnioncast)ConnectionError)
Connection)	Reference)ConsistencyLevel)!DATA_DEPRECATION_NEW_V14_CLS_NS_W!DATA_DEPRECATION_OLD_V14_CLS_NS_W)ObjectAlreadyExistsExceptionUnexpectedStatusCodeException)UUID)_get_dict_from_object
get_vectorget_valid_uuid_capitalize_first_letter_check_positive_numc                      e Zd ZdZdefdZ	 	 	 	 ddeeef   dedeee	j                  df   dee   d	ee   d
ee   defdZ	 	 	 ddeeef   dedeee	j                  f   dee   d	ee   d
ee   ddfdZ	 	 	 ddeeef   dedeee	j                  f   dee   d	ee   d
ee   ddfdZ	 ddeeef   dedeee	j                  f   dee   deeeef   ef   f
dZ	 	 	 	 	 	 ddeee	j                  f   deee      dedee   dee   d	ee   d
ee   dee   fdZ	 	 	 	 	 	 	 	 	 	 	 d deee	j                  df   deee      dedee   dee   d	ee   dee   dee
   dee   deeeeeeee   ee   f   f      d
ee   deeeef      fdZ	 	 	 ddeee	j                  f   dee   d	ee   d
ee   ddf
dZ	 	 	 ddeee	j                  f   dee   d	ee   d
ee   def
dZ	 	 d!deeef   dedeee	j                  df   dee   def
dZy)"
DataObjectz
    DataObject class used to manipulate object to/from Weaviate.

    Attributes
    ----------
    reference : weaviate.data.references.Reference
        A Reference object to create objects cross-references.
    
connectionc                 F    || _         t        | j                         | _        y)z
        Initialize a DataObject class instance.

        Parameters
        ----------
        connection : weaviate.connect.Connection
            Connection object to an active and running Weaviate instance.
        N)_connectionr   	reference)selfr   s     U/home/chris/cleankitchens-env/lib/python3.12/site-packages/weaviate/data/crud_data.py__init__zDataObject.__init__&   s     &"4#3#34    Ndata_object
class_nameuuidvectorconsistency_leveltenantreturnc                 |   t        |t              st        dt        |             t	        |      }t        |      |d}|t        |      |d<   |t        |      |d<   d}	i }
|t        |      j                  |
d<   |||d<   	 | j                  j                  |	||
	      }|j                  dk(  rt        |j                         d         S d}	 d|j                         d   d   d   v rd}|rt!        t        |            t#        d|      # t        $ r}t        d
      |d}~ww xY w# t        $ r Y Jw xY w)a
  
        Takes a dict describing the object and adds it to Weaviate.

        Parameters
        ----------
        data_object : dict or str
            Object to be added.
            If type is str it should be either a URL or a file.
        class_name : str
            Class name associated with the object given.
        uuid : str, uuid.UUID or None, optional
            Object will be created under this uuid if it is provided.
            Otherwise, Weaviate will generate a uuid for this object,
            by default None.
        vector: Sequence or None, optional
            Embedding for the object.
            Can be used when:
             - a class does not have a vectorization module.
             - The given vector was generated using the _identical_ vectorization module that is configured for the
             class. In this case this vector takes precedence.

            Supported types are `list`, 'numpy.ndarray`, `torch.Tensor` and `tf.Tensor`,
            by default None.
        consistency_level : Optional[ConsistencyLevel], optional
            Can be one of 'ALL', 'ONE', or 'QUORUM'. Determines how many replicas must acknowledge
        tenant: Optional[str], optional
            The name of the tenant for which this operation is being performed.

        Examples
        --------
        Schema contains a class Author with only 'name' and 'age' primitive property.

        >>> client.data_object.create(
        ...     data_object = {'name': 'Neil Gaiman', 'age': 60},
        ...     class_name = 'Author',
        ... )
        '46091506-e3a0-41a4-9597-10e3064d8e2d'
        >>> client.data_object.create(
        ...     data_object = {'name': 'Andrzej Sapkowski', 'age': 72},
        ...     class_name = 'Author',
        ...     uuid = 'e067f671-1202-42c6-848b-ff4d1eb804ab'
        ... )
        'e067f671-1202-42c6-848b-ff4d1eb804ab'

        Returns
        -------
        str
            Returns the UUID of the created object if successful.

        Raises
        ------
        TypeError
            If argument is of wrong type.
        ValueError
            If argument contains an invalid value.
        weaviate.ObjectAlreadyExistsException
            If an object with the given uuid already exists within Weaviate.
        weaviate.UnexpectedStatusCodeException
            If creating the object in Weaviate failed for a different reason,
            more information is given in the exception.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        z)Expected class_name of type str but was: class
propertiesNidr&   /objectsr'   r(   pathweaviate_objectparamsz!Object was not added to Weaviate.   Fzalready existserrorr   messageTzCreating object)
isinstancestr	TypeErrortyper   r   r   r   r   valuer   postRequestsConnectionErrorstatus_codejsonKeyErrorr   r   )r   r#   r$   r%   r&   r'   r(   loaded_data_objectweaviate_objr1   r3   responseconn_errobject_does_already_exists                 r    createzDataObject.create3   sz   R *c*GZHXGYZ[[2;? .j9,
 !/!5L%/%7L"(*:;L*M*S*SF&'%+L"	]'',,$]c,dH 3&x}}t,--$)!	8==?7#;A#>y#II,0) %.s4y99+,=xHH ' 	])*MNT\\	]  		s*   D D/ 	D,D''D,/	D;:D;c                 &   i }|t        |      j                  |d<   | j                  ||||      \  }}	|||d<   	 | j                  j	                  |	||      }
|
j                  dk(  ryt        d|
      # t
        $ r}t        d      |d}~ww xY w)a  
        Update an already existing object in Weaviate with the given data object.
        Overwrites only the specified fields, the unspecified ones remain unchanged.

        Parameters
        ----------
        data_object : dict or str
            The object states the fields that should be updated.
            Fields not specified in the 'data_object' remain unchanged.
            Fields that are None will not be changed.
            If type is str it should be either an URL or a file.
        class_name : str
            The class name of the object.
        uuid : str or uuid.UUID
            The ID of the object that should be changed.
        vector: Sequence or None, optional
            Embedding for the object.
            Can be used when:
             - a class does not have a vectorization module.
             - The given vector was generated using the _identical_ vectorization module that is configured for the
             class. In this case this vector takes precedence.

            Supported types are `list`, 'numpy.ndarray`, `torch.Tensor` and `tf.Tensor`,
            by default None.
        consistency_level : Optional[ConsistencyLevel], optional
            Can be one of 'ALL', 'ONE', or 'QUORUM'. Determines how many replicas must acknowledge
        tenant: Optional[str], optional
            The name of the tenant for which this operation is being performed.

        Examples
        --------
        >>> author_id = client.data_object.create(
        ...     data_object = {'name': 'Philip Pullman', 'age': 64},
        ...     class_name = 'Author'
        ... )
        >>> client.data_object.get(author_id)
        {
            "additional": {},
            "class": "Author",
            "creationTimeUnix": 1617111215172,
            "id": "bec2bca7-264f-452a-a5bb-427eb4add068",
            "lastUpdateTimeUnix": 1617111215172,
            "properties": {
                "age": 64,
                "name": "Philip Pullman"
            },
            "vectorWeights": null
        }
        >>> client.data_object.update(
        ...     data_object = {'age': 74},
        ...     class_name = 'Author',
        ...     uuid = author_id
        ... )
        >>> client.data_object.get(author_id)
        {
            "additional": {},
            "class": "Author",
            "creationTimeUnix": 1617111215172,
            "id": "bec2bca7-264f-452a-a5bb-427eb4add068",
            "lastUpdateTimeUnix": 1617111215172,
            "properties": {
                "age": 74,
                "name": "Philip Pullman"
            },
            "vectorWeights": null
        }

        Raises
        ------
        TypeError
            If argument is of wrong type.
        ValueError
            If argument contains an invalid value.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a none successful status.
        Nr'   r(   r0   zObject was not updated.   z#Update of the object not successful)r   r;   _create_object_for_updater   patchr=   r>   r   r   r#   r$   r%   r&   r'   r(   r3   rB   r1   rC   rD   s               r    updatezDataObject.update   s    n (*:;L*M*S*SF&'!;;KUY[abd%+L"	S''-- , . H 3&+,QS[\\ ' 	S)*CD(R	S   A6 6	B?BBc                 &   i }|t        |      j                  |d<   | j                  ||||      \  }}	|||d<   	 | j                  j	                  |	||      }
|
j                  dk(  ryt        d|
      # t
        $ r}t        d      |d}~ww xY w)a
  
        Replace an already existing object with the given data object.
        This method replaces the whole object.

        Parameters
        ----------
        data_object : dict or str
            Describes the new values. It may be an URL or path to a json
            or a python dict describing the new values.
        class_name : str
            Name of the class of the object that should be updated.
        uuid : str or uuid.UUID
            The UUID of the object that should be changed.
        vector: Sequence or None, optional
            Embedding for the object.
            Can be used when:
             - a class does not have a vectorization module.
             - The given vector was generated using the _identical_ vectorization module that is configured for the
             class. In this case this vector takes precedence.

            Supported types are `list`, 'numpy.ndarray`, `torch.Tensor` and `tf.Tensor`,
            by default None.
        consistency_level : Optional[ConsistencyLevel], optional
            Can be one of 'ALL', 'ONE', or 'QUORUM'. Determines how many replicas must acknowledge
        tenant: Optional[str], optional
            The name of the tenant for which this operation is being performed.

        Examples
        --------
        >>> author_id = client.data_object.create(
        ...     data_object = {'name': 'H. Lovecraft', 'age': 46},
        ...     class_name = 'Author'
        ... )
        >>> client.data_object.get(author_id)
        {
            "additional": {},
            "class": "Author",
            "creationTimeUnix": 1617112817487,
            "id": "d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
            "lastUpdateTimeUnix": 1617112817487,
            "properties": {
                "age": 46,
                "name": "H. Lovecraft"
            },
            "vectorWeights": null
        }
        >>> client.data_object.replace(
        ...     data_object = {'name': 'H.P. Lovecraft'},
        ...     class_name = 'Author',
        ...     uuid = author_id
        ... )
        >>> client.data_object.get(author_id)
        {
            "additional": {},
            "class": "Author",
            "id": "d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
            "lastUpdateTimeUnix": 1617112838668,
            "properties": {
                "name": "H.P. Lovecraft"
            },
            "vectorWeights": null
        }

        Raises
        ------
        TypeError
            If argument is of wrong type.
        ValueError
            If argument contains an invalid value.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a none OK status.
        Nr'   r(   r0   zObject was not replaced.r4   zReplace object)r   r;   rI   r   putr=   r>   r   rK   s               r    replacezDataObject.replace  s    f (*:;L*M*S*SF&'!;;KUY[abd%+L"	T''++|\b+cH 3&+,<hGG ' 	T)*DE8S	TrM   c                    t        |t              st        d      t        |      }t	        |      }||t        |      d}|t        |      |d<   | j                  j                  dk\  }|rdt        |       d| }||fS d| }||fS )NzClass must be type str)r.   r-   r,   r&   1.14	/objects//)	r7   r8   r9   r   r   r   r   r   server_version)	r   r#   r$   r%   r&   object_dictrB   is_server_version_14r1   s	            r    rI   z$DataObject._create_object_for_updaten  s     *c*455d#+K8 %-j9
 %/%7L"#//>>&H7
CDAdVLD T!! tf%DT!!r"   additional_propertieswith_vector	node_namec           	      2    | j                  |||||||      S )a  
        Get an object as dict.

        Parameters
        ----------
        uuid : str or uuid.UUID
            The identifier of the object that should be retrieved.
        additional_properties : list of str, optional
            List of additional properties that should be included in the request,
            by default None
        with_vector: bool
            If True the `vector` property will be returned too,
            by default False.
        class_name : Optional[str], optional
            The class name of the object with UUID `uuid`. Introduced in Weaviate version v1.14.0.
            STRONGLY recommended to set it with Weaviate >= 1.14.0. It will be required in future
            versions of Weaviate Server and Clients. Use None value ONLY for Weaviate < v1.14.0,
            by default None
        tenant: str, optional
            The name of the tenant for which this operation is being performed.

        Examples
        --------
        >>> client.data_object.get_by_id(
        ...     uuid="d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
        ...     class_name='Author', # ONLY with Weaviate >= 1.14.0
        ... )
        {
            "additional": {},
            "class": "Author",
            "creationTimeUnix": 1617112817487,
            "id": "d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
            "lastUpdateTimeUnix": 1617112817487,
            "properties": {
                "age": 46,
                "name": "H.P. Lovecraft"
            },
            "vectorWeights": null
        }

        Returns
        -------
        dict or None
            dict in case the object exists.
            None in case the object does not exist.

        Raises
        ------
        TypeError
            If argument is of wrong type.
        ValueError
            If argument contains an invalid value.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a none OK status.
        )r%   rX   rY   r$   rZ   r'   r(   )get)r   r%   rX   rY   r$   rZ   r'   r(   s           r    	get_by_idzDataObject.get_by_id  s0    H xx"7#!/  
 	
r"   limitafteroffsetsortc           	      P   | j                   j                  dk\  }|$|r"| t        j                  t        t
        d       |K|I|s t        j                  t        t
        d       t        |t              st        dt        |             t        ||      }|r$|r"|dt        |       }nd}t        |      |d<   nd}||d	t        |      z   z  }|t        |      j                  |d
<   |||d<   |||d<   |t!        |dt"        d       ||d<   |t        |      |d<   |	t!        |	dt"        d       |	|d<   |
d|
vrt%        d      d|
vrd|
d<   t        |
t&              st        dt        |
       d      t        |
d   t              r
|
d   g|
d<   nCt        |
d   t(              rt+        d |
d   D              st        dt        |
d          d      t-        |
d         dk(  rt%        d      t        |
d   t.              r|
d   gt-        |
d         z  |
d<   nCt        |
d   t(              rt+        d |
d   D              st        dt        |
d          d      t-        |
d         t-        |
d         k7  r*t%        dt-        |
d          dt-        |
d          d      t-        |
d         dk(  rt%        d       d!j1                  |
d         |d"<   |
d   D cg c]  }|rd#nd$
 }}d!j1                  |      |d%<   	 | j                   j3                  ||&      }|j6                  d(k(  r+t9        t&        t        t:        f   |j=                               S |j6                  d)k(  ryt?        d*|      c c}w # t4        $ r}t5        d'      |d}~ww xY w)+aP  
        Gets objects from Weaviate, the maximum number of objects returned is 100.
        If 'uuid' is None, all objects are returned. If 'uuid' is specified the result is the same
        as for `get_by_uuid` method.

        Parameters
        ----------
        uuid : str, uuid.UUID or None, optional
            The identifier of the object that should be retrieved.
        additional_properties : list of str, optional
            list of additional properties that should be included in the request,
            by default None
        with_vector : bool
            If True the `vector` property will be returned too,
            by default False
        class_name: Optional[str], optional
            The class name of the object with UUID `uuid`. Introduced in Weaviate version v1.14.0.
            STRONGLY recommended to set it with Weaviate >= 1.14.0. It will be required in future
            versions of Weaviate Server and Clients. Use None value ONLY for Weaviate < v1.14.0,
            by default None
        consistency_level : Optional[ConsistencyLevel], optional
            Can be one of 'ALL', 'ONE', or 'QUORUM'. Determines how many replicas must acknowledge
            a request before it is considered successful. Mutually exclusive with node_name param.
        node_name : Optional[str], optional
            The name of the target node which should fulfill the request. Mutually exclusive with
            consistency_level param.
        limit: Optional[int], optional
            The maximum number of data objects to return.
            by default None, which uses the Weaviate default of 100 entries
        after: Optional[UUID], optional
           Can be used to extract all elements by giving the last ID from the previous "page". Requires limit to be set
           but cannot be combined with any other filters or search. Part of the Cursor API.
        offset: Optional[int], optional
            The offset of objects returned, i.e. the starting index of the returned objects. Should be
            used in conjunction with the 'limit' parameter.
        sort: Optional[Dict]
            A dictionary for sorting objects.
            sort['properties']: str, List[str]
                By which properties the returned objects should be sorted. When more than one property is given, the objects are sorted in order of the list.
                The order of the sorting can be given by using 'sort['order_asc']'.
            sort['order_asc']: bool, List[bool]
                The order the properties given in 'sort['properties']' should be returned in. When a single boolean is used, all properties are sorted in the same order.
                If a list is used, it needs to have the same length as 'sort'. Each properties order is then decided individually.
                If 'sort['order_asc']' is True, the properties are sorted in ascending order. If it is False, they are sorted in descending order.
                if 'sort['order_asc']' is not given, all properties are sorted in ascending order.
        tenant: Optional[str], optional
            The name of the tenant for which this operation is being performed.

        Returns
        -------
        list of dicts
            A list of all objects. If no objects where found the list is empty.

        Raises
        ------
        TypeError
            If argument is of wrong type.
        ValueError
            If argument contains an invalid value.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a none OK status.
        rR   N   r6   category
stacklevel.'class_name' must be of type str. Given type: rS   r/   r,   rT   r'   r(   rZ   r^   F)include_zeror_   r`   Tr-   z<The sort clause is missing the required field: 'properties'.	order_ascz)'sort' must be of type dict. Given type: .c              3   <   K   | ]  }t        |t                y wN)r7   r8   .0xs     r    	<genexpr>z!DataObject.get.<locals>.<genexpr>f  s      E'(
1c"E   zC'sort['properties']' must be of type str or list[str]. Given type: r   z-'sort['properties']' cannot be an empty list.c              3   <   K   | ]  }t        |t                y wrl   )r7   boolrm   s     r    rp   z!DataObject.get.<locals>.<genexpr>q  s      D()
1d#Drq   zG'sort['order_asc']' must be of type boolean or list[bool]. Given type: z'sort['order_asc']' must be the same length as 'sort['properties']' or a boolean (not in a list). Current length is sort['properties']:z and sort['order_asc']:z,'sort['order_asc']' cannot be an empty list.,ra   ascdescorderr1   r3   zCould not get object/s.r4     zGet object/s) r   rU   warningswarnr   DeprecationWarningr   r7   r8   r9   r:   _get_paramsr   r   r   r;   r   int
ValueErrorr   listalllenrs   joinr\   r=   r>   r
   r   r?   r   )r   r%   rX   rY   r$   rZ   r'   r^   r_   r`   ra   r(   rW   r3   r1   ro   rw   rC   rD   s                      r    r\   zDataObject.get  sy   \  $//>>&H"64;KMM9+
 !d&6'=/ 
 j#."PQUV`QaPb cdd2K@."#;J#G"HI!"::"FwDC....D(*:;L*M*S*SF&'%F8 "+F;w%H#F7O,U3F7O#DI%F84' !_``$&$([!dD)"KDQUJ<WX YZZ$|,c2&*<&8%9\"\ 2D9 E,0,>E B  YZ^_cdp_qZrYsstu  4%&!+ !PQQ${+T2%)+%6$7#d<>P:Q$Q[![ 148 D-1+->D A  ]^bcghsct^u]vvwx  4%&#d;.?*@@  ^  _b  cg  ht  cu  _v  ^w  wN  OR  SW  Xc  Sd  Oe  Nf  fg  h  4$%* !OPP XXd<&89F6N59+5FGaUV+GEG!hhuoF7O	S''++ , H 3&S#X883&+NHEE H ' 	S)*CD(R	Ss   /NN 	N%N  N%c                 P   t        |      }| j                  j                  dk\  }|"|r t        j                  t
        t        d       |I|s t        j                  t        t        d       t        |t              st        dt        |             |r|rdt        |       d| }nd| }i }|dt        |      j                  i}|||d	<   	 | j                  j                  ||
      }|j"                  dk(  ryt%        d|      # t         $ r}	t!        d      |	d}	~	ww xY w)a[  
        Delete an existing object from Weaviate.

        Parameters
        ----------
        uuid : str or uuid.UUID
            The ID of the object that should be deleted.
        class_name : Optional[str], optional
            The class name of the object with UUID `uuid`. Introduced in Weaviate version v1.14.0.
            STRONGLY recommended to set it with Weaviate >= 1.14.0. It will be required in future
            versions of Weaviate Server and Clients. Use None value ONLY for Weaviate < v1.14.0,
            by default None
        consistency_level : Optional[ConsistencyLevel], optional
            Can be one of 'ALL', 'ONE', or 'QUORUM'. Determines how many replicas must acknowledge
        tenant: str, optional
            The name of the tenant for which this operation is being performed.

        Examples
        --------
        >>> client.data_object.get(
        ...     uuid="d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
        ...     class_name='Author', # ONLY with Weaviate >= 1.14.0
        ... )
        {
            "additional": {},
            "class": "Author",
            "creationTimeUnix": 1617112817487,
            "id": "d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
            "lastUpdateTimeUnix": 1617112817487,
            "properties": {
                "age": 46,
                "name": "H.P. Lovecraft"
            },
            "vectorWeights": null
        }
        >>> client.data_object.delete(
        ...     uuid="d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
        ...     class_name='Author', # ONLY with Weaviate >= 1.14.0
        ... )
        >>> client.data_object.get(
        ...     uuid="d842a0f4-ad8c-40eb-80b4-bfefc7b1b530",
        ...     class_name='Author', # ONLY with Weaviate >= 1.14.0
        ... )
        None

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a none OK status.
        TypeError
            If parameter has the wrong type.
        ValueError
            If uuid is not properly formed.
        rR   Nrc   rd   rg   rS   rT   r'   r(   rx   zObject could not be deleted.rH   zDelete object)r   r   rU   rz   r{   r   r|   r   r7   r8   r9   r:   r   r   r;   deleter=   r>   r   
r   r%   r$   r'   r(   rW   r1   r3   rC   rD   s
             r    r   zDataObject.delete  sQ   @ d##//>>&H"6MM9+
 !'=/ 
 j#."PQUV`QaPb cdd.7
CDAdVLDtf%D()+;<M+N+T+TUF%F8	X''.. / H 3&+OXFF ' 	X)*HIxW	Xs   D 	D%D  D%c                 ~   | j                   j                  dk\  }|"|r t        j                  t        t
        d       |I|s t        j                  t        t
        d       t        |t              st        dt        |             |r|rdt        |       dt        |       }ndt        |       }i }|dt        |      j                  i}|||d	<   	 | j                   j                  ||
      }|j"                  dk(  ry|j"                  dk(  ryt%        d|      # t         $ r}	t!        d      |	d}	~	ww xY w)a  
        Check if the object exist in Weaviate.

        Parameters
        ----------
        uuid : str or uuid.UUID
            The UUID of the object that may or may not exist within Weaviate.
        class_name : Optional[str], optional
            The class name of the object with UUID `uuid`. Introduced in Weaviate version 1.14.0.
            STRONGLY recommended to set it with Weaviate >= 1.14.0. It will be required in future
            versions of Weaviate Server and Clients. Use None value ONLY for Weaviate < 1.14.0,
            by default None
        consistency_level : Optional[ConsistencyLevel], optional
            Can be one of 'ALL', 'ONE', or 'QUORUM'. Determines how many replicas must acknowledge
        tenant: Optional[str], optional
            The name of the tenant for which this operation is being performed.

        Examples
        --------
        >>> client.data_object.exists(
        ...     uuid='e067f671-1202-42c6-848b-ff4d1eb804ab',
        ...     class_name='Author',  # ONLY with Weaviate >= 1.14.0
        ... )
        False
        >>> client.data_object.create(
        ...     data_object = {'name': 'Andrzej Sapkowski', 'age': 72},
        ...     class_name = 'Author',
        ...     uuid = 'e067f671-1202-42c6-848b-ff4d1eb804ab'
        ... )
        >>> client.data_object.exists(
        ...     uuid='e067f671-1202-42c6-848b-ff4d1eb804ab',
        ...     class_name='Author', # ONLY with Weaviate >= 1.14.0
        ... )
        True

        Returns
        -------
        bool
            True if object exists, False otherwise.

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a none OK status.
        TypeError
            If parameter has the wrong type.
        ValueError
            If uuid is not properly formed.
        rR   Nrc   rd   rg   rS   rT   r'   r(   rx   z Could not check if object exist.rH   Try   FzObject exists)r   rU   rz   r{   r   r|   r   r7   r8   r9   r:   r   r   r   r;   headr=   r>   r   r   s
             r    existszDataObject.exists  sf   v  $//>>&H"6MM9+
 !'=/ 
 j#."PQUV`QaPb cdd.7
CDAnUYFZE[\D~d345D()+;<M+N+T+TUF%F8	\'',, - H 3&3&+OXFF ' 	\)*LMS[[	\s   D" "	D<+D77D<c                    t        |      }t        |t              st        dt	        |             t        |      |d}|t        |      |d<   |t        |      |d<   d}	 | j                  j                  ||      }d	di}
|j                  d
k(  rd|
d<   |
S |j                  dk(  rd|
d<   |j                         d	   |
d	<   |
S t        d|      # t        $ r}	t        d      |	d}	~	ww xY w)a  
        Validate an object against Weaviate.

        Parameters
        ----------
        data_object : dict or str
            Object to be validated.
            If type is str it should be either an URL or a file.
        class_name : str
            Name of the class of the object that should be validated.
        uuid : str, uuid.UUID or None, optional
            The UUID of the object that should be validated against Weaviate.
            by default None.
        vector: Sequence or None, optional
            The embedding of the object that should be validated.
            Can be used when:
             - a class does not have a vectorization module.
             - The given vector was generated using the _identical_ vectorization module that is configured for the
             class. In this case this vector takes precedence.

            Supported types are `list`, 'numpy.ndarray`, `torch.Tensor` and `tf.Tensor`,
            by default None.

        Examples
        --------
        Assume we have a Author class only 'name' property, NO 'age'.

        >>> client1.data_object.validate(
        ...     data_object = {'name': 'H. Lovecraft'},
        ...     class_name = 'Author'
        ... )
        {'error': None, 'valid': True}
        >>> client1.data_object.validate(
        ...     data_object = {'name': 'H. Lovecraft', 'age': 46},
        ...     class_name = 'Author'
        ... )
        {
            "error": [
                {
                "message": "invalid object: no such prop with name 'age' found in class 'Author'
                    in the schema. Check your schema files for which properties in this class are
                    available"
                }
            ],
            "valid": false
        }

        Returns
        -------
        dict
            Validation result. E.g. {"valid": bool, "error": None or list}

        Raises
        ------
        TypeError
            If argument is of wrong type.
        ValueError
            If argument contains an invalid value.
        weaviate.UnexpectedStatusCodeException
            If validating the object against Weaviate failed with a different reason.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        z+Expected class_name of type `str` but was: r+   Nr.   r&   z/objects/validate)r1   r2   z*Object was not validated against Weaviate.r5   r4   Tvalidi  FzValidate object)r   r7   r8   r9   r:   r   r   r   r   r<   r=   r>   r?   r   )r   r#   r$   r%   r&   rA   rB   r1   rC   rD   results              r    validatezDataObject.validate^  s"   N 3;?*c*I$zJZI[\]] .j9,

 !/!5L%/%7L""	'',,$,UH  3&"F7OM3&#F7O&mmog6F7OM+,=xHH ' 	)<	s   $C 	C-C((C-)NNNN)NNNrl   )NFNNNN)NNFNNNNNNNN)NN)__name__
__module____qualname____doc__r   r!   r	   dictr8   uuid_libr   r   r   r   rF   rL   rP   r   r   r   rI   r   rs   r]   r~   r\   r   r   r    r"   r    r   r      s   5: 5" 15%)8< $lI49%lI lI C,-	lI
 "lI $$45lI lI 
lIf &*8< $i]49%i] i] C&'	i]
 "i] $$45i] i] 
i]` &*8< $`H49%`H `H C&'	`H
 "`H $$45`H `H 
`HN &*"49%" " C&'	"
 "" 
tCH~s"	#"D 6:!$(#'8< $L
C&'L
  (S	2L
 	L

 SML
 C=L
 $$45L
 L
 
$L
` 1559!$(#'8<# $ $MQ $rFC,-rF  (S	2rF 	rF
 SMrF C=rF $$45rF }rF ~rF rF tCsD$t*d3i'G!HHIJrF rF 
$sCx.	!rFn %)8< $hGC&'hG SMhG $$45	hG
 hG 
hGZ %)8< $cGC&'cG SMcG $$45	cG
 cG 
cGR 15%)gI49%gI gI C,-	gI
 "gI 
gIr"   r   rX   rY   r)   c                     i }| r;t        | t              st        dt        |              dj	                  |       |d<   |rd|v r|d   dz   |d<   |S d|d<   |S )a  
    Get underscore properties in the format accepted by Weaviate.

    Parameters
    ----------
    additional_properties : list of str or None
        A list of additional properties or None.
    with_vector: bool
        If True the `vector` property will be returned too.

    Returns
    -------
    dict
        A dictionary including Weaviate-accepted additional properties
        and/or `vector` property.

    Raises
    ------
    TypeError
        If 'additional_properties' is not of type list.
    z3Additional properties must be of type list but are rt   includez,vectorr&   )r7   r   r9   r:   r   )rX   rY   r3   s      r    r}   r}     s    . F/6 5679   HH%:;y &y 1I =F9 M !)F9Mr"   ))r   r%   r   rz   typingr   r   r   r   r   r   r	   r
   requests.exceptionsr   r=   weaviate.connectr   weaviate.data.referencesr   weaviate.data.replicationr   weaviate.error_msgsr   r   weaviate.exceptionsr   r   weaviate.typesr   weaviate.utilr   r   r   r   r   r   r8   rs   r   r}   r   r"   r    <module>r      sq      J J J J ' . 6 d   iI iIX%xS	': % %RV %r"   