
    Oh                     &    S SK r S SKrS rS rS rg)    Nc           	      R   US:X  a  U S-  $ UR                  S5      (       a  U S-  [        XS[        S5      *  5      -   $ [        R                  " SU5      nU(       a  [        XR                  S5      5      $ [        R                  " SU5      nU(       a  [        XR                  S5      5      $ [        R                  " S	U5      nU(       a  [        XR                  S5      5      $ [        R                  " S
U5      nU(       a5  [        XR                  S5      5      [        XR                  S5      5      -   $ [        R                  " SU5      nU(       a;  [        UR                  S5      5      [        UR                  S5      5      -  S-   S-  $ [        R                  " SU5      nU(       a5  [        UR                  S5      5      [        UR                  S5      5      -   $ [        R                  " SU5      nU(       a  [        UR                  S5      5      $ US:X  d  US:X  a  U S-  S-   $ US:X  a  U $ US:X  a  U S-   S-  $ US:X  a  U S-  S-   S-  $ US:X  a  U S-  $ US:X  a  U S-  $ [        R                  " SU5      nU(       a3  [        [        UR                  S5      5      UR                  S5      5      $ [        R                  " SU5      nU(       a3  [        [        UR                  S5      5      UR                  S5      5      $ [        R                  " SU5      nU(       a  [        XR                  S5      5      $ [        R                  " SU5      nU(       a3  [        [        UR                  S5      5      UR                  S5      5      $ [        SU-   5      e)zVsize of one vector in an index in dimension d
constructed with factory string indexkeyFlat   z,RFlatNzIVF\d+(_HNSW32)?,(.*)$   zIVF\d+\(.*\)?,(.*)$   zIMI\d+x2,(.*)$z(.*),Refine\((.*)\)$zPQ(\d+)x(\d+)(fs|fsr)?$      zPQ(\d+)\+(\d+)$zPQ(\d+)$HNSW32zHNSW32,Flat   SQ8SQ4SQ6   SQfp16SQbf16zPCAR?(\d+),(.*)$zOPQ\d+_(\d+),(.*)$zOPQ\d+,(.*)$zRR(\d+),(.*)$zcannot parse )endswithget_code_sizelenrematchgroupintRuntimeError)dindexkeymos      S/var/www/html/shao/venv/lib/python3.13/site-packages/faiss/contrib/factory_tools.pyr   r   
   s    61u""1u}Q3x=.(ABBB	+X	6B	Q,,	*H	5B	Q,,	#X	.B	Q,,	*H	5B	Q,}Q/LLL	-x	8B	BHHQK 3rxx{#33a7A==	&	1B	BHHQK 3rxx{#334	+x	(B	288A;8x=81uv~5	U	A!|	U	A	a	X	1u	X	1u	%x	0B	S!-rxx{;;	((	3B	S!-rxx{;;	/8	,B	Q,,	"H	-B	S!-rxx{;;
1
22    c                 R    U R                   R                  R                  S5      S-  $ )Nr   r   )hnswcum_nneighbor_per_levelat)indexs    r   
get_hnsw_Mr$   M   s"    ::--003q88r   c           
         [         R                  " U 5      n [        U [         R                  5      (       a  g[        U [         R                  5      (       Ga  [         R                  " U R
                  5      n[        U[         R                  5      (       a  SU R                   3nO[        U[         R                  5      (       a1  SUR                  R                   SUR                  R                   3nOW[        U[         R                  5      (       a  SU R                   S[        U5       3nOSU R                   S[        U5       S3n[        U [         R                  5      (       a  US-   $ [        U [         R                  5      (       a  US	-   $ [        U [         R                   5      (       a3  US
U R                  R                   SU R                  R                   3-   $ [        U [         R"                  5      (       a4  US
U R                  R                   SU R                  R                   S3-   $  [+        5       e[        U [         R$                  5      (       GaP  U R&                  R)                  5       S:w  a
  [+        5       e[         R,                  " U R&                  R/                  S5      5      n[        U[         R0                  5      (       a  SUR                   SUR2                   3nO[        U[         R4                  5      (       a  SUR6                  R2                   3nOj[        U[         R8                  5      (       aA  UR:                  S:X  d   eSUR<                  (       a  SOS-   [?        UR2                  5      -   nO
[+        5       eU S[        U R@                  5       3$ [        U [         R                  5      (       a  S[        U 5       3$ [        U [         RB                  5      (       a.  [        U RD                  5       S[        U RF                  5       S3$ [        U [         RH                  5      (       a1  SU R                  R                   SU R                  R                   S3$ [        U [         RJ                  5      (       a0  SU R                  R                   SU R                  R                   3$ [        U [         RL                  5      (       a0  SU RN                  (       a  SOS-   U RP                  (       a  S-   $ S-   $ [        U [         RR                  5      (       a  [         RT                  RV                  S[         RT                  RX                  S[         RT                  RZ                  S[         RT                  R\                  S[         RT                  R^                  S0nS X@R`                  Rb                      3$ [+        5       e)!z=
attempts to get the factory string the index was built with
r   IVFIMIx_HNSW()z,Flatz,SQ8z,PQfsr   r   OPQ_ITQPCAR ,HNSWz,Refine(PQLSHrt846fp16bf16SQ)2faissdowncast_index
isinstance	IndexFlatIndexIVF	quantizernlistMultiIndexQuantizerpqMnbits	IndexHNSWr$   reverse_index_factoryIndexIVFFlatIndexIVFScalarQuantizer
IndexIVFPQIndexIVFPQFastScanIndexPreTransformchainsizeNotImplementedErrordowncast_VectorTransformr"   	OPQMatrixd_outITQTransformitq	PCAMatrixeigen_powerrandom_rotationstrr#   IndexRefine
base_indexrefine_indexIndexPQFastScanIndexPQIndexLSHrotate_datatrain_thresholdsIndexScalarQuantizerScalarQuantizerQT_8bitQT_4bitQT_6bitQT_fp16QT_bf16sqqtype)r#   rD   prefixvtsqtypess        r   rK   rK   Q   sg      'E%))	E5>>	*	*((9	i115;;-(F	5#<#<==9<<>>*!ILL,>,>+?@F	5??335;;-uZ	-B,CDF5;;-q)>y)I(J!LFeU//00G##eU::;;F?"eU--..c%((**Quxx~~.>???eU5566c%((**Quxx~~.>bAAA 7V 
Q 
E522	3	3;;"%''++EKKNN1,=>b%//**244&"((,FE..//266<<.)FEOO,,>>Q&&&R%7%7cR@3rxx=PF%''0=>??	E5??	+	+j'())	E5,,	-	-'(8(89:(CXY^YkYkClBmmnoo	E500	1	1EHHJJ<q 033	E5==	)	)EHHJJ<q 011	E5>>	*	*u00b9EDZDZScc`bcc	E555	6	6!!))3!!))3!!))3!!))6!!))6
 GHHNN+,--

r   )r?   r   r   r$   rK    r   r   <module>rr      s     	@3F9D r   