
    i                     T    S SK rS SKrS rS rS rS rS rSS jrS r	S	 r
S
 rS rg)    Nc                 n   [         R                  " U 5      n U R                  U5      n[        R                  " USS9nS=pE U R                  U5      nUS:  a5  [         R                  " [         R                  " U5      XCR                  5        U R                  U5      nU R                  [         R                  R                  :w  a!  [        R                  " X R                  4SS9nO<U R                  nU R                  nX'-   S-
  U-  n	[        R                  " XU-  U4SS9nUS:  a5  [         R                  " [         R                  " U5      XVR                  5        Ub  U R                  X5        Ub  U R!                  X5        X64$ ! Ub  U R                  X5        Ub  U R!                  X5        f f = f)zpreturns the inverted lists content as a pair of (list_ids, list_codes).
The codes are reshaped to a proper size
int64dtypeNr   uint8   )faissdowncast_InvertedLists	list_sizenpzerosget_idsmemcpyswig_ptrnbytes	get_codes	code_sizeInvertedListsINVALID_CODE_SIZEn_per_block
block_sizerelease_idsrelease_codes)
invlistsllslist_idsidscodes
list_codesnpbbsls_rounds
             k/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/faiss/contrib/inspect_tools.pyget_invlistr%   
   s{    ++H5H			A	Bxx'*HC-q!6LL13H""1%!4!4!F!FF2'9'9":'JJ &&C$$B1,H83Y"<GLJ6LL
3U<M<MN?  (""1,	 ?  (""1, s   DF	 	+F4c                     [         R                  " [        U R                  5       Vs/ s H  nU R	                  U5      PM     snSS9$ s  snf )z0return the array of sizes of the inverted lists r   r   )r   arrayrangenlistr   )r   is     r$   get_invlist_sizesr+   )   sL    88x~~&&A 	1&   s   A	c           	      p    U R                   R                   H  n[        U S[        X5       35        M     g)z2list values all fields of an object known to SWIG z = N)	__class____swig_getmethods__printgetattr)objnames     r$   print_object_fieldsr3   1   s1     11c'#,-./ 2    c                     [         R                  " U R                  5      nUR                  U R                  U R
                  U R                  5      $ )z$return the PQ centroids as an array )r	   vector_to_array	centroidsreshapeMksubdsub)pqcens     r$   get_pq_centroidsr>   8   s5    



-C;;rttRWWbgg..r4   c                     [         R                  " U R                  5      n[         R                  " U R                  5      R	                  U R
                  U R                  5      nX!4$ )zfextract matrix + bias from the PCA object
works for any linear transform (OPQ, random rotation, etc.)
)r	   r6   bAr8   d_outd_in)pcar@   rA   s      r$   get_LinearTransform_matrixrE   >   sH     	cee$Acee$,,SYYAA4Kr4   c                 R   U R                   u  p#Ub  UR                   U4:X  d   e[        R                  " X2USL5      n[        R                  " U R	                  5       UR
                  5        Ub   [        R                  " XR                  5        SUl        UR                  5         U$ )z@make a linear transform from a matrix and a bias term (optional)NT)	shaper	   LinearTransformcopy_array_to_vectorravelrA   r@   
is_trainedset_is_orthonormal)rA   r@   rB   rC   lts        r$   make_LinearTransform_matrixrN   G   s    ''KE}ww5)###			tATM	:B	qwwy"$$/}""1dd+BMIr4   c                     [         R                  " U R                  5      R                  SU R                  5      n[         R                  " U R
                  5      n[        U R                  5       Vs/ s H  nXU   X#S-       PM     sn$ s  snf )z-return to codebooks of an additive quantizer r   )r	   r6   	codebooksr8   dcodebook_offsetsr(   r9   )aqrQ   cor*   s       r$    get_additive_quantizer_codebooksrV   U   s{    %%bll3;;BEI			r22	3B rttA 	Q%q5	"  s   2Bc                     [         R                  " U R                  5      R                  S5      nUR	                  U R
                  U R                  5      $ )z0copy and return the data matrix in an IndexFlat float32)r	   r6   r   viewr8   ntotalrR   )indexxbs     r$   get_flat_datar]   _   s:    			u{{	+	0	0	;B::ellEGG,,r4   c                     [         R                  " U R                  5      R                  U R                  U R
                  5      $ )z1get the codes from an indexFlatCodes as an array )r	   r6   r   r8   rZ   r   )
index_flats    r$   get_flat_codesr`   e   s7      !1!12::://1 1r4   c                     U R                  5       n[        R                  " UR                  UR                  4SS9n[
        R                  " [
        R                  " U5      UR                  UR                  5        U$ )zaget the neighbor list for the vectors stored in the NSG structure, as
a N-by-K matrix of indices int32r   )
get_final_graphr   r   NKr	   r   r   datar   )nsggraph	neighborss      r$   get_NSG_neighborsrj   k   s_     !E%''577+7;I	LLy!


 r4   )N)numpyr   r	   r%   r+   r3   r>   rE   rN   rV   r]   r`   rj    r4   r$   <module>rm      s?      >0/-1
r4   