
    Ih0                         d dl Z d dlmZ d dl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mZmZmZ dZd	Zd
ZdZdZdZdZdZdZdZdZ G d de      Z G d de      Z  G d de      Z!y)    N)Enum)	AwaitableDictListOptionalUnion)NEVER_DECODE)get_protocol_version)	DataError)CommandsProtocol
EncodableTKeyTNumberVADDVSIMVREMVDIMVCARDVEMBVLINKSVINFOVSETATTRVGETATTRVRANDMEMBERc                       e Zd ZdZdZdZdZy)QuantizationOptionsz*Quantization options for the VADD command.NOQUANTBINQ8N)__name__
__module____qualname____doc__r   r   r        Z/var/www/html/planif/env/lib/python3.12/site-packages/redis/commands/vectorset/commands.pyr   r      s    4G
C	Br%   r   c                        e Zd ZdZdZdZdZdZy)CallbacksOptionsz2Options that can be set for the commands callbacksRAW
WITHSCORESALLOW_DECODINGRESP3N)r    r!   r"   r#   r)   r*   r+   r,   r$   r%   r&   r(   r(      s    <
CJ%NEr%   r(   c                      e Zd ZdZ	 	 	 	 	 	 d dedeee   ef   de	de
e   de
e   de
e   d	e
e   d
e
eee	f      de
e   deee   ef   fdZ	 	 	 	 	 	 	 d!dedeee   ee	f   de
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            e
eeee   eeef   f         f   fdZdedeee   ef   fdZdedeee   ef   fdZdede	deee   ef   fdZ	 d"dede	de
e   deee
eee   ee	ef   f         e
eee   ee	ef   f      f   fdZ	 d"dede	de
e   deee
eeeee	ef      eee	ef   ef   f            e
eeeee	ef      eee	ef   ef   f         f   fdZdedeee   ef   fdZ	 d#dede	d
e
eee	f      deee   ef   fdZdede	dee
ee      e
e   f   fdZ	 d#dede
e   deee
eee	   e	f         e
eee	   e	f      f   fdZy)$VectorSetCommandszRedis VectorSet commandsNkeyvectorelement
reduce_dimcasquantizationef
attributesnumlinksreturnc
                    |r|st        d      g }
|r|
j                  d|g       g }t        |t              r|j                  d|g       n-|j                  dt	        |      g       |j                  |       |
j                  |       |
j                  |       |r|
j                  d       |r|
j                  |j                         |r|
j                  d|g       |r;t        |t              rt        j                  |      }n|}|
j                  d|g       |	r|
j                  d|	g        | j                  t        |g|
 S )	a  
        Add vector ``vector`` for element ``element`` to a vector set ``key``.

        ``reduce_dim`` sets the dimensions to reduce the vector to.
                If not provided, the vector is not reduced.

        ``cas`` is a boolean flag that indicates whether to use CAS (check-and-set style)
                when adding the vector. If not provided, CAS is not used.

        ``quantization`` sets the quantization type to use.
                If not provided, int8 quantization is used.
                The options are:
                - NOQUANT: No quantization
                - BIN: Binary quantization
                - Q8: Signed 8-bit quantization

        ``ef`` sets the exploration factor to use.
                If not provided, the default exploration factor is used.

        ``attributes`` is a dictionary or json string that contains the attributes to set for the vector.
                If not provided, no attributes are set.

        ``numlinks`` sets the number of links to create for the vector.
                If not provided, the default number of links is used.

        For more information see https://redis.io/commands/vadd
        z(Both vector and element must be providedREDUCEFP32VALUESCASEFSETATTRM)r   extend
isinstancebyteslenappendvaluedictjsondumpsexecute_commandVADD_CMD)selfr/   r0   r1   r2   r3   r4   r5   r6   r7   piecesvalues_piecesattributes_jsons                r&   vaddzVectorSetCommands.vadd+   s#   N WFGGMM8Z01fe$  &&!12  (CK!89  (m$gMM% MM,,,-MM4*%*d+"&**Z"8",MM9o67MM3/*#t##Hc;F;;r%   inputwith_scorescountfilter	filter_eftruth	no_threadc
                    |st        d      g }
i }t        |t              r|
j                  d|g       nQt        |t              r.|
j                  dt        |      g       |
j                  |       n|
j                  d|g       |r.|
j                  d       d|t        j                  j                  <   |r|
j                  d|g       |r|
j                  d|g       |r|
j                  d	|g       |r|
j                  d
|g       |r|
j                  d       |	r|
j                  d        | j                  t        |g|
i |S )a  
        Compare a vector or element ``input``  with the other vectors in a vector set ``key``.

        ``with_scores`` sets if the results should be returned with the
                similarity scores of the elements in the result.

        ``count`` sets the number of results to return.

        ``ef`` sets the exploration factor.

        ``filter`` sets filter that should be applied for the search.

        ``filter_ef`` sets the max filtering effort.

        ``truth`` when enabled forces the command to perform linear scan.

        ``no_thread`` when enabled forces the command to execute the search
                on the data structure in the main thread.

        For more information see https://redis.io/commands/vsim
        z'input' should be providedr;   r<   ELEr*   TCOUNTr>   FILTERz	FILTER-EFTRUTHNOTHREAD)r   rB   rC   rA   listrD   rE   r(   r*   rF   rJ   VSIM_CMD)rL   r/   rQ   rR   rS   r5   rT   rU   rV   rW   rM   optionss               r&   vsimzVectorSetCommands.vsimy   s%   J 899eU#MM65/*t$MM8SZ01MM% MM5%.)MM,'9=G$//556MM7E*+MM4*%MM8V,-MM;	23MM'"MM*%#t##HcFFFgFFr%   c                 .    | j                  t        |      S )a  
        Get the dimension of a vector set.

        In the case of vectors that were populated using the `REDUCE`
        option, for random projection, the vector set will report the size of
        the projected (reduced) dimension.

        Raises `redis.exceptions.ResponseError` if the vector set doesn't exist.

        For more information see https://redis.io/commands/vdim
        )rJ   VDIM_CMDrL   r/   s     r&   vdimzVectorSetCommands.vdim   s     ##Hc22r%   c                 .    | j                  t        |      S )z
        Get the cardinality(the number of elements) of a vector set with key ``key``.

        Raises `redis.exceptions.ResponseError` if the vector set doesn't exist.

        For more information see https://redis.io/commands/vcard
        )rJ   	VCARD_CMDrd   s     r&   vcardzVectorSetCommands.vcard   s     ##Is33r%   c                 0    | j                  t        ||      S )zw
        Remove an element from a vector set.

        For more information see https://redis.io/commands/vrem
        )rJ   VREM_CMDrL   r/   r1   s      r&   vremzVectorSetCommands.vrem   s     ##Hc7;;r%   rawc                 \   i }g }|j                  ||g       t        | j                        dv rd|t        j                  j
                  <   |r|j                  d       d|t        <   t        | j                  d      r#| j                  j                  j                  d   s9t        | j                  d      r@| j                  j                  j                  d   rd|t        j                  j
                  <   d|t        j                  j
                  <    | j                  t        g|i |S )a'  
        Get the approximated vector of an element ``element`` from vector set ``key``.

        ``raw`` is a boolean flag that indicates whether to return the
                interal representation used by the vector.


        For more information see https://redis.io/commands/vembed
        )3   Tr)   connection_pooldecode_responsesnodes_manager)rA   r
   clientr(   r,   rF   rE   r	   hasattrrq   connection_kwargsrs   r+   r)   rJ   VEMB_CMD)rL   r/   r1   rm   r`   rM   s         r&   vembzVectorSetCommands.vemb   s     sGn%,848G$**001MM% $(GL!%67KK//AABTU_5KK--??@RS
 BF(77==>26G$((../#t##HAvAAAr%   c                     i }g }|j                  ||g       |r.|j                  d       d|t        j                  j                  <    | j
                  t        g|i |S )a  
        Returns the neighbors for each level the element ``element`` exists in the vector set ``key``.

        The result is a list of lists, where each list contains the neighbors for one level.
        If the element does not exist, or if the vector set does not exist, None is returned.

        If the ``WITHSCORES`` option is provided, the result is a list of dicts,
        where each dict contains the neighbors for one level, with the scores as values.

        For more information see https://redis.io/commands/vlinks
        r*   T)rA   rE   r(   r*   rF   rJ   
VLINKS_CMD)rL   r/   r1   rR   r`   rM   s         r&   vlinkszVectorSetCommands.vlinks  sa    * sGn%MM,'9=G$//556#t##JCC7CCr%   c                 .    | j                  t        |      S )zw
        Get information about a vector set.

        For more information see https://redis.io/commands/vinfo
        )rJ   	VINFO_CMDrd   s     r&   vinfozVectorSetCommands.vinfo-  s     ##Is33r%   c                     |d}n(t        |t              rt        j                  |      }n|}| j	                  t
        |||      S )z
        Associate or remove JSON attributes ``attributes`` of element ``element``
        for vector set ``key``.

        For more information see https://redis.io/commands/vsetattr
        z{})rB   rG   rH   rI   rJ   VSETATTR_CMD)rL   r/   r1   r6   rO   s        r&   vsetattrzVectorSetCommands.vsetattr5  sC     "O
D)"jj4O(O##L#wPPr%   c                 0    | j                  t        ||      S )a  
        Retrieve the JSON attributes of an element ``elemet`` for vector set ``key``.

        If the element does not exist, or if the vector set does not exist, None is
        returned.

        For more information see https://redis.io/commands/vgetattr
        )rJ   VGETATTR_CMDrk   s      r&   vgetattrzVectorSetCommands.vgetattrH  s     ##L#w??r%   c                 |    g }|j                  |       ||j                  |        | j                  t        g| S )a  
        Returns random elements from a vector set ``key``.

        ``count`` is the number of elements to return.
                If ``count`` is not provided, a single element is returned as a single string.
                If ``count`` is positive(smaller than the number of elements
                            in the vector set), the command returns a list with up to ``count``
                            distinct elements from the vector set
                If ``count`` is negative, the command returns a list with ``count`` random elements,
                            potentially with duplicates.
                If ``count`` is greater than the number of elements in the vector set,
                            only the entire set is returned as a list.

        If the vector set does not exist, ``None`` is returned.

        For more information see https://redis.io/commands/vrandmember
        )rE   rJ   VRANDMEMBER_CMD)rL   r/   rS   rM   s       r&   vrandmemberzVectorSetCommands.vrandmemberU  s?    , cMM% #t##O=f==r%   )NFNNNN)FNNNNFF)F)N)r    r!   r"   r#   r   r   r   floatrC   strr   intboolr   r   rG   r   rP   r   r   ra   re   rh   rl   rx   r{   r~   r   r   r   r$   r%   r&   r.   r.   (   s   " %)#6:#15"&L<L< d5k5()L< 	L<
 SML< d^L< 23L< VL< U49-.L< 3-L< 
y~s"	#L<d ',## $#' %$)IGIG T%[%,-IG d^	IG
 }IG VIG IG C=IG ~IG D>IG 
(4d:&6Z=O8P&P QRSTeD,d:v3E.FFGHI	K
IGV3 3y~s':!; 34 4%	#(;"< 4< <s <uYs^S5H/I < >C(B(B"%(B,4TN(B	(5j!14Z3H!HIJKtJ'c:o)>>?@	B
(BV FKDD"%D4<TND	U4c5j 12DsEz9JF9R4SSTU	

 	eDsEz!23T%U
:KV:S5TTUVW	Y
D>4 4%	$(="> 4 QUQQ"%Q3;E$)<L3MQ	y~s"	#Q&@@"%@	x	$((4.8	9@ 15>> (>	(5cC012HU49c>=R4SS
>r%   r.   )"rH   enumr   typingr   r   r   r   r   redis.clientr	   redis.commands.helpersr
   redis.exceptionsr   redis.typingr   r   r   r   rK   r_   rj   rc   rg   rw   rz   r}   r   r   r   r   r(   r.   r$   r%   r&   <module>r      s~      9 9 % 7 & C C	
	$ t G>( G>r%   