
    3fiW                    r   d dl mZ d dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
 d dlZd dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ d	d
lmZ d	dlmZ d	dlmZmZm Z m!Z!m"Z"m#Z# dddddddZ$h dZ%ddhZ&h dZ' e(e$      jS                  e&      jS                  e'      jS                  e%      Z* G d de      Z+y)    )annotationsN)AnyCallableIterableOptionalSequence)Document)
Embeddings)VectorStoreutils)
RowMappingtext)AsyncEngine   )PGEngine)HybridSearchConfig)DEFAULT_DISTANCE_STRATEGYDEFAULT_INDEX_NAME_SUFFIX	BaseIndexDistanceStrategyExactNearestNeighborQueryOptions=z!=<z<=>z>=)$eqz$nez$ltz$ltez$gtz$gte>   $in$nin$exists$between$like$ilike>   $or$and$notc                  N   e Zd ZdZ e       Zddddddedd	d
ddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d9dZedddddddedd	d
ddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:d       Z	e
d;d       Z	 	 d<	 	 	 	 	 	 	 	 	 	 	 d=dZ	 	 d<	 	 	 	 	 	 	 	 	 d>dZ	 d?	 	 	 	 	 	 	 d@dZ	 d?	 	 	 	 	 dAdZedddddddddedd	d
ddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBd       Zeddddddddedd	d
ddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dCd       Zddd	 	 	 	 	 	 	 	 	 dDdZ	 	 d<	 	 	 	 	 	 	 	 	 dEdZdFdZ	 	 d<	 	 	 	 	 	 	 	 	 dGdZ	 	 d<	 	 	 	 	 	 	 	 	 dHdZ	 	 d<	 	 	 	 	 	 	 	 	 dIdZ	 	 	 	 dJ	 	 	 	 	 	 	 	 	 	 	 	 	 dKdZ	 	 	 	 dJ	 	 	 	 	 	 	 	 	 	 	 	 	 dLd Z	 	 	 	 dJ	 	 	 	 	 	 	 	 	 	 	 	 	 dMd!Z	 dN	 	 	 dOd#Z	 d?d"d$	 	 	 	 	 	 	 dPd%Zd?dQd&Z	 d?	 	 	 dQd'Z	 d?	 	 	 dRd(ZdSd)Z 	 	 	 	 	 	 dTd*Z!dUd+Z"dSd,Z#	 	 d<	 	 	 	 	 	 	 	 	 d>d-Z$	 d?	 	 	 	 	 	 	 d@d.Z%	 d?	 	 	 	 	 dAd/Z&e	 	 	 	 	 	 	 	 dV	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dWd0       Z'e	 	 	 	 	 	 	 dX	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dYd1       Z(	 	 d<	 	 	 	 	 	 	 	 	 dEd2Z)	 	 d<	 	 	 	 	 	 	 	 	 dGd3Z*	 	 d<	 	 	 	 	 	 	 	 	 dHd4Z+	 	 d<	 	 	 	 	 	 	 	 	 dId5Z,	 	 	 	 dJ	 	 	 	 	 	 	 	 	 	 	 	 	 dKd6Z-	 	 	 	 dJ	 	 	 	 	 	 	 	 	 	 	 	 	 dLd7Z.	 	 	 	 dJ	 	 	 	 	 	 	 	 	 	 	 	 	 dMd8Z/y)ZAsyncPGVectorStorezPostgres Vector Store classpubliccontent	embeddingNlangchain_idlangchain_metadata      g      ?schema_namecontent_columnembedding_columnmetadata_columns	id_columnmetadata_json_columndistance_strategykfetch_klambda_multindex_query_optionshybrid_search_configc                  |t         j                  k7  rt        d      || _        || _        || _        || _        || _        || _        ||ng | _	        |	| _
        |
| _        || _        || _        || _        || _        || _        || _        y)a  AsyncPGVectorStore constructor.
        Args:
            key (object): Prevent direct constructor usage.
            engine (PGEngine): Connection pool engine for managing connections to postgres database.
            embedding_service (Embeddings): Text embedding model to use.
            table_name (str): Name of the existing table or the table to be created.
            schema_name (str, optional): Name of the database schema. Defaults to "public".
            content_column (str): Column that represent a Document's page_content. Defaults to "content".
            embedding_column (str): Column for embedding vectors. The embedding is generated from the document value. Defaults to "embedding".
            metadata_columns (list[str]): Column(s) that represent a document's metadata.
            id_column (str): Column that represents the Document's id. Defaults to "langchain_id".
            metadata_json_column (str): Column to store metadata as JSON. Defaults to "langchain_metadata".
            distance_strategy (DistanceStrategy): Distance strategy to use for vector similarity search. Defaults to COSINE_DISTANCE.
            k (int): Number of Documents to return from search. Defaults to 4.
            fetch_k (int): Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult (float): Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
            index_query_options (QueryOptions): Index query option.
            hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Defaults to None.


        Raises:
            Exception: If called directly by user.
        z<Only create class through 'create' or 'create_sync' methods!N)r'   _AsyncPGVectorStore__create_key	Exceptionengineembedding_service
table_namer0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   )selfkeyr?   r@   rA   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   s                    e/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_postgres/v2/async_vectorstore.py__init__zAsyncPGVectorStore.__init__?   s    V $111N  !2$&, 04D4P 0VX"$8!!2&#6 $8!    r0   r1   r2   r3   ignore_metadata_columnsr4   r5   r6   r7   r8   r9   r:   r;   c                 K   |g }|r|rt        d      d}|j                  j                         4 d{   }|j                  t	        |      ||d       d{   }|j                         }|j                         }ddd      d{    i }D ]  }|d   ||d   <    |	|vrt        d|	 d      ||vrt        d	| d      ||   }|d
k7  rd|vrt        d	| d| d      |r0|j                  r|j                  n|dz   }||vs||   dk7  rd|_        ||vrt        d| d      ||   dvrt        d| d      |
|vrdn|
}
|D ]  }||vst        d| d       |}|r0|D ]  }||=  ||	= ||= ||= |j                         D cg c]  }| }} | | j                  |j                  |||||||	|
|||||      S 7 7 o7 B# 1 d{  7  sw Y   SxY wc c}w w)a  Create an AsyncPGVectorStore instance.

        Args:
            engine (PGEngine): Connection pool engine for managing connections to postgres database.
            embedding_service (Embeddings): Text embedding model to use.
            table_name (str): Name of an existing table.
            schema_name (str, optional): Name of the database schema. Defaults to "public".
            content_column (str): Column that represent a Document's page_content. Defaults to "content".
            embedding_column (str): Column for embedding vectors. The embedding is generated from the document value. Defaults to "embedding".
            metadata_columns (list[str]): Column(s) that represent a document's metadata.
            ignore_metadata_columns (list[str]): Column(s) to ignore in pre-existing tables for a document's metadata. Can not be used with metadata_columns. Defaults to None.
            id_column (str): Column that represents the Document's id. Defaults to "langchain_id".
            metadata_json_column (str): Column to store metadata as JSON. Defaults to "langchain_metadata".
            distance_strategy (DistanceStrategy): Distance strategy to use for vector similarity search. Defaults to COSINE_DISTANCE.
            k (int): Number of Documents to return from search. Defaults to 4.
            fetch_k (int): Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult (float): Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
            index_query_options (QueryOptions): Index query option.
            hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Defaults to None.

        Returns:
            AsyncPGVectorStore
        Nz>Can not use both metadata_columns and ignore_metadata_columns.z|SELECT column_name, data_type FROM information_schema.columns WHERE table_name = :table_name AND table_schema = :schema_name)rA   r0   	data_typecolumn_namezId column, z, does not exist.zContent column, r   charz, is type, z(. It must be a type of character string._tsvtsvector zEmbedding column, )zUSER-DEFINEDvectorz, is not type Vector.zMetadata column, r/   )

ValueError_poolconnectexecuter   mappingsfetchall
tsv_columnkeysr=   )clsr?   r@   rA   r0   r1   r2   r3   rH   r4   r5   r6   r7   r8   r9   r:   r;   stmtconnresult
result_mapresultscolumnsfieldcontent_typetsv_column_namecolumnall_columnss                               rD   createzAsyncPGVectorStore.create   s    Z #! 7P  N<<'') 	, 	,T<<T
)+F F  *J ))+G	, 	,  	?E,1+,>GE-()	? G#{9+5FGHH(//??PQRR~.6!fL&@">"2+l^Kst    (22 %//#f, 
 g-1IZ1W24$/7*12B1CCTUVV#$,FF$%5$66KL 
 )7D=Q 	
 ' 	PFW$ #4VH<M!NOO	P
 "1 ('( I&N+,-+6+;+;+=>a>>LL#)--!5/# 3!5!
 	
s	,	, 	, 	, 	,n  ?si   4G,GG,"GG$GG,GC
G,9G,	G'/G,GG,G$GG$G,c                    | j                   S N)r@   rB   s    rD   
embeddingszAsyncPGVectorStore.embeddings  s    %%%rF   c                  K   |s+|D cg c]  }t        t        j                               ! }}n.|D cg c]#  }||nt        t        j                               % }}|s|D cg c]  }i  }}t        | j                  dd      }t        |      }	t        ||||      D ]j  \  }}
}}t        | j                        dkD  r%ddj                  d | j                  D              z   nd}| j                  r0| j                  j                  rd| j                  j                   dnd}d	| j                   d
| j                   d| j                   d| j                   d| j                    d| | }||
t        |D cg c]  }t#        |       c}      d}d}|s |	rd| j                  j%                  |
       }| j                  rV| j                  j                  r@| j                  j&                  rd| j                  j&                   dnd}|d| dz  }|
|d<   t)        j*                  |      }| j                  D ]  }||v r|d| z  }||   ||<   ||= |dz  }! || j,                  rd| j,                   dndz  }| j,                  r|dz  }t/        j0                  |      |d<   n|dz  }d| j                   d| j                   d| j                   d| j                    d| j                    d}| j                  rJ| j                  j                  r4|d| j                  j                   d| j                  j                   dz  }| j,                  r |d| j,                   d| j,                   dz  }| j                  D ]  }|d| d| dz  } |dz  }||z   |z   }| j2                  j5                         4 d{   }|j7                  t9        |      |       d{    |j;                          d{    ddd      d{    m |S c c}w c c}w c c}w c c}w 7 h7 G7 17 ## 1 d{  7  sw Y   xY ww)zAdd data along with embeddings to the table.

        Raises:
            :class:`InvalidTextRepresentationError <asyncpg.exceptions.InvalidTextRepresentationError>`: if the `ids` data type does not match that of the `id_column`.
        Nembed_query_inliner   , c              3  (   K   | ]
  }d | d   yw"N .0cols     rD   	<genexpr>z5AsyncPGVectorStore.aadd_embeddings.<locals>.<genexpr>   s      M1SE M   rO   z, "ro   zINSERT INTO ""."z"("z", ")r+   r)   r*   z+VALUES (:langchain_id, :content, :embeddingz!VALUES (:langchain_id, :content, '',z, to_tsvector(z :tsv_content)tsv_contentz, :z,null"))z	, :extra)extraz ON CONFLICT ("z") DO UPDATE SET "z" = EXCLUDED.";)struuiduuid4getattrr@   callableziplenr3   joinr;   rW   r0   rA   r4   r1   r2   floatrk   tsv_langcopydeepcopyr5   jsondumpsr?   rS   rT   r   commit)rB   textsri   	metadatasidskwargs_idinline_embed_funccan_inline_embedr)   r*   metadatametadata_col_nameshybrid_search_columninsert_stmt	dimensionvaluesvalues_stmtlangr|   metadata_columnupsert_stmtrc   queryr[   s                             rD   aadd_embeddingsz"AsyncPGVectorStore.aadd_embeddings  s     .343tzz|$4C4 JMM22S->>MCM%*++I+ $D$:$:<PRVW#$5603C
I0V D	$,BH t,,-1 tyy Mt7L7L MMM  ,,1J1J1U1U d//::;1= !
 *$*:*:);3t>OsSWSaSaRbbfgkgzgzf{{  AE  AV  AV  @W  WX  Ym  Xn  oA  nB  CK "" I!Ny%	"2!NOF
 HK!1 A$BXBXBkBklsBtAuv((T-F-F-Q-Q 0099 11::;2> 
 v^DD(/}%MM(+E#'#8#8 +"h.S(9#::K.6.GF?+o.7*K+ ,, 112"7K
 (({*"&**U"3ws"+DNN+;;MdNaNaMbbpqu  rE  rE  qF  FJ  KO  K`  K`  Ja  ao  pt  pE  pE  oF  FG  HK((T-F-F-Q-QT%>%>%I%I$J.Y]YrYrY}Y}X~~   A  A((T%>%>$?~dNgNgMhhijj// EVHN6(!DDE 3K+-;E{{**, $ $ll4;777kkm##$ $ $ED	$L 
c 5 N+* "Of$7#$ $ $ $s   Q$PQ(PQ$	P-DQ8P
H0Q:P#;Q>P+P%P+5P'6P+:QP)Q%P+'P+)Q+P>	1P42P>	9Qc                ,  K   t        | j                  dd      }t        |      rt        |      D cg c]  }g  }}n,| j                  j	                  t        |             d{   } | j
                  ||f||d| d{   }|S c c}w 7 *7 w)zEmbed texts and add to the table.

        Raises:
            :class:`InvalidTextRepresentationError <asyncpg.exceptions.InvalidTextRepresentationError>`: if the `ids` data type does not match that of the `id_column`.
        rk   Nr   r   )r   r@   r   listaembed_documentsr   )rB   r   r   r   r   r   r   ri   s           rD   
aadd_textszAsyncPGVectorStore.aadd_textsf  s      $D$:$:<PRVW%&9=e,EAR,EJ,E#55FFtE{SSJ(D((:
)2
?E
 
 
 -FS
s-   0B	B*B%B&BBBBc                  K   |D cg c]  }|j                    }}|D cg c]  }|j                   }}|s|D cg c]  }|j                   }} | j                  |f||d| d{   }|S c c}w c c}w c c}w 7 w)zEmbed documents and add to the table.

        Raises:
            :class:`InvalidTextRepresentationError <asyncpg.exceptions.InvalidTextRepresentationError>`: if the `ids` data type does not match that of the `id_column`.
        r   N)page_contentr   r   r   )rB   	documentsr   r   docr   r   s          rD   aadd_documentsz!AsyncPGVectorStore.aadd_documents~  s      .77c!!77-67cS\\7	7%./c366/C/#DOOERYCR6RR
 87/Rs0   BA0BA5BA:B)A?*Bc           	     $  K   |sydj                  d t        t        |            D              }t        |      D ci c]  \  }}d| | }}}d| j                   d| j
                   d| j                   d| d		}| j                  j                         4 d
{   }|j                  t        |      |       d
{    |j                          d
{    d
d
d
      d
{    yc c}}w 7 V7 57 7 # 1 d
{  7  sw Y   yxY ww)zDelete records from the table.

        Raises:
            :class:`InvalidTextRepresentationError <asyncpg.exceptions.InvalidTextRepresentationError>`: if the `ids` data type does not match that of the `id_column`.
        Frl   c              3  &   K   | ]	  }d |   ywz:id_Nrp   rr   is     rD   rt   z-AsyncPGVectorStore.adelete.<locals>.<genexpr>        E4s E   id_zDELETE FROM "rv   " WHERE z in (r{   NT)r   ranger   	enumerater0   rA   r4   r?   rS   rT   r   r   )	rB   r   r   placeholdersr   r   
param_dictr   r[   s	            rD   adeletezAsyncPGVectorStore.adelete  s     yy EU3s8_ EE1:3@2A3im@
@ 0 01T__4EXdnnM]]bcobppqr;;&&( 	  	 D,,tE{J777++-	  	   A	 7	  	  	  	  sw   <DC-ADC3D C;?C5 C;C7C;D'C9(D5C;7C;9D;DDD	D)r0   r   r   r1   r2   r3   rH   r4   r5   r6   r7   r8   r9   r:   r;   c                  K   | j                  ||||||	|
|||||||||       d{   } |j                  |f||d| d{    |S 7 $7 w)a  Create an AsyncPGVectorStore instance from texts.

        Args:
            texts (list[str]): Texts to add to the vector store.
            embedding (Embeddings): Text embedding model to use.
            engine (PGEngine): Connection pool engine for managing connections to postgres database.
            table_name (str): Name of an existing table.
            metadatas (Optional[list[dict]]): List of metadatas to add to table records.
            ids: (Optional[list[str]]): List of IDs to add to table records.
            content_column (str): Column that represent a Document's page_content. Defaults to "content".
            embedding_column (str): Column for embedding vectors. The embedding is generated from the document value. Defaults to "embedding".
            metadata_columns (list[str]): Column(s) that represent a document's metadata.
            ignore_metadata_columns (list[str]): Column(s) to ignore in pre-existing tables for a document's metadata. Can not be used with metadata_columns. Defaults to None.
            id_column (str): Column that represents the Document's id. Defaults to "langchain_id".
            metadata_json_column (str): Column to store metadata as JSON. Defaults to "langchain_metadata".
            distance_strategy (DistanceStrategy): Distance strategy to use for vector similarity search. Defaults to COSINE_DISTANCE.
            k (int): Number of Documents to return from search. Defaults to 4.
            fetch_k (int): Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult (float): Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
            index_query_options (QueryOptions): Index query option.

        Raises:
            :class:`InvalidTextRepresentationError <asyncpg.exceptions.InvalidTextRepresentationError>`: if the `ids` data type does not match that of the `id_column`.

        Returns:
            AsyncPGVectorStore
        rG   Nr   )re   r   )rY   r   r*   r?   rA   r0   r   r   r1   r2   r3   rH   r4   r5   r6   r7   r8   r9   r:   r;   r   vss                         rD   afrom_textszAsyncPGVectorStore.afrom_texts  s     h ::#)--$;!5/# 3!5!  
 
$ bmmEJYCJ6JJJ	'
$ 	Ks!   %AAAAAA)r0   r   r1   r2   r3   rH   r4   r5   r6   r7   r8   r9   r:   r;   c                 K   | j                  |||||||	|
||||||||       d{   }|D cg c]  }|j                   }}|D cg c]  }|j                   }} |j                  |f||d| d{    |S 7 Vc c}w c c}w 7 w)a  Create an AsyncPGVectorStore instance from documents.

        Args:
            documents (list[Document]): Documents to add to the vector store.
            embedding (Embeddings): Text embedding model to use.
            engine (PGEngine): Connection pool engine for managing connections to postgres database.
            table_name (str): Name of an existing table.
            metadatas (Optional[list[dict]]): List of metadatas to add to table records.
            ids: (Optional[list[str]]): List of IDs to add to table records.
            content_column (str): Column that represent a Document's page_content. Defaults to "content".
            embedding_column (str): Column for embedding vectors. The embedding is generated from the document value. Defaults to "embedding".
            metadata_columns (list[str]): Column(s) that represent a document's metadata.
            ignore_metadata_columns (list[str]): Column(s) to ignore in pre-existing tables for a document's metadata. Can not be used with metadata_columns. Defaults to None.
            id_column (str): Column that represents the Document's id. Defaults to "langchain_id".
            metadata_json_column (str): Column to store metadata as JSON. Defaults to "langchain_metadata".
            distance_strategy (DistanceStrategy): Distance strategy to use for vector similarity search. Defaults to COSINE_DISTANCE.
            k (int): Number of Documents to return from search. Defaults to 4.
            fetch_k (int): Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult (float): Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
            index_query_options (QueryOptions): Index query option.

        Raises:
            :class:`InvalidTextRepresentationError <asyncpg.exceptions.InvalidTextRepresentationError>`: if the `ids` data type does not match that of the `id_column`.

        Returns:
            AsyncPGVectorStore
        rG   Nr   )re   r   r   r   )rY   r   r*   r?   rA   r0   r   r1   r2   r3   rH   r4   r5   r6   r7   r8   r9   r:   r;   r   r   r   r   r   s                           rD   afrom_documentsz"AsyncPGVectorStore.afrom_documents  s     h ::#)--$;!5/# 3!5!  
 
$ .77c!!77-67cS\\7	7bmmEJYCJ6JJJ	+
$ 87Js8   %BA>BB B	BB7B
8B B)r7   filterc               	  K   |j                  d| j                        }||n| j                  }|}|r|j                  }| j                  j
                  }| j                  j                  }	| j                  | j                  | j                  g| j                  z   }
| j                  r|
j                  | j                         dj                  d |
D              }d}d}|r$t        |t              r| j!                  |      \  }}t#        | j$                  dd      }|s1t'        |      r&d|v r"| j$                  j)                  |d         }| }n|D cg c]  }t+        |       c} }d}|rd| nd	}d
| d|	 d| j                   d| d| j,                   d| j.                   d| d| j                   d| d| d}||d}|r|j1                  |       | j2                  r| j4                  j7                         4 d{   }| j2                  j9                         D ]*  }d| d}|j;                  t=        |             d{    , |j;                  t=        |      |       d{   }|j?                         }|jA                         }ddd      d{    nv| j4                  j7                         4 d{   }|j;                  t=        |      |       d{   }|j?                         }|jA                         }ddd      d{    |r|jB                  r|jB                  n|j                  dd	      }|rU|rR||jD                  d<   |jF                  rd|jF                   dnd	}d| d}||d<   |jH                  rd|jH                   d}nd| d| j                   d}|rd | d!nd	}d
| d"| d| d#| j,                   d| j.                   d$| d%| d| d&|jJ                   d} | j4                  j7                         4 d{   }|j;                  t=        |       |       d{   }|j?                         }|jA                         }!ddd      d{     |jL                  !fi |jD                  d'| j                  i}"|"S S c c}w 7 7 _7 =7 # 1 d{  7  sw Y   xY w7 7 7 # 1 d{  7  sw Y   xY w7 7 7 ~# 1 d{  7  sw Y   xY ww)(a  
        Perform similarity search (or hybrid search) query on database.
        Queries might be slow if the hybrid search column does not exist.
        For best hybrid search performance, consider creating a TSV column
        and adding GIN index.
        r;   Nrl   c              3  (   K   | ]
  }d | d   ywrn   rp   rq   s     rD   rt   z8AsyncPGVectorStore.__query_collection.<locals>.<genexpr>\        ?1SE ?ru   rk   r   z:query_embeddingzWHERE rO   SELECT z("z", z) as distance
        FROM "rv   z" z ORDER BY " z LIMIT :dense_limit;
        )query_embeddingdense_limitz
SET LOCAL r}   	fts_queryfetch_top_krw   rx   zplainto_tsquery(z :fts_query)ro   to_tsvector( "rz   zAND (r{   z, ts_rank_cd(z) as distance FROM "r   z @@ z  ORDER BY distance desc LIMIT r6   )'getr;   r7   primary_top_kr6   operatorsearch_functionr4   r1   r2   r3   r5   appendr   
isinstancedict_create_filter_clauser   r@   r   rk   r   r0   rA   updater:   r?   rS   to_parameterrT   r   rU   rV   r   fusion_function_parametersr   rW   secondary_top_kfusion_function)#rB   r*   r7   r   r   r;   final_kr   r   r   r_   column_namessafe_filterfilter_dictr   r   embedding_data_stringr   where_filtersdense_query_stmtr   r[   query_optionquery_options_stmtr\   r]   dense_resultsr   r   	query_tsvcontent_tsvand_filterssparse_query_stmtsparse_resultscombined_resultss#                                      rD   __query_collectionz%AsyncPGVectorStore.__query_collection9  s      &zz"D$=$= 
 }!$&&.<<K))2200@@ NN!!
 !!	"
 $$NN4445yy ?w ??j.'+'A'A&'I$K#D$:$:<PRVWX&78W=N"44GGwXO'6&7!DM!Ny%	"2!N OO$6!2=&.2&|nB6Gr$J_J_I``cdycz { DOO#4B}o[QUQfQfPggijrisst  vK  uL L	 *9U
k*##{{**, 6 6$($<$<$I$I$K AL+5l^1)E&,,t,>'?@@@A  $||D1A,BJOO#__.
 * 3 3 56 6 6 {{**, 6 6#||D1A,BJOO#__.
 * 3 3 56 6 $(<(F(F !**K, 	
  IMT ;;MJ (00 (112"5 
 +4&=I&/J{##.. !"6"A"A!B!D ,TF"T5H5H4IL4?E+a0RK"),}[MQST]S^^rsw  tD  tD  sE  EH  IM  IX  IX  HY  Ya  bm  an  nr  s|  r}  }~  J  ~K  Kj  k  kO  kO  jP  PQ  !R{{**, 7 7#||D1B,CZPP#__.
!+!4!4!67 7
  D3CC  'AA  #'"8"8	  $#s "O6 AO6 6 6 66O6 6 6 647P7 7 7 7s#  ES;R$BS;>R?S;AR+R"$R+(R%)$R+S;R(#S;<S=S; S
S $S
S;SDS;S S;S&5S"6$S&S;%S$&:S;"R+%R+(S;+R>1R42R>9	S;S
S;
SSS	S;"S&$S;&S8,S/-S84S;c                T  K   t        | j                  dd      }t        |      rg n#| j                  j                  |       d{   }||d<   |j	                  d| j
                        }|r|j                  s||_        ||d<    | j                  d|||d| d{   S 7 ]7 w)z3Return docs selected by similarity search on query.rk   Nr   r   r;   r*   r7   r   rp   )r   r@   r   aembed_queryr   r;   r   asimilarity_search_by_vector)rB   r   r7   r   r   r   r*   r;   s           rD   asimilarity_searchz%AsyncPGVectorStore.asimilarity_search  s      $D$:$:<PRVW )* --:::FF 	
  w  &zz"D$=$= 
  (<(F(F-2 *-AF)*6T66 
1V
7=
 
 	
 G
s%   AB(B$AB(B& B(&B(c                    | j                   t        j                  k(  r| j                  S | j                   t        j                  k(  r| j
                  S | j                   t        j                  k(  r| j                  S y)z7Select a relevance function based on distance strategy.N)r6   r   COSINE_DISTANCE_cosine_relevance_score_fnINNER_PRODUCT%_max_inner_product_relevance_score_fn	EUCLIDEAN_euclidean_relevance_score_fnrh   s    rD   _select_relevance_score_fnz-AsyncPGVectorStore._select_relevance_score_fn  sm     !!%5%E%EE222!!%5%C%CC===##'7'A'AA555 BrF   c                X  K   t        | j                  dd      }t        |      rg n#| j                  j                  |       d{   }||d<   |j	                  d| j
                        }|r|j                  s||_        ||d<    | j                  d|||d| d{   }|S 7 _7 w)zGReturn docs and distance scores selected by similarity search on query.rk   Nr   r   r;   r   rp   )r   r@   r   r   r   r;   r   'asimilarity_search_with_score_by_vector)	rB   r   r7   r   r   r   r*   r;   docss	            rD   asimilarity_search_with_scorez0AsyncPGVectorStore.asimilarity_search_with_score  s      $D$:$:<PRVW )* --:::FF 	
  w  &zz"D$=$= 
  (<(F(F-2 *-AF)*ATAA 
1V
7=
 
  G
s%   AB*B&AB*B( B*(B*c                   K    | j                   d|||d| d{   }|D cg c]  \  }}|	 c}}S 7 c c}}w w)z1Return docs selected by vector similarity search.r   Nrp   )r   )rB   r*   r7   r   r   docs_and_scoresr   r   s           rD   r   z/AsyncPGVectorStore.asimilarity_search_by_vector  sU      !M L L !
1V!
7=!
 
 #22Q22	
 3s   >6	>8>>c                t  K    | j                   d|||d| d{   }g }|D ]  }| j                  r|| j                     r|| j                     ni }| j                  D ]
  }	||	   ||	<    |j                  t	        || j
                     |t        || j                                 |d   f        |S 7 w)zEReturn docs and distance scores selected by vector similarity search.r   Nr   r   r   distancerp   )%_AsyncPGVectorStore__query_collectionr5   r3   r   r	   r1   r~   r4   )
rB   r*   r7   r   r   r^   documents_with_scoresrowr   rs   s
             rD   r   z:AsyncPGVectorStore.asimilarity_search_with_score_by_vector  s      0// 
1V
7=
 
 !# 	C ,,T5N5N1O D--. 
 ,, ) #C)!((%()<)<%=!)s4>>23
 
O		& %$1
s   B8B6BB8c           	        K   | j                   j                  |       d{   } | j                  d|||||d| d{   S 7 $7 w):Return docs selected using the maximal marginal relevance.r   N)r*   r7   r8   r9   r   rp   )r@   r   (amax_marginal_relevance_search_by_vector)rB   r   r7   r8   r9   r   r   r*   s           rD   amax_marginal_relevance_searchz1AsyncPGVectorStore.amax_marginal_relevance_search  sh      00==5=II	BTBB 
#
 
 
 	
 J
s!    AAAA	A	Ac                ~   K    | j                   |f||||d| d{   }|D cg c]  }|d   	 c}S 7 c c}w w)r  )r7   r8   r9   r   Nr   )3amax_marginal_relevance_search_with_score_by_vector)	rB   r*   r7   r8   r9   r   r   r   r\   s	            rD   r  z;AsyncPGVectorStore.amax_marginal_relevance_search_by_vector,  sb      K$JJ'   	 )88fq	88 9s   =6=8==c                  K    | j                   d|||d| d{   }|r|n| j                  }|r|n| j                  }|r|n| j                  }|D cg c]$  }t	        j
                  || j                           & }	}t        j                  t        j                  |t        j                        |	||      }
g }|D ]  }| j                  r|| j                     r|| j                     ni }| j                  D ]
  }||   ||<    |j                  t        || j                      |t#        || j$                                 |d   f        t'        |      D cg c]  \  }}||
v s| c}}S 7 Vc c}w c c}}w w)zNReturn docs and distance scores selected using the maximal marginal relevance.r   N)dtype)r7   r9   r   r   rp   )r   r7   r8   r9   r   loadsr2   r   maximal_marginal_relevancenparrayfloat32r5   r3   r   r	   r1   r~   r4   r   )rB   r*   r7   r8   r9   r   r   r^   r  embedding_listmmr_selectedr   r   rs   r   rs                   rD   r  zFAsyncPGVectorStore.amax_marginal_relevance_search_with_score_by_vectorC  s     0// 
76
=C
 
 A$'$,,%0kd6F6FLSTS$**S)>)>%?@TT77HHYbjj1#	
 !# 	C ,,T5N5N1O D--. 
 ,, ) #C)!((%()<)<%=!)s4>>23
 
O		& ((=>Tda!|BSTTG
 U8 Us4   F E28F )E5>CF E:*E:.F 5F Fc                P  K   | j                   r,| j                   j                  r| j                   j                  st        d      | j                   j                  rd| j                   j                   dnd}| j                   j
                  r| j                   j
                  nd| d| j                   d}d|rd	nd d| j                   j                   d
| j                   d| j                   d| j                   j                   d| d}|rp| j                  j                         4 d{   }|j                  d       d{   }|j                  t        |             d{    ddd      d{    y| j                  j                         4 d{   }|j                  t        |             d{    |j                          d{    ddd      d{    y7 7 7 7 y# 1 d{  7  sw Y   yxY w7 l7 L7 67 (# 1 d{  7  sw Y   yxY ww)z:Creates a TSV index in the vector store table if possible.z)Hybrid Search Config cannot create index.rw   rx   rO   r   r   r{   CREATE INDEX CONCURRENTLYz ON "rv   " USING ();N
AUTOCOMMITisolation_level)r;   
index_type
index_namerQ   r   rW   r1   r0   rA   r?   rS   execution_optionsrT   r   r   )rB   concurrentlyr   rb   tsv_index_queryr[   autocommit_conns          rD   aapply_hybrid_search_indexz-AsyncPGVectorStore.aapply_hybrid_search_indexr  sz     )),,77,,77 HII ((11 ))22326 	 ((33 %%00vQt':':&;1= 	
 *L.b)QQRSWSlSlSwSwRxx}  C  O  O  ~P  PS  TX  Tc  Tc  Sd  dl  mq  mF  mF  mQ  mQ  lR  RS  Tc  Sd  df  g{{**, E E(,(>(>$0 )? ) # &--d?.CDDD	E E E {{**, $ $ll4#8999kkm##$ $ $E# E	E E E E$9#$ $ $ $s   D*H&,G,-H&0G4G.!G4(G0)G4-H&8G29#H&H	H& H>H?HHHH&&H'H&.G40G42H&4H:G=;HH&HHH&H#HH#H&)r  c               `  K   t        |t              r| j                          d{    y|j                  rz| j                  j                         4 d{   }|j                  t        d|j                                d{    |j                          d{    ddd      d{    |j                         }|j                  rd|j                   dnd}d|j                         z   }|0|j                  | j                  t        z   |_        |j                  }d|rdnd d	| d
| j                   d| j                   d|j                    d| j"                   d| d| d| d}|rp| j                  j                         4 d{   }|j%                  d       d{   }	|	j                  t        |             d{    ddd      d{    y| j                  j                         4 d{   }|j                  t        |             d{    |j                          d{    ddd      d{    y7 )7 7 7 7 # 1 d{  7  sw Y   xY w7 7 7 7 # 1 d{  7  sw Y   yxY w7 7 q7 [7 M# 1 d{  7  sw Y   yxY ww)z'Create index in the vector store table.NzCREATE EXTENSION IF NOT EXISTS zWHERE (r{   rO   zWITH r  r  r   z" ON "rv   r  z (r   z) r}   r  r  )r   r   adrop_vector_indexextension_namer?   rS   rT   r   r   get_index_functionpartial_indexesindex_optionsnamerA   r   r0   r  r2   r  )
rB   indexr(  r  r[   functionr   paramsrZ   r   s
             rD   aapply_vector_indexz&AsyncPGVectorStore.aapply_vector_index  s     e12))+++ {{**, $ $ll:5;O;O:PQR   kkm##	$ $
 ++-7<7L7L750013RT5..00<zz!!__/HH
::D~2FbfUYUeUeTffijnjyjyiz  {C  DI  DT  DT  CU  UW  X\  Xm  Xm  Wn  no  px  oy  y{  |B  {C  CD  EK  DL  LM  N{{**, : :(,(>(>$0 )? ) # &--d4j999	: : : {{**, $ $ll4:...kkm##$ $ $7 ,
$ $	$ $ $ $ :# :	: : : :$.#$ $ $ $sH  $J.I/J.IJ.+IIIII"J.-I.C!J.I4J.I<)I6*!I<I8I<J.I:#J.?J J.J!J"J9J:J>J.	J
J.J.IIJ.I1$I'%I1,	J.6I<8I<:J.<JJJ
J.JJJ.J+J" J+'J.c                Z  K   |xs | j                   t        z   }d| d}| j                  j                         4 d{   }|j	                  t        |             d{    |j                          d{    ddd      d{    y7 O7 /7 7 # 1 d{  7  sw Y   yxY ww)z Re-index the vector store table.zREINDEX INDEX "";NrA   r   r?   rS   rT   r   r   rB   r  r   r[   s       rD   areindexzAsyncPGVectorStore.areindex  s     N4??5N#N
!*R0;;&&( 	  	 D,,tE{+++++-	  	  	 +	  	  	  	 i   <B+BB+B B!B8B9B=B+B	B+BBB+B(BB($B+c                Z  K   |xs | j                   t        z   }d| d}| j                  j                         4 d{   }|j	                  t        |             d{    |j                          d{    ddd      d{    y7 O7 /7 7 # 1 d{  7  sw Y   yxY ww)zDrop the vector index.zDROP INDEX IF EXISTS "r.  Nr/  r0  s       rD   r#  z%AsyncPGVectorStore.adrop_vector_index  s     
  N4??5N#N
(B7;;&&( 	  	 D,,tE{+++++-	  	  	 +	  	  	  	 r2  c                  K   |xs | j                   t        z   }d}| j                   | j                  |d}| j                  j	                         4 d{   }|j                  t        |      |       d{   }|j                         }|j                         }ddd      d{    t        t              dk(        S 7 n7 M7 # 1 d{  7  sw Y   /xY ww)z#Check if index exists in the table.z
        SELECT tablename, indexname
        FROM pg_indexes
        WHERE tablename = :table_name AND schemaname = :schema_name AND indexname = :index_name;
        )rA   r0   r  Nr   )rA   r   r0   r?   rS   rT   r   rU   rV   boolr   )rB   r  r   r   r[   r\   r]   r^   s           rD   is_valid_indexz!AsyncPGVectorStore.is_valid_index  s     
  N4??5N#N
 //++$


 ;;&&( 	, 	,D<<UZ@@F*J ))+G	, 	, CLA%&&		,@	, 	, 	, 	,sZ   ACCCC	7C8$C	C'C(CC	C	CCCCc                  K   | j                   | j                  | j                  gz   }| j                  r|j	                  | j                         dj                  d |D              }dj                  d t        t        |            D              }t        |      D ci c]  \  }}d| | }}}d| d| j                   d| j                   d| j                   d	| d
}| j                  j                         4 d{   }	|	j                  t        |      |       d{   }
|
j                         }|j!                         }ddd      d{    g }D ]  }| j                  r|| j                     r|| j                     ni }| j                   D ]
  }||   ||<    |j	                  t#        || j                     |t%        || j                                         |S c c}}w 7 7 7 # 1 d{  7  sw Y   xY ww)zGet documents by ids.rl   c              3  (   K   | ]
  }d | d   ywrn   rp   rq   s     rD   rt   z1AsyncPGVectorStore.aget_by_ids.<locals>.<genexpr>  r   ru   c              3  &   K   | ]	  }d |   ywr   rp   r   s     rD   rt   z1AsyncPGVectorStore.aget_by_ids.<locals>.<genexpr>  r   r   r   r   z FROM "rv   z	" WHERE "z" IN (r  Nr   )r3   r4   r1   r5   r   r   r   r   r   r0   rA   r?   rS   rT   r   rU   rV   r	   r~   )rB   r   r_   r   r   r   r   r   r   r[   r\   r]   r^   r   r  r   rs   s                    rD   aget_by_idszAsyncPGVectorStore.aget_by_ids  s     ''NN+
 
 $$NN4445yy ?w ??yy EU3s8_ EE1:3@2A3im@
@,wt/?/?.@DOOCTT]^b^l^l]mms  uA  tB  BD  E;;&&( 	, 	,D<<UZ@@F*J ))+G	, 	,
 	 	C ,,T5N5N1O D--. 
 ,, ) #C)%()<)<%=!)s4>>23	$ 9 A	,@	, 	, 	, 	,sh   BH	G(/AH	 G.H	G4#G0$$G4H	G2BH	0G42H	4H:G=;HH	c          	     <   t        |t              st        dt        |       d|       |j	                  d      rt        d|       |j                         st        d| d      t        |t              r~t        |      dk7  r4t        dt        |       d	t        |j                               d
d        t        |j                               d   \  }}|t        vrt        d| dt               d}|}t        t        j                               j                  d      d   }|t        v rt        |   }| d| }| d| d| | |ifS |dk(  r'|\  }}	| d| }
| d| }d| d|
 d| d|
 || |	ifS |dv r|D ]a  }t        |t        t         t"        f      st%        dt        |       d|       t        |t&              sIt%        dt        |       d|        | d|j)                  dd       d| }|dk(  r| d | d| |ifS | d!| d| |ifS |d"v r;| d|j)                  dd       d| }|d#k(  rd| d$| d| |ifS d| d%| d| |ifS |d&k(  r0t        |t&              st        d'|       |rd| d(i fS d| d)i fS t%               )*a  Create a filter for a specific field.

        Args:
            field: name of field
            value: value to filter
                If provided as is then this will be an equality filter
                If provided as a dictionary then this will be a filter, the key
                will be the operator and the value will be the value to filter by

        Returns:
            sql where query as a string
        z"field should be a string but got: z with value: $z@Invalid filter condition. Expected a field but got an operator: zInvalid field name: z. Expected a valid identifier.r   zInvalid filter condition. Expected a value which is a dictionary with a single key that corresponds to an operator but got a dictionary with z keys. The first few keys are: N   r   zInvalid operator: z. Expected one of r   -r   r   z :r    _low__high_r  z
 BETWEEN :z AND :r{   >   r   r   zUnsupported type:  for value: rO   r   z = ANY(:z
 <> ALL (:>   r!   r"   r!   z LIKE :z ILIKE :r   z8Expected a boolean value for $exists operator, but got: z IS NOT NULL)z	 IS NULL))r   r~   rQ   type
startswithisidentifierr   r   r   rX   itemsSUPPORTED_OPERATORSr   r   splitCOMPARISONS_TO_NATIVEintr   NotImplementedErrorr5  replace)rB   r`   valuer   filter_value	suffix_idnative
param_namelowhighlow_param_namehigh_param_namevals                rD   _handle_field_filterz'AsyncPGVectorStore._handle_field_filter  s   $ %%4T%[MugV  C R'  !!#&ug-KL  eT"5zQ 114U =!!%ejjl!3BQ!7 8:  &*%++-%8%;"Hl22 (
 3'':&;= 
 H L

%++C03	,, +84F!7!I;/JWAfXR
|4*6UUU#$IC %weI;7N!&vi[9OugZ'7vo=NaP!"S"#dS   (# 	!#S%'89-,T#YK|C5I  c4(-,T#YK|C5I 	 "7!H$4$4S"$=#>a	{KJ5 A6J<,8WWW
:,a8!l\;   ,,!7!H$4$4S"$=#>a	{KJ7"5'A6J<,8WWW5'*Q7ZL<9XXX"lD1 **69 
  ug]3R77ugY/33%''rF   c                   t        |t              st        dt        |             t	        |      dk(  rGt        |j                               d   \  }}|j                  d      r |j                         dvr$t        d|       | j                  |||         S |j                         dk(  s|j                         d	k(  rt        |t
              st        d
t        |       d|       |dd j                         }|D cg c]  }| j                  |       }}t	        |      dkD  rJ|D cg c]  }|d   	 }}i }	|D ]  }|	j                  |d           dd| dj                  |       d|	fS t	        |      dk(  r|d   S t        d      |j                         dk(  rt        |t
              rv|D 
cg c]  }
| j                  |
       }}
|D cg c]  }|d   	 }}i }	|D ]  }|	j                  |d           |D cg c]  }d| 	 }}ddj                  |       d|	fS t        |t              r| j                  |      \  }}	d| d|	fS t        dt        |             t        d|       t	        |      dkD  r|j                         D ]!  }|j                  d      st        d|        |j                         D cg c]  \  }}| j                  ||       }}}t	        |      dkD  rF|D cg c]  }|d   	 }}i }	|D ]  }|	j                  |d           ddj                  |       d|	fS t	        |      dk(  r|d   S t        d      di fS c c}w c c}w c c}
w c c}w c c}w c c}}w c c}w )zCreate LangChain filter representation to matching SQL where clauses

        Args:
            filters: Dictionary of filters to apply to the query.

        Returns:
            String containing the sql where query.
        z2Invalid type: Expected a dictionary but got type: r   r   r<  )r$   r#   r%   z>Invalid filter condition. Expected $and, $or or $not but got: )r`   rL  r$   r#   zExpected a list, but got rA  Nr  r   r{   zKInvalid filter condition. Expected a dictionary but got an empty dictionaryr%   zNOT z AND z(NOT zCInvalid filter condition. Expected a dictionary or a list but got: z4Invalid filter condition. Expected a field but got: rO   )r   r   rQ   rB  r   r   rE  rC  lowerrV  upperr   r   r   rX   )rB   filtersrC   rL  opelfilter_clauseclauseall_clausesr+  itemnot_conditions	condition	not_stmtsnot_r7   vand_s                     rD   r   z(AsyncPGVectorStore._create_filter_clause  s    '4(DT']OT  w<1 gmmo.q1JC~~c"99;&==$$$'5*  00s'#,0OOyy{f$		u(<!%.$3DK=UGT  W]]_JO PB!;!;B!? P P}%);H"I6!9"IK"IF"/ 1fQi012$ay~~k:;1=vEE'1,(++$6  &eT*EJ&=A2248&N & <J"J6!9"JK"JF"0 1fQi01EP Q	4	{!3 QI Qw||I67q96AAt,#'#=#=e#DLD&"4&?F22$..25k]< 
 !  #u&  \A||~ >>#&$NseT  IP@D1)));D  4y1}7;<Vvay<<" -FMM&),-7<<45Q7??TaAw 2 
 r6M !Q"I& #K !R. =s*   M)0M.;M3M8M=NNc                    t        d      Nz]Sync methods are not implemented for AsyncPGVectorStore. Use PGVectorStore interface instead.rJ  )rB   r   s     rD   
get_by_idszAsyncPGVectorStore.get_by_ids  s    !k
 	
rF   c                    t        d      rh  ri  )rB   r   r   r   r   s        rD   	add_textszAsyncPGVectorStore.add_texts       "k
 	
rF   c                    t        d      rh  ri  )rB   r   r   r   s       rD   add_documentsz AsyncPGVectorStore.add_documents  s     "k
 	
rF   c                    t        d      rh  ri  )rB   r   r   s      rD   deletezAsyncPGVectorStore.delete  s    
 "k
 	
rF   c                    t        d      rh  ri  )rY   r   r*   r?   rA   r   r   r1   r2   r3   rH   r4   r5   r   s                 rD   
from_textszAsyncPGVectorStore.from_texts  s    " "k
 	
rF   c                    t        d      rh  ri  )rY   r   r*   r?   rA   r   r1   r2   r3   rH   r4   r5   r   s                rD   from_documentsz!AsyncPGVectorStore.from_documents  s      "k
 	
rF   c                    t        d      rh  ri  rB   r   r7   r   r   s        rD   similarity_searchz$AsyncPGVectorStore.similarity_search0  rm  rF   c                    t        d      rh  ri  rw  s        rD   similarity_search_with_scorez/AsyncPGVectorStore.similarity_search_with_score;  rm  rF   c                    t        d      rh  ri  rB   r*   r7   r   r   s        rD   similarity_search_by_vectorz.AsyncPGVectorStore.similarity_search_by_vectorF  rm  rF   c                    t        d      rh  ri  r|  s        rD   &similarity_search_with_score_by_vectorz9AsyncPGVectorStore.similarity_search_with_score_by_vectorQ  rm  rF   c                    t        d      rh  ri  )rB   r   r7   r8   r9   r   r   s          rD   max_marginal_relevance_searchz0AsyncPGVectorStore.max_marginal_relevance_search\       "k
 	
rF   c                    t        d      rh  ri  rB   r*   r7   r8   r9   r   r   s          rD   'max_marginal_relevance_search_by_vectorz:AsyncPGVectorStore.max_marginal_relevance_search_by_vectori  r  rF   c                    t        d      rh  ri  r  s          rD   2max_marginal_relevance_search_with_score_by_vectorzEAsyncPGVectorStore.max_marginal_relevance_search_with_score_by_vectorv  r  rF   ) rC   objectr?   r   r@   r
   rA   r~   r0   r~   r1   r~   r2   r~   r3   Optional[list[str]]r4   r~   r5   Optional[str]r6   r   r7   rI  r8   rI  r9   r   r:   Optional[QueryOptions]r;   Optional[HybridSearchConfig])$rY   type[AsyncPGVectorStore]r?   r   r@   r
   rA   r~   r0   r~   r1   r~   r2   r~   r3   r  rH   r  r4   r~   r5   r  r6   r   r7   rI  r8   rI  r9   r   r:   r  r;   r  returnr'   )r  r
   )NN)r   Iterable[str]ri   zlist[list[float]]r   Optional[list[dict]]r   Optional[list]r   r   r  	list[str])
r   r  r   r  r   r  r   r   r  r  rg   )r   list[Document]r   r  r   r   r  r  )r   r  r   r   r  zOptional[bool]),rY   r  r   r  r*   r
   r?   r   rA   r~   r0   r~   r   r  r   r  r1   r~   r2   r~   r3   r  rH   r  r4   r~   r5   r~   r6   r   r7   rI  r8   rI  r9   r   r:   r  r;   r  r   r   r  r'   )*rY   r  r   r  r*   r
   r?   r   rA   r~   r0   r~   r   r  r1   r~   r2   r~   r3   r  rH   r  r4   r~   r5   r~   r6   r   r7   rI  r8   rI  r9   r   r:   r  r;   r  r   r   r  r'   )
r*   list[float]r7   Optional[int]r   Optional[dict]r   r   r  zSequence[RowMapping])
r   r~   r7   r  r   r  r   r   r  r  )r  zCallable[[float], float])
r   r~   r7   r  r   r  r   r   r  list[tuple[Document, float]])
r*   r  r7   r  r   r  r   r   r  r  )
r*   r  r7   r  r   r  r   r   r  r  )NNNN)r   r~   r7   r  r8   r  r9   Optional[float]r   r  r   r   r  r  )r*   r  r7   r  r8   r  r9   r  r   r  r   r   r  r  )r*   r  r7   r  r8   r  r9   r  r   r  r   r   r  r  )F)r  r5  r  None)r)  r   r(  r  r  r5  r  r  )r  r  r  r  )r  r  r  r5  )r   zSequence[str]r  r  )r`   r~   rL  r   r  tuple[str, dict])rZ  r   r  r  )NNr)   r*   NNr+   r,   )rY   r  r   r  r*   r
   r?   r   rA   r~   r   r  r   r  r1   r~   r2   r~   r3   r  rH   r  r4   r~   r5   r~   r   r   r  r'   )Nr)   r*   NNr+   r,   )rY   r  r   r  r*   r
   r?   r   rA   r~   r   r  r1   r~   r2   r~   r3   r  rH   r  r4   r~   r5   r~   r   r   r  r'   )0__name__
__module____qualname____doc__r  r=   r   rE   classmethodre   propertyri   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r!  r,  r1  r#  r6  r:  rV  r   rj  rl  ro  rq  rs  ru  rx  rz  r}  r  r  r  r  rp   rF   rD   r'   r'   :   sC   %8L $' +04'.B.G 6:=A%>9>9 >9 &	>9
 >9 >9 >9 >9 .>9 >9 ,>9 ,>9 >9 >9  !>9" 4#>9$ ;%>9@  $' +047;'.B.G 6:=A%
%

 &
 	
 
 
 
 .
 "5
 
 ,
 ,
 
 
  !
" 4#
$ ;%
& 
'
 
B & & +/"__ &_ (	_
 _ _ 
_H +/"	 ( 	
  
6 #!  	
 
( #  
	*  $*."' +047;'$8.G 6:=A+F%FF F 	F
 F F (F F F F .F "5F F "F  ,!F" #F$ %F& 'F( 4)F* ;+F, -F. 
/F FP  $"' +047;'$8.G 6:=A)H%H!H H 	H
 H H H H H .H "5H H "H ,H  !H" #H$ %H& 4'H( ;)H* +H, 
-H H\  !%hh 	h
 h h 
hZ  !%	

 
 	

 
 

8	6  !%	  	
  
&@  !%	33 3 	3
 3 
3"  !%	 % %  % 	 %
  % 
& %J  !%'+!%

 
 	

 %
 
 
 

0  !%'+!%99 9 	9
 %9 9 9 
94  !%'+!%-U-U -U 	-U
 %-U -U -U 
&-Ub #!$!$ 
!$L #&$
 #&$&$ &$
 &$ 
&$P  %)	 !	  
	  %)'!' 
',)Vm( m( 	m(
 
m(^bH
 +/"		
	
 (	
 		

 	
 
	
 #
!
 
 	

 

 #

 
 
	
  +/"' +047;'$8
%

 
 	

 
 (
 
 
 
 .
 "5
 
 "
 
 

 
(  #' +047;'$8
%
!
 
 	

 
 
 
 
 .
 "5
 
 "
 
 

 
,  !%		
	
 	
 		

 	
 
	
  !%		
	
 	
 		

 	
 
&	
  !%		
	
 	
 		

 	
 
	
  !%		
	
 	
 		

 	
 
&	
  !%'+!%

 
 	

 %
 
 
 

   !%'+!%

 
 	

 %
 
 
 

   !%'+!%

 
 	

 %
 
 
 
&
rF   r'   ),
__future__r   r   r   r   typingr   r   r   r   r   numpyr  langchain_core.documentsr	   langchain_core.embeddingsr
   langchain_core.vectorstoresr   r   
sqlalchemyr   r   sqlalchemy.ext.asyncior   r?   r   r;   r   indexesr   r   r   r   r   r   rH  SPECIAL_CASED_OPERATORSTEXT_OPERATORSLOGICAL_OPERATORSsetunionrF  r'   rp   rF   rD   <module>r     s    "    > >  - 0 : ' .  4     
 ,  
U>
U
U"#	 G
 G
rF   