
    3fi                        U d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	 ddl
mZ e G d d             Z G d d	eej                        Zej                  Zeed
<   dZeed<   deddfdZe G d de             Ze G d de             Ze G d de             Ze G d de             Ze G d de             Ze G d de             Ze G d de             Zy)zIndex class to add vector indexes on the PGVectorStore.

Learn more about vector indexes at https://github.com/pgvector/pgvector?tab=readme-ov-file#indexing
    N)ABCabstractmethod)	dataclassfield)Optionalc                   ,    e Zd ZU eed<   eed<   eed<   y)StrategyMixinoperatorsearch_functionindex_functionN)__name__
__module____qualname__str__annotations__     [/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_postgres/v2/indexes.pyr	   r	      s    Mr   r	   c                       e Zd ZdZdZdZdZy)DistanceStrategyz&Enumerator of the Distance strategies.)z<->l2_distancevector_l2_ops)z<=>cosine_distancevector_cosine_ops)z<#>inner_productvector_ip_opsN)r   r   r   __doc__	EUCLIDEANCOSINE_DISTANCEINNER_PRODUCTr   r   r   r   r      s    05ICO;Mr   r   DEFAULT_DISTANCE_STRATEGYlangchainvectorindexDEFAULT_INDEX_NAME_SUFFIX
identifierreturnc                 N    t        j                  d|       t        d|  d      y )Nz^[a-zA-Z_][a-zA-Z0-9_]*$zInvalid identifier: zw. Identifiers must start with a letter or underscore, and subsequent characters can be letters, digits, or underscores.)rematch
ValueError)r$   s    r   validate_identifierr*   !   s:    	xx+Z8@":,  /f  g
 	
 Ar   c                       e Zd ZU dZdZee   ed<   dZeed<    e	d       Z
eed<   dZeee      ed	<   dZee   ed
<   edefd       ZdefdZddZy)	BaseIndexa  
    Abstract base class for defining vector indexes.

    Attributes:
        name (Optional[str]): A human-readable name for the index. Defaults to None.
        index_type (str): A string identifying the type of index. Defaults to "base".
        distance_strategy (DistanceStrategy): The strategy used to calculate distances
            between vectors in the index. Defaults to DistanceStrategy.COSINE_DISTANCE.
        partial_indexes (Optional[list[str]]): A list of names of partial indexes. Defaults to None.
        extension_name (Optional[str]): The name of the extension to be created for the index, if any. Defaults to None.
    Nnamebase
index_typec                  "    t         j                  S N)r   r   r   r   r   <lambda>zBaseIndex.<lambda>9   s     0 @ @ r   )default_factorydistance_strategypartial_indexesextension_namer%   c                     t        d      )8Set index query options for vector store initialization.z4index_options method must be implemented by subclassNotImplementedErrorselfs    r   index_optionszBaseIndex.index_options>   s     "B
 	
r   c                 .    | j                   j                  S r1   )r4   r   r;   s    r   get_index_functionzBaseIndex.get_index_functionE   s    %%444r   c                     | j                   rt        | j                          | j                  rt        | j                         yy)zCheck if initialization parameters are valid.

        Raises:
            ValueError: extension_name is a valid postgreSQL identifier
        N)r6   r*   r/   r;   s    r   __post_init__zBaseIndex.__post_init__H   s3      3 34??0 r   )r%   N)r   r   r   r   r-   r   r   r   r/   r   r4   r   r5   listr6   r   r=   r?   rA   r   r   r   r,   r,   (   s    
 D(3-J*/@+'  ,0OXd3i(/$(NHSM(
s 
 
5C 5
1r   r,   c                       e Zd ZU dZeed<   y)ExactNearestNeighborexactnearestneighborr/   N)r   r   r   r/   r   r   r   r   r   rD   rD   U   s    ,J,r   rD   c                   >    e Zd Zedee   fd       Zedefd       Zy)QueryOptionsr%   c                     t        d      )3Convert index attributes to list of configurations.z3to_parameter method must be implemented by subclassr9   r;   s    r   to_parameterzQueryOptions.to_parameter\   s     ""WXXr   c                     t        d      )#Convert index attributes to string.z0to_string method must be implemented by subclassr9   r;   s    r   	to_stringzQueryOptions.to_stringa   s     ""TUUr   N)r   r   r   r   rB   r   rJ   rM   r   r   r   rG   rG   Z   s@    Yd3i Y Y V3 V Vr   rG   c                   D    e Zd ZU dZeed<   dZeed<   dZeed<   defdZ	y	)
	HNSWIndexhnswr/      m@   ef_constructionr%   c                 <    d| j                    d| j                   dS )r8   z(m = z, ef_construction = ))rR   rT   r;   s    r   r=   zHNSWIndex.index_optionsm   s#    tvvh243G3G2HJJr   N)
r   r   r   r/   r   r   rR   intrT   r=   r   r   r   rO   rO   g   s-    JAsKOSKs Kr   rO   c                   :    e Zd ZU dZeed<   dee   fdZdefdZ	y)HNSWQueryOptions(   	ef_searchr%   c                 "    d| j                    gS )rI   hnsw.ef_search = )r[   r;   s    r   rJ   zHNSWQueryOptions.to_parameterv   s    #DNN#3455r   c                 T    t        j                  dt               d| j                   S )rL   2to_string is deprecated, use to_parameter instead.r]   )warningswarnDeprecationWarningr[   r;   s    r   rM   zHNSWQueryOptions.to_stringz   s(    @	
 #4>>"233r   N)
r   r   r   r[   rW   r   rB   r   rJ   rM   r   r   r   rY   rY   r   s(    Is6d3i 643 4r   rY   c                   6    e Zd ZU dZeed<   dZeed<   defdZy)IVFFlatIndexivfflatr/   d   listsr%   c                 "    d| j                    dS )r8   z	(lists = rV   )rg   r;   s    r   r=   zIVFFlatIndex.index_options   s    4::,a((r   N)	r   r   r   r/   r   r   rg   rW   r=   r   r   r   rd   rd      s"    JE3)s )r   rd   c                   :    e Zd ZU dZeed<   dee   fdZdefdZ	y)IVFFlatQueryOptions   probesr%   c                 "    d| j                    gS )rI   ivfflat.probes = )rl   r;   s    r   rJ   z IVFFlatQueryOptions.to_parameter   s    #DKK=122r   c                 T    t        j                  dt               d| j                   S )rL   r_   rn   )r`   ra   rb   rl   r;   s    r   rM   zIVFFlatQueryOptions.to_string   s'    @	
 #4;;-00r   N)
r   r   r   rl   rW   r   rB   r   rJ   rM   r   r   r   rj   rj      s'    FCO3d3i 313 1r   rj   )r   enumr'   r`   abcr   r   dataclassesr   r   typingr   r	   Enumr   r   r!   r   r#   r   r*   r,   rD   rG   rO   rY   rd   rj   r   r   r   <module>ru      s?  
  	  # (    <}dii < /?.N.N + N!7 3 7
C 
D 
 )1 )1 )1X -9 - - 	V3 	V 	V K	 K K 4| 4 4  )9 ) ) 1, 1 1r   