Ë
    µŒj
  ã                   ó  — d Z ddlZddlmZmZmZmZ ddlZ ej                  e
«      Zeeee      eej                     ej                  f   Zdededej                  fd„Z	 	 ddededee   d	ee   deeeeef      ee   f   f
d
„Zy)zMath utils.é    N)ÚListÚOptionalÚTupleÚUnionÚXÚYÚreturnc                 ó,  — t        | «      dk(  st        |«      dk(  rt        j                  g «      S t        j                  | «      } t        j                  |«      }| j                  d   |j                  d   k7  r&t	        d| j                  › d|j                  › d�«      ‚	 ddl}t        j                  | t        j                  ¬«      } t        j                  |t        j                  ¬«      }dt        j                  |j                  | |d¬	«      «      z
  }|S # t        $ rî t        j                  d
«       t        j                  j                  | d¬«      }t        j                  j                  |d¬«      }t        j                  dd¬«      5  t        j                  | |j                  «      t        j                   ||«      z  }ddd«       n# 1 sw Y   nxY wdt        j"                  |«      t        j$                  |«      z  <   |cY S w xY w)z<Row-wise cosine similarity between two equal-width matrices.r   é   z;Number of columns in X and Y must be the same. X has shape z and Y has shape Ú.N)ÚdtypeÚcosine)ÚmetriczƒUnable to import simsimd, defaulting to NumPy implementation. If you want to use simsimd please install with `pip install simsimd`.©ÚaxisÚignore)ÚdivideÚinvalidg        )ÚlenÚnpÚarrayÚshapeÚ
ValueErrorÚsimsimdÚfloat32ÚcdistÚImportErrorÚloggerÚdebugÚlinalgÚnormÚerrstateÚdotÚTÚouterÚisnanÚisinf)r   r   ÚsimdÚZÚX_normÚY_normÚ
similaritys          úh/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/utils/math.pyÚcosine_similarityr.      s�  € ä
ˆ1ƒv�‚{”c˜!“f ’kÜ�x‰x˜‹|Ðä
�‰�‹€AÜ
�‰�‹€AØ‡w�wˆq�z�Q—W‘W˜Q‘ZÒÜØIÈ!Ï'É'Èð SØ Ÿw™w˜i qð*ó
ð 	
ðÛä�H‰H�QœbŸj™jÔ)ˆÜ�H‰H�QœbŸj™jÔ)ˆØ”—‘˜Ÿ™ A q°˜Ó:Ó;Ñ;ˆØˆøÜò Ü�‰ðHô	
ô —‘—‘ ¨�Ó*ˆÜ—‘—‘ ¨�Ó*ˆä�[‰[ °(Ö;ÜŸ™  1§3¡3›¬"¯(©(°6¸6Ó*BÑBˆJ÷ <×;Ñ;úàBEˆ
”2—8‘8˜JÓ'¬"¯(©(°:Ó*>Ñ>Ñ?ØÒðús,   Â"A9D ÄA7HÆ8GÇ	HÇG	Ç7HÈHÚtop_kÚscore_thresholdc                 ó  — t        | «      dk(  st        |«      dk(  rg g fS t        | |«      }|xs d}d|||k  <   t        |xs t        |«      t        j                  |«      «      }t        j
                  || d¬«      | d }|t        j                  |j                  «       |   «         ddd…   }t        j                  ||j                  «      }|j                  «       |   j                  «       }t        t        |Ž «      |fS )a¡  Row-wise cosine similarity with optional top-k and score threshold filtering.

    Args:
        X: Matrix.
        Y: Matrix, same width as X.
        top_k: Max number of results to return.
        score_threshold: Minimum cosine similarity of results.

    Returns:
        Tuple of two lists. First contains two-tuples of indices (X_idx, Y_idx),
            second contains corresponding cosine similarities.
    r   g      ð¿Nr   éÿÿÿÿ)r   r.   Úminr   Úcount_nonzeroÚargpartitionÚargsortÚravelÚunravel_indexr   ÚtolistÚlistÚzip)r   r   r/   r0   Úscore_arrayÚ
top_k_idxsÚret_idxsÚscoress           r-   Úcosine_similarity_top_kr@   .   s÷   € ô$ ˆ1ƒv�‚{”c˜!“f ’kØ�2ˆvˆÜ# A qÓ)€KØ%Ò-¨€OØ12€K�˜oÑ-Ñ.Ü�Ò)œ˜[Ó)¬2×+;Ñ+;¸KÓ+HÓI€EÜ—‘ ¨u¨f¸4Ô@À%ÀÀÐI€JØœBŸJ™J {×'8Ñ'8Ó':¸:Ñ'FÓGÑHÉÈ2ÈÑN€JÜ×Ñ 
¨K×,=Ñ,=Ó>€HØ×ÑÓ  Ñ,×3Ñ3Ó5€FÜ”�X�Ó Ð'Ð'ó    )é   N)Ú__doc__ÚloggingÚtypingr   r   r   r   Únumpyr   Ú	getLoggerÚ__name__r   ÚfloatÚndarrayÚMatrixr.   Úintr@   © rA   r-   Ú<module>rN      sÊ   ðÙ ã ß /Ó /ã à	ˆ×	Ñ	˜8Ó	$€à	ˆt�D˜‘KÑ  $ r§z¡zÑ"2°B·J±JÐ>Ñ	?€ð˜ð  Fð ¨r¯z©zó ðH Ø'+ñ	(Øð(àð(ð �C‰=ð(ð ˜e‘_ð	(ð
 ˆ4��c˜3�h‘Ñ  $ u¡+Ð-Ñ.ô(rA   