
    rh                     R    d dl Zd dlZd Zd Zd Zd Zd ZddZd Z	d	 Z
d
 Zd Zy)    Nc                 x   t        j                  |       } | j                  |      }t        j                  |d      }dx}}	 | j                  |      }|dkD  r4t        j                  t        j                  |      ||j                         | j                  |      }| j                  t         j                  j                  k7  r$t        j                  || j                  fd      }n@| j                  }| j                  }||z   dz
  |z  }	t        j                  |	||z  |fd      }|dkD  r4t        j                  t        j                  |      ||j                         || j                  ||       || j!                  ||       ||fS # || j                  ||       || j!                  ||       w w xY w)zy returns 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
             n/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/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2x'9'9":'JJ &&C$$BS1,H8R3Y"<GLJ6LL
3UJ<M<MN?  C(""1e,Z	 ?  C(""1e, s   DF +F9c                     t        j                  t        | j                        D cg c]  }| j	                  |       c}d      S c c}w )z1 return the array of sizes of the inverted lists r   r   )r   arrayrangenlistr   )r   is     r$   get_invlist_sizesr+   )   sG    88x~~& 	1   s   Ac           	      n    | j                   j                  D ]  }t        | dt        | |               y)z3 list values all fields of an object known to SWIG z = N)	__class____swig_getmethods__printgetattr)objnames     r$   print_object_fieldsr3   1   s8     11 0c'#t,-./0    c                     t        j                  | j                        }|j                  | j                  | j
                  | j                        S )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                     t        j                  | j                        }t        j                  | j                        j	                  | j
                  | j                        }||fS )zo extract 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   >   sJ     	cee$Acee$,,SYYAAa4Kr4   c                 L   | j                   \  }}||j                   |fk(  sJ t        j                  |||du      }t        j                  | j	                         |j
                         | t        j                  ||j                         d|_        |j                          |S )zA 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    ''KE4}ww5)###			tUATM	:B	qwwy"$$/}""1bdd+BMIr4   c                    t        j                  | j                        j                  d| j                        }t        j                  | j
                        }t        | j                        D cg c]  }|||   ||dz        c}S c c}w )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   sz    %%bll3;;BEI			r22	3B rtt 	"Q%1q5	"  s   0Bc                     t        j                  | j                        j                  d      }|j	                  | j
                  | j                        S )z1 copy 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                     t        j                  | j                        j                  | j                  | j
                        S )z2 get 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                     | j                         }t        j                  |j                  |j                  fd      }t        j                  t        j                  |      |j                  |j                         |S )zf get 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   