o
    ¾¿ix  ã                   @   s<   d dl Z d dlmZ d dlmZ dd„ Zdd„ Zdd	„ ZdS )
é    N)Úpairs_to_dict)ÚCallbacksOptionsc              	   K   sè   | du r| S |  tjj¡rAi }|  tjj¡r| d  d¡n| d |d< | d |d< t| d ƒ|d< t| ƒd	kr?t| d	 ƒ|d
< |S |  tjj¡rJ| S g }t	t| ƒƒD ]}z| 
t| | ƒ¡ W qR tyq   | 
t| | ƒ¡ Y qRw |S )a  
    Handle VEMB result since the command can returning different result
    structures depending on input options and on quantization type of the vector set.

    Parsing VEMB result into:
    - List[Union[bytes, Union[int, float]]]
    - Dict[str, Union[bytes, str, float]]
    Nr   zutf-8Úquantizationé   Úrawé   Úl2é   Úrange)Úgetr   ÚRAWÚvalueÚALLOW_DECODINGÚdecodeÚfloatÚlenÚRESP3r
   ÚappendÚintÚ
ValueError)ÚresponseÚoptionsÚresultÚi© r   úR/home/ubuntu/.local/lib/python3.10/site-packages/redis/commands/vectorset/utils.pyÚparse_vemb_result   s.   	ÿýþr   c                 K   sd   | du r| S |  tjj¡r0g }| D ]}i }t|ƒ ¡ D ]\}}t|ƒ}|||< q| |¡ q|S | S )zÑ
    Handle VLINKS result since the command can be returning different result
    structures depending on input options.
    Parsing VLINKS result into:
    - List[List[str]]
    - List[Dict[str, Number]]
    N)r   r   Ú
WITHSCORESr   r   Úitemsr   r   )r   r   r   Ú
level_itemÚlevel_data_dictÚkeyr   r   r   r   Úparse_vlinks_result.   s   
r"   c                 K   sR  | du r| S t | tjj¡ƒ}t | tjj¡ƒ}|r|r |sO|rOi }| tjj¡r,| }nt| ƒ}| ¡ D ]\}}|r?t	|ƒ}n	|rFt
 |¡nd}|||< q4|S |r§|r§t| ƒ}i }| tjj¡r„|  ¡ D ]\}	}
|
d durvt
 |
d ¡}nd}|
d |dœ||	< qd|S t|||ƒD ]\}	}}|dur™t
 |¡}nd}t	|ƒ|dœ||	< qŠ|S | S )a¹  
    Handle VSIM result since the command can be returning different result
    structures depending on input options.
    Parsing VSIM result into:
    - List[List[str]]
    - List[Dict[str, Number]] - when with_scores is used (without attributes)
    - List[Dict[str, Mapping[str, Any]]] - when with_attribs is used (without scores)
    - List[Dict[str, Union[Number, Mapping[str, Any]]]] - when with_scores and with_attribs are used

    Nr   r   )ÚscoreÚ
attributes)Úboolr   r   r   r   ÚWITHATTRIBSr   r   r   r   ÚjsonÚloadsÚiterÚzip)r   r   Ú
withscoresÚwithattribsÚresult_dictÚ	resp_dictr!   r   ÚitÚelemÚdataÚattribs_dictr#   Úattribsr   r   r   Úparse_vsim_resultJ   s@   

	ùr4   )r'   Úredis._parsers.helpersr   Ú!redis.commands.vectorset.commandsr   r   r"   r4   r   r   r   r   Ú<module>   s    '