
    ht                       d Z 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mZmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ  ed
g      Zd
ZdZdZ ej>                   ej@                  d            jB                  Z" ejF                   ej@                  d            jB                  Z$ejJ                  jB                  Z&ddZ'ddZ(ddZ)ddZ*ddZ+ G d de      Z,y)z&Wrapper around TileDB vector database.    )annotationsN)AnyDictIterableListMappingOptionalTuple)Document)
Embeddingsguard_import)VectorStore)maximal_marginal_relevance	euclidean	documentsvectorsuint64float32c                 .    t        d      t        d      fS )z@Import tiledb-vector-search if available, otherwise raise error.tiledb.vector_searchtiledbr        e/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/vectorstores/tiledb.pydependable_tiledb_importr      s     	+,X r   c                (    | t            j                  S ) Get the URI of the vector index.)VECTOR_INDEX_NAMEurigroups    r   get_vector_index_uri_from_groupr#   #   s    "#'''r   c                (    | t            j                  S )zGet the URI of the documents array from group.

    Args:
        group: TileDB group object.

    Returns:
        URI of the documents array.
    )DOCUMENTS_ARRAY_NAMEr    r!   s    r   "get_documents_array_uri_from_groupr&   (   s     %&***r   c                    |  dt          S )r   /)r   r    s    r   get_vector_index_urir*   4   s    U!%&''r   c                    |  dt          S )z#Get the URI of the documents array.r(   )r%   r)   s    r   get_documents_array_urir,   9   s    U!()**r   c                  >   e Zd ZdZdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d%dZed&d       Zdded		 	 	 	 	 	 	 	 	 	 	 d'd
Zdddd	 	 	 	 	 	 	 	 	 	 	 d(dZ	dddd	 	 	 	 	 	 	 	 	 	 	 d)dZ
	 	 	 d*	 	 	 	 	 	 	 	 	 	 	 d+dZ	 	 	 d*	 	 	 	 	 	 	 	 	 	 	 d,dZddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d-dZ	 	 	 	 d.	 	 	 	 	 	 	 	 	 	 	 	 	 d/dZ	 	 	 	 d.	 	 	 	 	 	 	 	 	 	 	 	 	 d0dZeddd	 	 	 	 	 	 	 	 	 	 	 	 	 d1d       Zeddedddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2d       Z	 d3	 	 	 	 	 	 	 d4dZ	 	 	 d5	 	 	 	 	 	 	 	 	 	 	 d6dZeddeddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7d        Zeddedddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d8d!       Zeeddd"	 	 	 	 	 	 	 	 	 	 	 	 	 d9d#       Zd:d$Zy);TileDBa2  TileDB vector store.

    To use, you should have the ``tiledb-vector-search`` python package installed.

    Example:
        .. code-block:: python

            from langchain_community import TileDB
            embeddings = OpenAIEmbeddings()
            db = TileDB(embeddings, index_uri, metric)

     NF)vector_index_uridocs_array_uriconfig	timestampallow_dangerous_deserializationc                  |st        d      || _        |j                  | _        || _        || _        || _        t        d      t        d      }}
|j                  |      5  |j                  | j                  d      }|dk7  r|n
t        |      | _        |dk7  r|n
t        |      | _        |j                          |j                  | j                  d      }|j                  j!                  d      | _        |j                          || _        | j"                  dk(  rD |
j&                  j(                  d| j                  | j                  | j$                  d	|	| _        nR| j"                  d
k(  rC |
j,                  j.                  d| j                  | j                  | j$                  d	|	| _        ddd       y# 1 sw Y   yxY w)a  Initialize with necessary components.

        Args:
            allow_dangerous_deserialization: whether to allow deserialization
                of the data which involves loading data using pickle.
                data can be modified by malicious actors to deliver a
                malicious payload that results in execution of
                arbitrary code on your machine.
        a  TileDB relies on pickle for serialization and deserialization. This can be dangerous if the data is intercepted and/or modified by malicious actors prior to being de-serialized. If you are sure that the data is safe from modification, you can  set allow_dangerous_deserialization=True to proceed. Loading of compromised data using pickle can result in execution of arbitrary code on your machine.r   r   ctx_or_configrr/   
index_typeFLAT)r    r2   r3   IVF_FLATNr   )
ValueError	embeddingembed_queryembedding_function	index_urimetricr2   r   	scope_ctxGroupr#   r0   r&   r1   closemetagetr9   r3   
flat_index	FlatIndexvector_indexivf_flat_indexIVFFlatIndex)selfr=   r@   rA   r0   r1   r2   r3   r4   kwargs	tiledb_vsr   index_groupr"   s                 r   __init__zTileDB.__init__L   s   , /2  #"+"7"7" /0" 	 F3 	 ,,t~~s;K $r) !4[A ! "R' 7D 
 LL!6!6<E#jjnn\:DOKKM&DN&($BI$8$8$B$B %--;;"nn% 	%! J.$II$<$<$I$I %--;;"nn% 	%!3	 	 	s   #EF??Gc                    | j                   S N)r=   )rL   s    r   
embeddingszTileDB.embeddings   s    ~~r      )kfilterscore_thresholdc          
        t        d      }g }|j                  | j                  d| j                  | j                        }t        ||      D ]g  \  }	}
|	dk(  r|
dk(  r|	t        k(  r
|
t        k(  r%||	   }|t        |d         dk(  rt        d|	 d|       |j                  d	      }t        t        |d   d         
      |ht        j                  t        j                   |j#                               j%                  t        j&                        j)                               }|_        |o|j-                         D ci c]  \  }}|t/        |t0              s|gn| }}}t3        fd|j-                         D              s@|j5                  |
f       U|j5                  |
f       j |j7                          |D 
cg c]  \  }}
|
|k  s||
f }}}
|d| S c c}}w c c}
}w )a  Turns TileDB results into a list of documents and scores.

        Args:
            ids: List of indices of the documents in the index.
            scores: List of distances of the documents in the index.
            k: Number of Documents to return. Defaults to 4.
            filter (Optional[Dict[str, Any]]): Filter by metadata. Defaults to None.
            score_threshold: Optional, a floating point value to filter the
                resulting set of retrieved docs
        Returns:
            List of Documents and scores.
        r   r8   r3   r2   r   NtextzCould not find document for id z, got metadata)page_contentc              3  ^   K   | ]$  \  }}j                   j                  |      |v  & y wrR   )r[   rF   ).0keyvalue
result_docs      r   	<genexpr>z/TileDB.process_index_results.<locals>.<genexpr>   s3      "U ''++C0E9s   *-)r   openr1   r3   r2   zip
MAX_UINT64MAX_FLOAT_32lenr<   rF   r   strpickleloadsnparraytolistastypeuint8tobytesr[   items
isinstancelistallappendrD   )rL   idsscoresrU   rV   rW   r   docs
docs_arrayidxscoredocpickled_metadatar[   r_   r`   ra   s                   @r   process_index_resultszTileDB.process_index_results   s   * h'[[t{{ ! 

 c6* 	1JCaxEQJj Ul%:S/C{c#f+.!3 #B3%vcU!STT"wwz2!s3v;q>/BCJ+!<<HH-4467>>rxxHPPR '/
#! '-lln"U 
5$(?%UJ   &,lln  KKU 34Z/05	16 	/3Peu7OePPBQx Qs    G*G0G0   rU   rV   fetch_kc                  d|v r|j                  d      }nt        } | j                  j                  t	        j
                  t	        j
                  |      j                  t        j                        g      j                  t        j                        fd||n|i|\  }}| j                  |d   |d   |||      S )a[  Return docs most similar to query.

        Args:
            embedding: Embedding vector to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter (Optional[Dict[str, Any]]): Filter by metadata. Defaults to None.
            fetch_k: (Optional[int]) Number of Documents to fetch before filtering.
                      Defaults to 20.
            **kwargs: kwargs to be passed to similarity search. Can include:
                nprobe: Optional, number of partitions to check if using IVF_FLAT index
                score_threshold: Optional, a floating point value to filter the
                    resulting set of retrieved docs

        Returns:
            List of documents most similar to the query text and distance
            in float for each. Lower score represents more similarity.
        rW   rU   r   rv   rw   rV   rU   rW   )	pop	MAX_FLOATrI   queryrk   rl   rn   r   r~   )	rL   r=   rU   rV   r   rM   rW   dis	            r   &similarity_search_with_score_by_vectorz-TileDB.similarity_search_with_score_by_vector   s    4 &$jj):;O'O&t  &&HHbhhy)00<=>EEbjjQ
>aw
 
1
 ))!QqT&A * 
 	
r   c               V    | j                  |      } | j                  |f|||d|}|S )a  Return docs most similar to query.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.
            fetch_k: (Optional[int]) Number of Documents to fetch before filtering.
                      Defaults to 20.

        Returns:
            List of documents most similar to the query text with
            Distance as float. Lower score represents more similarity.
        r   )r?   r   )rL   r   rU   rV   r   rM   r=   rx   s           r   similarity_search_with_scorez#TileDB.similarity_search_with_score   sH    , ++E2	:t::
	

 
 r   c                f     | j                   |f|||d|}|D cg c]  \  }}|	 c}}S c c}}w )a  Return docs most similar to embedding vector.

        Args:
            embedding: Embedding to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.
            fetch_k: (Optional[int]) Number of Documents to fetch before filtering.
                      Defaults to 20.

        Returns:
            List of Documents most similar to the embedding.
        r   )r   )	rL   r=   rU   rV   r   rM   docs_and_scoresr|   _s	            r   similarity_search_by_vectorz"TileDB.similarity_search_by_vector  sL    ( F$EE
	

 
 #22Q222   -c                f     | j                   |f|||d|}|D cg c]  \  }}|	 c}}S c c}}w )a  Return docs most similar to query.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            filter: (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.
            fetch_k: (Optional[int]) Number of Documents to fetch before filtering.
                      Defaults to 20.

        Returns:
            List of Documents most similar to the query.
        r   )r   )	rL   r   rU   rV   r   rM   r   r|   r   s	            r   similarity_searchzTileDB.similarity_search7  sG    ( <$;;
vw
:@
 #22Q222r         ?rU   r   lambda_multrV   c                  d|v r|j                  d      }nt        } | j                  j                  t	        j
                  t	        j
                  |      j                  t        j                        g      j                  t        j                        fd||n|dz  i|\  }}	| j                  |	d   |d   |||n|dz  |      }
|
D cg c].  \  }}| j                  j                  |j                  g      d   0 }}}t        t	        j
                  |gt        j                        |||      }g }|D ]  }|j                  |
|           |S c c}}w )az  Return docs and their similarity scores selected using the maximal marginal
            relevance.

        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            embedding: Embedding to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            fetch_k: Number of Documents to fetch before filtering to
                     pass to MMR algorithm.
            lambda_mult: 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.
        Returns:
            List of Documents and similarity scores selected by maximal marginal
                relevance and score for each.
        rW   rU      r   r   dtype)rU   r   )r   r   rI   r   rk   rl   rn   r   r~   r=   embed_documentsr\   r   ru   )rL   r=   rU   r   r   rV   rM   rW   rw   indicesresultsr|   r   rS   mmr_selectedr   r   s                    r   2max_marginal_relevance_search_with_score_by_vectorz9TileDB.max_marginal_relevance_search_with_score_by_vectorP  sa   : &$jj):;O'O1$++11HHbhhy)00<=>EEbjjQ
gWq[
 

 ,,
!9gWq[+ - 
 QX
FLc1DNN**C,<,<+=>qA

 
 2HHi[

3#	
  	/A""71:.	/
s   3Ec                h     | j                   |f||||d|}|D 	cg c]  \  }}	|	 c}	}S c c}	}w )a  Return docs selected using the maximal marginal relevance.

        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            embedding: Embedding to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            fetch_k: Number of Documents to fetch before filtering to
                     pass to MMR algorithm.
            lambda_mult: 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.
        Returns:
            List of Documents selected by maximal marginal relevance.
        r   )r   )
rL   r=   rU   r   r   rV   rM   r   r|   r   s
             r   'max_marginal_relevance_search_by_vectorz.TileDB.max_marginal_relevance_search_by_vector  sO    4 R$QQ
#
 
 #22Q222s   .c                X    | j                  |      } | j                  |f||||d|}|S )a  Return docs selected using the maximal marginal relevance.

        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.
            fetch_k: Number of Documents to fetch before filtering (if needed) to
                     pass to MMR algorithm.
            lambda_mult: 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.
        Returns:
            List of Documents selected by maximal marginal relevance.
        r   )r?   r   )	rL   r   rU   r   r   rV   rM   r=   rx   s	            r   max_marginal_relevance_searchz$TileDB.max_marginal_relevance_search  sK    4 ++E2	;t;;
#
 
 r   T)	metadatasr2   c                  t        d      t        d      }}|j                  |      5  	 |j                  |       |j	                  |d      }
t        |
j                        }t        |
j                        }|dk(  r |j                  j                  ||||       n$|dk(  r|j                  j                  ||||       |
j                  |t               |j                  d	d
t        dz
  ft        j                   t        j"                              }|j%                  |      }|j'                  dt        j                   d      d      }|g}|r3|j'                  dt        j(                  d      }|j+                  |       |j-                  |dd|      }|j.                  j                  ||       |
j                  |t0               |
j3                          d d d        y # |j                  $ r}	|	d }	~	ww xY w# 1 sw Y   y xY w)Nr   r   r6   wr:   )r    
dimensionsvector_typer2   r;   )nameidr      )r   domainr   rZ   U1T)r   r   varr[   F)r   sparseallows_duplicatesattrs)r   rB   group_createTileDBErrorrC   r*   r    r,   rG   createrJ   addr   Dimre   rk   r   r   DomainAttrro   ru   ArraySchemaArrayr%   rD   )clsr@   r9   r   r   r   r2   rN   r   errr"   r0   docs_uridimdom	text_attrr   metadata_attrschemas                      r   r   zTileDB.create  s    /0" 	 F3 /	##I. LLC0E3EII>.uyy9HV#$$++() +!	 ,  z)((//() +!	 0  II&->I?
 **:>*hhryy)  C
 --$Crxx~4PIKE &288QU V]+''"'	 ( F LL&1IIh%9I:KKM_/	 /	 %% 	/	 /	s.   H G'F"H 'G=6G88G==H  H	r:   r   )r   rv   rA   r9   r2   index_timestampc               *   |t         vrt        d| dt        t                      t        d      t        d      }}t	        j
                  |      j                  t        j                        }| j                  |||j                  d   |j                  |d u|	       |j                  |	      5  |st        d      t        |      }t        |      }|3|D cg c](  }t        t        j                   d	t"        dz
              * }}t	        j
                  |      j                  t        j$                        } |j&                  j(                  d|||||
d	k7  r|
nd |	d
| |j+                  |d      5 }|Lt	        j,                  t/        |      t        j$                        }t1        t/        |            D ]  }|||<   	 i }t	        j
                  |      |d<   |st	        j2                  t/        |      gt4              }d	}|D ]B  }t	        j6                  t9        j:                  |      t        j<                        ||<   |dz  }D ||d<   |||<   d d d        d d d         | d||||	d|S c c}w # 1 sw Y   #xY w# 1 sw Y   'xY w)NzUnsupported distance metric: z. Expected one of r   r   r   )r@   r9   r   r   r   r2   r6   z3embeddings must be provided to build a TileDB indexr   )r9   r@   input_vectorsexternal_idsr   r2   r   r   rZ   r[   )r=   r@   rA   r2   r   )INDEX_METRICSr<   rs   r   rk   rl   rn   r   r   shaper   rB   r*   r,   rh   randomrandintre   r   	ingestioningestrc   zerosrg   rangeemptyobject
frombufferri   dumpsro   )r   textsrS   r=   r@   r   rv   rA   r9   r2   r   rM   rN   r   r   r0   r   r   r   Ar   datar   r[   s                           r   __fromzTileDB.__from  s     &3F8 <''+M':&;=  /0" 	 ,33BJJ?

!$**1-%++t+ 	 	
 F3 $	' !VWW3I>.y9H{GLM!s6>>!Z!^<=MM88C=//		:L&I&& %*+)3Ba3GT  Xs+ 'q'#%88CJbii#HL"3u:. ,*+Q,!xxV($&HHc)n-=V$LMA$- +-=="LL2"((,a( Q	
 (5D$"&,#''$	'J  
	

 
 	
= N' ''$	' $	's8   1*J	-I8A0J	8C#I=J	8J	=J	J		Jc                    t        j                  |      j                  t         j                        }| j                  j                  ||dk7  r|       yd       y)am  Delete by vector ID or other criteria.

        Args:
            ids: List of ids to delete.
            timestamp: Optional timestamp to delete with.
            **kwargs: Other keyword arguments that subclasses might use.

        Returns:
            Optional[bool]: True if deletion is successful,
            False otherwise, None if not implemented.
        r   N)r   r3   T)rk   rl   rn   r   rI   delete_batch)rL   rv   r3   rM   r   s        r   deletezTileDB.deletee  s_     xx}++BII6&&%i1n 	' 	
  SW 	' 	
 r   c           
        t        d      }| j                  j                  t        |            }|3|D cg c](  }t	        t        j                  dt        dz
              * }}t        j                  |      j                  t        j                        }	t        j                  t        |      d      }
t        t        |            D ]-  }t        j                  ||   t        j                        |
|<   / | j                   j#                  |
|	|dk7  r|nd       i }t        j                  |      |d<   |st        j                  t        |      gt$              }d}|D ]B  }t        j&                  t)        j*                  |      t        j,                        ||<   |dz  }D ||d	<   |j/                  | j0                  d
|dk7  r|nd| j2                        }|||	<   |j5                          |S c c}w )a  Run more texts through the embeddings and add to the vectorstore.

        Args:
            texts: Iterable of strings to add to the vectorstore.
            metadatas: Optional list of metadatas associated with the texts.
            ids: Optional ids of each text object.
            timestamp: Optional timestamp to write new texts with.
            kwargs: vectorstore specific parameters

        Returns:
            List of ids from adding the texts into the vectorstore.
        r   Nr   r   Or   )r   r   r3   rZ   r[   r   rY   )r   r=   r   rs   rh   r   r   re   rk   rl   rn   r   r   rg   r   r   rI   update_batchr   r   ri   r   ro   rc   r1   r2   rD   )rL   r   r   rv   r3   rM   r   rS   r   r   r   r   rx   r   r[   ry   s                   r   	add_textszTileDB.add_textsz  s   ( h'^^33DK@
;CHIa3v~~aa89ICIxx}++BII6((C
OC8s:' 	CA*Q-rzzBGAJ	C&&%#,>it 	' 	
 xxV HHc)n%5VDMA% #%==h1Grxx#Xa Q  -D[[#,>it;;	 ! 

 $(
< 
= Js   -G6z/tmp/tiledb_arrayc
                b    g }|j                  |      } | j                  d||||||||||	d
|
S )a  Construct a TileDB index from raw documents.

        Args:
            texts: List of documents to index.
            embedding: Embedding function to use.
            metadatas: List of metadata dictionaries to associate with documents.
            ids: Optional ids of each text object.
            metric: Metric to use for indexing. Defaults to "euclidean".
            index_uri: The URI to write the TileDB arrays
            index_type: Optional,  Vector index type ("FLAT", IVF_FLAT")
            config: Optional, TileDB config
            index_timestamp: Optional, timestamp to write new texts with.

        Example:
            .. code-block:: python

                from langchain_community import TileDB
                from langchain_community.embeddings import OpenAIEmbeddings
                embeddings = OpenAIEmbeddings()
                index = TileDB.from_texts(texts, embeddings)
        
r   rS   r=   r   rv   rA   r@   r9   r2   r   r   )r   _TileDB__from)r   r   r=   r   rv   rA   r@   r9   r2   r   rM   rS   s               r   
from_textszTileDB.from_texts  sZ    F 
..u5
szz 
!!+
 
 	
r   c                   |D cg c]  }|d   	 }}|D cg c]  }|d   	 }} | j                   d||||||||||	d
|
S c c}w c c}w )a  Construct TileDB index from embeddings.

        Args:
            text_embeddings: List of tuples of (text, embedding)
            embedding: Embedding function to use.
            index_uri: The URI to write the TileDB arrays
            metadatas: List of metadata dictionaries to associate with documents.
            metric: Optional, Metric to use for indexing. Defaults to "euclidean".
            index_type: Optional, Vector index type ("FLAT", IVF_FLAT")
            config: Optional, TileDB config
            index_timestamp: Optional, timestamp to write new texts with.

        Example:
            .. code-block:: python

                from langchain_community import TileDB
                from langchain_community.embeddings import OpenAIEmbeddings
                embeddings = OpenAIEmbeddings()
                text_embeddings = embeddings.embed_documents(texts)
                text_embedding_pairs = list(zip(texts, text_embeddings))
                db = TileDB.from_embeddings(text_embedding_pairs, embeddings)
        r   r   r   r   )r   )r   text_embeddingsr=   r@   r   rv   rA   r9   r2   r   rM   tr   rS   s                 r   from_embeddingszTileDB.from_embeddings  s{    J  //!1//$34qad4
4szz 
!!+
 
 	
 04s
   AA)rA   r2   r3   c          	          | d|||||d|S )a}  Load a TileDB index from a URI.

        Args:
            index_uri: The URI of the TileDB vector index.
            embedding: Embeddings to use when generating queries.
            metric: Optional, Metric to use for indexing. Defaults to "euclidean".
            config: Optional, TileDB config
            timestamp: Optional, timestamp to use for opening the arrays.
        )r=   r@   rA   r2   r3   r   r   )r   r@   r=   rA   r2   r3   rM   s          r   loadzTileDB.load  s/    (  

 
 	
r   c                F     | j                   j                  di || _         y )Nr   )rI   consolidate_updates)rL   rM   s     r   r   zTileDB.consolidate_updates7  s     AD--AAKFKr   )r=   r   r@   rh   rA   rh   r0   rh   r1   rh   r2   Optional[Mapping[str, Any]]r3   r   r4   boolrM   r   )returnzOptional[Embeddings])rv   z	List[int]rw   List[float]rU   intrV   Optional[Dict[str, Any]]rW   floatr   List[Tuple[Document, float]])r=   r   rU   r   rV   r   r   r   rM   r   r   r   )r   rh   rU   r   rV   r   r   r   rM   r   r   r   )rT   Nr   )r=   r   rU   r   rV   r   r   r   rM   r   r   List[Document])r   rh   rU   r   rV   r   r   r   rM   r   r   r   )r=   r   rU   r   r   r   r   r   rV   r   rM   r   r   r   )rT   r   r   N)r=   r   rU   r   r   r   r   r   rV   r   rM   r   r   r   )r   rh   rU   r   r   r   r   r   rV   r   rM   r   r   r   )r@   rh   r9   rh   r   r   r   znp.dtyper   r   r2   r   r   None)r   	List[str]rS   zList[List[float]]r=   r   r@   rh   r   Optional[List[dict]]rv   Optional[List[str]]rA   rh   r9   rh   r2   r   r   r   rM   r   r   r.   )Nr   )rv   r   r3   r   rM   r   r   zOptional[bool])NNr   )r   zIterable[str]r   r   rv   r   r3   r   rM   r   r   r   )r   r   r=   r   r   r   rv   r   rA   rh   r@   rh   r9   rh   r2   r   r   r   rM   r   r   r.   )r   zList[Tuple[str, List[float]]]r=   r   r@   rh   r   r   rv   r   rA   rh   r9   rh   r2   r   r   r   rM   r   r   r.   )r@   rh   r=   r   rA   rh   r2   r   r3   r   rM   r   r   r.   )rM   r   r   r   )__name__
__module____qualname____doc__rP   propertyrS   r   r~   r   r   r   r   r   r   r   classmethodr   DEFAULT_METRICr   r   r   r   r   r   r   r   r   r   r.   r.   >   s-   & !# .205HH H 	H H H ,H H *.H HT   +/!*77 7
 7 )7 7 
&7z +/%
%
 	%

 )%
 %
 %
 
&%
V +/ 	
 )   
&F +/33 3 )	3
 3 3 
3@ +/33 3 )	3
 3 3 
3:  +/99 	9
 9 9 )9 9 
&9|  +/"3"3 "3 	"3
 "3 )"3 "3 
"3N  +/## # 	#
 # )# # 
#J  .2== = 	=
 = = ,= 
= =~  +/#'$ .2 N
N
 &N
 	N

 N
 (N
 !N
 N
 N
 ,N
 N
 N
 
N
 N
b AB&:=MP	0 +/#'55 (5 !	5
 5 5 
5n 
 +/#'$, .2 0
0
 0
 (	0

 !0
 0
 0
 0
 ,0
 0
 0
 
0
 0
d  +/#'$ .2 3
63
 3
 	3
 (3
 !3
 3
 3
 ,3
 3
 3
 
3
 3
j  %.2

 

 
 ,
 
 
 

 
8Lr   r.   )r   r   )r"   r   r   rh   )r    rh   r   rh   )-r   
__future__r   ri   r   systypingr   r   r   r   r   r	   r
   numpyrk   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.utilsr   langchain_core.vectorstoresr   &langchain_community.vectorstores.utilsr   	frozensetr   r   r%   r   iinfor   maxre   finforf   
float_infor   r   r#   r&   r*   r,   r.   r   r   r   <module>r     s    , "   
 F F F  - 0 - 3 M;-("  RXXhbhhx()--
rxx+,00NN	(
	+(
+
zL[ zLr   