o
    Ci
                     @   sL   d dl Zd dlZdd Zdd Zdd Zdd	 Zd
d Zdd Zdd Z	dS )    Nc           
   
   C   s2  t | } | |}tj|dd}d }}zm| |}|dkr*t t |||j | 	|}| j
t jjkrAtj|| j
fdd}n| j}| j}|| d | }	tj|	|| |fdd}|dkrjt t |||j W |duru| || |dur| || ||fS |dur| || |dur| || w 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_round r"   s/var/www/html/fyndo/python/python_agents/rag_suite/venv/lib/python3.10/site-packages/faiss/contrib/inspect_tools.pyget_invlist
   s8   



r$   c                    s"   t j fddt jD ddS )z1 return the array of sizes of the inverted lists c                    s   g | ]}  |qS r"   )r	   .0ir   r"   r#   
<listcomp>+   s    z%get_invlist_sizes.<locals>.<listcomp>r   r   )r
   arrayrangenlistr(   r"   r(   r#   get_invlist_sizes)   s
   r-   c                 C   s*   | j jD ]}t| dt| |  qdS )z3 list values all fields of an object known to SWIG z = N)	__class____swig_getmethods__printgetattr)objnamer"   r"   r#   print_object_fields1   s   r4   c                 C   s    t | j}|| j| j| jS )z% return the PQ centroids as an array )r   vector_to_array	centroidsreshapeMksubdsub)pqcenr"   r"   r#   get_pq_centroids8   s   r=   c                 C   s,   t | j}t | j| j| j}||fS )zo extract matrix + bias from the PCA object
    works for any linear transform (OPQ, random rotation, etc.)
    )r   r5   bAr7   d_outd_in)pcar>   r?   r"   r"   r#   get_LinearTransform_matrix>   s   rC   c                    s<   t | jd| jt | j  fddt| jD S )z. return to codebooks of an additive quantizer c                    s$   g | ]} |  |d    qS )r   r"   r%   co	codebooksr"   r#   r)   K   s    z4get_additive_quantizer_codebooks.<locals>.<listcomp>)r   r5   rG   r7   dcodebook_offsetsr+   r8   )aqr"   rE   r#    get_additive_quantizer_codebooksG   s
   rK   c                 C   s"   t | jd}|| j| jS )z1 copy and return the data matrix in an IndexFlat float32)r   r5   r   viewr7   ntotalrH   )indexxbr"   r"   r#   get_flat_dataQ   s   rQ   )
numpyr
   r   r$   r-   r4   r=   rC   rK   rQ   r"   r"   r"   r#   <module>   s   	
