
    rh              	       z    d dl mZ d dlZd dlZ ej                  e      Z	 ddej                  dee   deddfdZ	y)	    )ListNtrained_indexshard_fnamesivfdata_fnamereturnc                 d   t        | t        j                        rJ d       g }|D ]u  }t        j	                  d|z          t        j
                  |t        j                        }t        j                  |      }|j                  |j                         d|_
        w | }t        j                  |      }|j                  dk(  sJ d       t        j                  |j                  |j                  |      }t        j                         }	|D ]  }
|	j!                  |
        t        j	                  d|	j#                         z         |j%                  |	j'                         |	j#                         |      }|x|_        |_        |j)                  |d       |j*                  j-                          y)	zAdd the contents of the indexes stored in shard_fnames into the index
    trained_index. The on-disk data is stored in ivfdata_fnamez1IndexIVFPQR is not supported as an on disk index.zread Fr   zworks only on empty indexzmerge %d inverted lists TN)
isinstancefaissIndexIVFPQRLOGinfo
read_indexIO_FLAG_MMAPextract_index_ivfappendinvlistsown_invlistsntotalOnDiskInvertedListsnlist	code_sizeInvertedListsPtrVector	push_backsizemerge_from_multipledatareplace_invliststhisdisown)r   r   r   	shift_idsivfsfnameindex	index_ivfr   
ivf_vectorivfr   s               g/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/faiss/contrib/ondisk.pymerge_ondiskr(      s   
 u(( ;:; 
 D 
' 	5!  (:(:;++E2	I&&' "'	
' E''.I<<1999 ((,,mH
 --/J "S!" HH'*//*;;<))*//*;Z__=NPYZF '-,EL9#x.MM    )F)
typingr   r
   logging	getLogger__name__r   Indexstrr(    r)   r'   <module>r1      sV      g! X].;;..23i.HK.	.r)   