
    Ngt                       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                    j!        Z" ej#         ej         d                    j!        Z$ej%        j!        Z&ddZ'ddZ(ddZ)ddZ*ddZ+ G d de          Z,dS )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float32returnr   c                 >    t          d          t          d          fS )z@Import tiledb-vector-search if available, otherwise raise error.tiledb.vector_searchtiledbr        c/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/vectorstores/tiledb.pydependable_tiledb_importr      s%     	+,,X r   groupstrc                &    | t                    j        S ) Get the URI of the vector index.)VECTOR_INDEX_NAMEurir   s    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   r#   c                    |  dt            S )r!   /)r"   r#   s    r   get_vector_index_urir,   4   s    ''%'''r   c                    |  dt            S )z#Get the URI of the documents array.r*   )r'   r+   s    r   get_documents_array_urir.   9   s    **(***r   c                     e Zd ZdZdddddddUdZedVd            ZddeddWd%Zddd&d'dXd)Z	ddd&d'dYd+Z
	 	 	 dZd[d-Z	 	 	 dZd\d.Zdd&d/dd0d]d2Z	 	 	 	 d^d_d3Z	 	 	 	 d^d`d4Zed5dd6dad=            Zedded>dd?d@dbdH            Z	 dcdddJZ	 	 	 dedfdLZeddedMd>dd?fdgdN            Zedded>dd?d@dhdQ            ZeedddRdidS            ZdjdTZdS )k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_deserialization	embeddingr   	index_urir   metricr2   r3   r4   Optional[Mapping[str, Any]]r5   r   r6   boolkwargsc               `   |st          d          || _        |j        | _        || _        || _        || _        t          d          t          d          }}
|                    |          5  |	                    | j        d          }|dk    r|nt          |          | _        |dk    r|nt          |          | _        |                                 |	                    | j        d          }|j                            d          | _        |                                 || _        | j        dk    r+ |
j        j        d| j        | j        | j        d	|	| _        n5| j        d
k    r* |
j        j        d| j        | j        | j        d	|	| _        ddd           dS # 1 swxY w Y   dS )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rr1   
index_typeFLAT)r#   r4   r5   IVF_FLATNr   )
ValueErrorr7   embed_queryembedding_functionr8   r9   r4   r   	scope_ctxGroupr%   r2   r(   r3   closemetagetrA   r5   
flat_index	FlatIndexvector_indexivf_flat_indexIVFFlatIndex)selfr7   r8   r9   r2   r3   r4   r5   r6   r<   	tiledb_vsr   index_groupr   s                 r   __init__zTileDB.__init__L   s;   , / 		2   #"+"7" /00"" 	 F33 	 	 ,,t~s;;K $r)) ! 4[AA ! "R'' 7DD 
 LL!6<<E#jnn\::DOKKMMM&DN&(($BI$8$B %-;"n% % 	% %!! J..$II$<$I %-;"n% % 	% %!3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .D(F##F'*F'r   Optional[Embeddings]c                    | j         S N)r7   )rQ   s    r   
embeddingszTileDB.embeddings   s
    ~r      )kfilterscore_thresholdids	List[int]scoresList[float]rZ   intr[   Optional[Dict[str, Any]]r\   floatList[Tuple[Document, float]]c                  t          d          }g }|                    | j        d| j        | j                  }t          ||          D ]\  }	}
|	dk    r|
dk    r|	t          k    r|
t          k    r*||	         }|t          |d                   dk    rt          d|	 d|           |
                    d	          }t          t          |d         d                   
          |nt          j        t          j        |                                                              t          j                                                            }|_        |dd |                                D             }t/          fd|                                D                       r|                    |
f           v|                    |
f           |                                 fd|D             }|d|         S )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   r@   r5   r4   r   NtextzCould not find document for id z, got metadata)page_contentc                J    i | ] \  }}|t          |t                    s|gn|!S r   )
isinstancelist).0keyvalues      r   
<dictcomp>z0TileDB.process_index_results.<locals>.<dictcomp>   sC       "U 
5$(?(?J%U  r   c              3  V   K   | ]#\  }}j                             |          |v V  $d S rW   )rh   rK   )rm   rn   ro   
result_docs      r   	<genexpr>z/TileDB.process_index_results.<locals>.<genexpr>   sQ        "U '++C00E9     r   c                *    g | ]\  }}|k    ||fS r   r   )rm   docscorer\   s      r   
<listcomp>z0TileDB.process_index_results.<locals>.<listcomp>   s+    PPPeu7O7Oe7O7O7Or   )r   openr3   r5   r4   zip
MAX_UINT64MAX_FLOAT_32lenrD   rK   r   r   pickleloadsnparraytolistastypeuint8tobytesrh   itemsallappendrI   )rQ   r]   r_   rZ   r[   r\   r   docs
docs_arrayidxrv   ru   pickled_metadatarh   rr   s        `        @r   process_index_resultszTileDB.process_index_results   s1   * h''[[t{ ! 
 

 c6** 	1 	1JCaxxEQJJj  Ul%:%:S/C{c#f+..!33 !S3!S!Sc!S!STTT"wwz22!s3v;q>/B/BCCCJ+!<H-446677>>rxHHPPRR  '/
#! &,llnn       &,llnn     5 KKU 3444Z/0000PPPPtPPPBQBxr      rZ   r[   fetch_kr   c                  d|v r|                     d          }nt          } | j        j        t	          j        t	          j        |                              t          j                  g                              t          j                  fd||n|i|\  }}|                     |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.
        r\   rZ   Nr   r]   r_   r[   rZ   r\   )	pop	MAX_FLOATrN   queryr   r   r   r   r   )	rQ   r7   rZ   r[   r   r<   r\   dis	            r   &similarity_search_with_score_by_vectorz-TileDB.similarity_search_with_score_by_vector   s    4 &&$jj):;;OO'O&t &Hbhy))00<<=>>EEbjQQ
 
>aaw
 
 
1
 ))!QqT&A * 
 
 	
r   r   c               T    |                      |          } | 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   )rF   r   )rQ   r   rZ   r[   r   r<   r7   r   s           r   similarity_search_with_scorez#TileDB.similarity_search_with_score   sR    , ++E22	:t:
	
 

 
 
 r   List[Document]c                >     | j         |f|||d|}d |D             S )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   c                    g | ]\  }}|S r   r   rm   ru   _s      r   rw   z6TileDB.similarity_search_by_vector.<locals>.<listcomp>5      222Q222r   )r   )rQ   r7   rZ   r[   r   r<   docs_and_scoress          r   similarity_search_by_vectorz"TileDB.similarity_search_by_vector  sO    ( F$E
	
 

 
 
 32/2222r   c                >     | j         |f|||d|}d |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.
        r   c                    g | ]\  }}|S r   r   r   s      r   rw   z,TileDB.similarity_search.<locals>.<listcomp>N  r   r   )r   )rQ   r   rZ   r[   r   r<   r   s          r   similarity_searchzTileDB.similarity_search7  sJ    ( <$;
vw
 
:@
 
 32/2222r         ?rZ   r   lambda_multr[   r   c               d    d|v r|                     d          }nt          }  j        j        t	          j        t	          j        |                              t          j                  g                              t          j                  fd||n|dz  i|\  }}	                     |	d         |d         |||n|dz  |          }
 fd|
D             }t          t	          j        |gt          j                  |||	          }g }|D ]}|
                    |
|                    |S )
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.
        r\   rZ   N   r   r   c                b    g | ]+\  }}j                             |j        g          d          ,S r   )r7   embed_documentsri   )rm   ru   r   rQ   s      r   rw   zMTileDB.max_marginal_relevance_search_with_score_by_vector.<locals>.<listcomp>}  sE     
 
 
FLc1DN**C,<+=>>qA
 
 
r   dtype)rZ   r   )r   r   rN   r   r   r   r   r   r   r   r   )rQ   r7   rZ   r   r   r[   r<   r\   r_   indicesresultsrX   mmr_selectedr   r   s   `              r   2max_marginal_relevance_search_with_score_by_vectorz9TileDB.max_marginal_relevance_search_with_score_by_vectorP  st   : &&$jj):;;OO'O1$+1Hbhy))00<<=>>EEbjQQ
 
ggWq[
 
 

 ,,
!9ggWq[+ - 
 

 
 
 
PW
 
 

 2Hi[
333#	
 
 
  	/ 	/A""71:....r   c                @     | j         |f||||d|}d |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:
            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   c                    g | ]\  }}|S r   r   r   s      r   rw   zBTileDB.max_marginal_relevance_search_by_vector.<locals>.<listcomp>  r   r   )r   )rQ   r7   rZ   r   r   r[   r<   r   s           r   'max_marginal_relevance_search_by_vectorz.TileDB.max_marginal_relevance_search_by_vector  sR    4 R$Q
#
 
 
 
 32/2222r   c                V    |                      |          } | 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   )rF   r   )	rQ   r   rZ   r   r   r[   r<   r7   r   s	            r   max_marginal_relevance_searchz$TileDB.max_marginal_relevance_search  sU    4 ++E22	;t;
#
 
 
 
 r   T)	metadatasr4   rA   
dimensionsvector_typenp.dtyper   Nonec               v   t          d          t          d          }}|                    |          5  	 |                    |           n# |j        $ r}	|	d }	~	ww xY w|                    |d          }
t          |
j                  }t          |
j                  }|dk    r|j        	                    ||||           n$|dk    r|j
        	                    ||||           |
                    |t                     |                    d	d
t          dz
  ft          j        t          j                            }|                    |          }|                    dt          j        d          d          }|g}|r7|                    dt          j        d          }|                    |           |                    |dd|          }|j        	                    ||           |
                    |t0                     |
                                 d d d            d S # 1 swxY w Y   d S )Nr   r   r>   wrB   )r#   r   r   r4   rC   )nameidr      )r   domainr   rg   U1T)r   r   varrh   F)r   sparseallows_duplicatesattrs)r   rG   group_createTileDBErrorrH   r,   r#   r.   rL   createrO   addr"   Dimrz   r   r   r   DomainAttrr   r   ArraySchemaArrayr'   rI   )clsr8   rA   r   r   r   r4   rR   r   errr   r2   docs_uridimdom	text_attrr   metadata_attrschemas                      r   r   zTileDB.create  s    /00"" 	 F33 /	 /	##I....%   	LLC00E3EI>>.uy99HV##$++() +!	 ,     z))(//() +!	 0    II&->I???
 **:>*hry))   C
 --$$Crx~~4PPIKE , &28QU V V]+++''"'	 (  F L&111IIh%9I:::KKMMM_/	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	s5   H.AH.
AAAGH..H25H2rB   r   )r   r]   r9   rA   r4   index_timestamptexts	List[str]rX   List[List[float]]Optional[List[dict]]Optional[List[str]]r   c                  |t           vr't          d| dt          t                                t          d          t          d          }}t	          j        |                              t          j                  }|                     |||j	        d         |j
        |d u|	           |                    |	          5  |st          d          t          |          }t          |          }|d	 |D             }t	          j        |                              t          j                  } |j        j        d|||||
d
k    r|
nd |	d| |                    |d          5 }|Qt	          j        t'          |          t          j                  }t)          t'          |                    D ]}|||<   i }t	          j        |          |d<   |ot	          j        t'          |          gt,                    }d
}|D ]<}t	          j        t1          j        |          t          j                  ||<   |dz  }=||d<   |||<   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y    | d||||	d|S )NzUnsupported distance metric: z. Expected one of r   r   r   )r8   rA   r   r   r   r4   r>   z3embeddings must be provided to build a TileDB indexc           	     b    g | ],}t          t          j        d t          dz
                      -S r   r   r   randomrandintrz   rm   r   s     r   rw   z!TileDB.__from.<locals>.<listcomp>?  s0    MMM!s6>!Z!^<<==MMMr   r   )rA   r8   input_vectorsexternal_idsr   r4   r   r   rg   rh   )r7   r8   r9   r4   r   )INDEX_METRICSrD   rl   r   r   r   r   r   r   shaper   rG   r,   r.   r   	ingestioningestrx   zerosr|   rangeemptyobject
frombufferr}   dumpsr   )r   r   rX   r7   r8   r   r]   r9   rA   r4   r   r<   rR   r   r   r2   r   r   Ar   datar   rh   s                          r   __fromzTileDB.__from  sk     &&=F = ='+M':':= =   /00"" 	 ,,33BJ??

!$*1-%+t+ 	 	
 	
 	
 F33 $	' $	' X !VWWW3I>>.y99H{MMuMMM8C==//	::L&I& %*+)3Ba3G3GT     Xs++ 'q'#%8CJJbi#H#H#HL"3u::.. , ,*+Q!xV($&Hc)nn-=V$L$L$LMA$-  +-="L22"(, , ,a( Q'4D$"&,#' ' ' ' ' ' ' ' ' ' ' ' ' ' ''$	' $	' $	' $	' $	' $	' $	' $	' $	' $	' $	' $	' $	' $	' $	'J s 
	
 

 
 
 	
s8   B&I/)C#II/I	I/I	 I//I36I3Optional[bool]c                    t          j        |                              t           j                  }| j                            ||dk    r|nd           dS )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   r5   T)r   r   r   r   rN   delete_batch)rQ   r]   r5   r<   r   s        r   deletezTileDB.deletee  sZ     x}}++BI66&&%i1nnRV 	' 	
 	
 	
 tr   Iterable[str]c                   t          d          }| j                            t          |                    }|d |D             }t	          j        |                              t          j                  }t	          j        t          |          d          }	t          t          |                    D ]+}
t	          j        ||
         t          j                  |	|
<   ,| j                            |	||dk    r|nd           i }t	          j        |          |d<   |ot	          j        t          |          gt                    }d}
|D ]<}t	          j        t!          j        |          t          j                  ||
<   |
d	z  }
=||d
<   |                    | j        d|dk    r|nd| j                  }|||<   |                                 |S )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   Nc           	     b    g | ],}t          t          j        d t          dz
                      -S r   r   r   s     r   rw   z$TileDB.add_texts.<locals>.<listcomp>  s0    IIIa3v~aa8899IIIr   Or   r   )r   r   r5   rg   r   rh   r   rf   )r   r7   r   rl   r   r   r   r   r   r|   r   r   rN   update_batchr   r   r}   r   r   rx   r3   r4   rI   )rQ   r   r   r]   r5   r<   r   rX   r   r   r   r   r   rh   r   s                  r   	add_textszTileDB.add_textsz  s   ( h''^33DKK@@
;II5IIICx}}++BI66(C
OOC888s:'' 	C 	CA*Q-rzBBBGAJJ&&%#,>>iit 	' 	
 	
 	
 xV Hc)nn%5VDDDMA%  #%=h1G1Grx#X#X#Xa Q,D[[#,>>iit;	 ! 
 

 $(
< 
r   z/tmp/tiledb_arrayc
                `    g }|                     |          } | 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   rX   r7   r   r]   r9   r8   rA   r4   r   r   )r   _TileDB__from)r   r   r7   r   r]   r9   r8   rA   r4   r   r<   rX   s               r   
from_textszTileDB.from_texts  se    F 
..u55
sz 
!!+
 
 
 
 	
r   text_embeddingsList[Tuple[str, List[float]]]c               b    d |D             }d |D             } | j         d||||||||||	d
|
S )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)
        c                    g | ]
}|d          S r   r   rm   ts     r   rw   z*TileDB.from_embeddings.<locals>.<listcomp>	  s    ///!1///r   c                    g | ]
}|d          S )r   r   r  s     r   rw   z*TileDB.from_embeddings.<locals>.<listcomp>
  s    444qad444r   r   r   )r  )r   r  r7   r8   r   r]   r9   rA   r4   r   r<   r   rX   s                r   from_embeddingszTileDB.from_embeddings  ss    J 0////44O444
sz 
!!+
 
 
 
 	
r   )r9   r4   r5   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.
        )r7   r8   r9   r4   r5   r   r   )r   r8   r7   r9   r4   r5   r<   s          r   loadzTileDB.load  s;    ( s 

 
 
 
 	
r   c                4     | j         j        di || _         d S )Nr   )rN   consolidate_updates)rQ   r<   s     r   r  zTileDB.consolidate_updates7  s&    AD-AKKFKKr   )r7   r   r8   r   r9   r   r2   r   r3   r   r4   r:   r5   r   r6   r;   r<   r   )r   rU   )r]   r^   r_   r`   rZ   ra   r[   rb   r\   rc   r   rd   )r7   r`   rZ   ra   r[   rb   r   ra   r<   r   r   rd   )r   r   rZ   ra   r[   rb   r   ra   r<   r   r   rd   )rY   Nr   )r7   r`   rZ   ra   r[   rb   r   ra   r<   r   r   r   )r   r   rZ   ra   r[   rb   r   ra   r<   r   r   r   )r7   r`   rZ   ra   r   ra   r   rc   r[   rb   r<   r   r   rd   )rY   r   r   N)r7   r`   rZ   ra   r   ra   r   rc   r[   rb   r<   r   r   r   )r   r   rZ   ra   r   ra   r   rc   r[   rb   r<   r   r   r   )r8   r   rA   r   r   ra   r   r   r   r;   r4   r:   r   r   )r   r   rX   r   r7   r   r8   r   r   r   r]   r   r9   r   rA   r   r4   r:   r   ra   r<   r   r   r0   )Nr   )r]   r   r5   ra   r<   r   r   r   )NNr   )r   r   r   r   r]   r   r5   ra   r<   r   r   r   )r   r   r7   r   r   r   r]   r   r9   r   r8   r   rA   r   r4   r:   r   ra   r<   r   r   r0   )r  r  r7   r   r8   r   r   r   r]   r   r9   r   rA   r   r4   r:   r   ra   r<   r   r   r0   )r8   r   r7   r   r9   r   r4   r:   r5   r   r<   r   r   r0   )r<   r   r   r   )__name__
__module____qualname____doc__rT   propertyrX   r   r   r   r   r   r   r   r   r   classmethodr   DEFAULT_METRICr  r   r   r  r
  r  r  r   r   r   r0   r0   >   s@        & !# .205H H H H H HT    X +/!*7 7 7 7 7 7z +/%
 %
 %
 %
 %
 %
V +/     F +/3 3 3 3 3@ +/3 3 3 3 3:  +/9 9 9 9 9 9|  +/"3 "3 "3 "3 "3N  +/# # # # #J  .2= = = = = [=~  +/#'$ .2 N
 N
 N
 N
 N
 [N
b AB    0 +/#'5 5 5 5 5n 
 +/#'$, .2 0
 0
 0
 0
 [0
d  +/#'$ .2 3
 3
 3
 3
 3
 [3
j  %.2
 
 
 
 
 [
8L L L L L Lr   r0   )r   r   )r   r   r   r   )r#   r   r   r   )-r  
__future__r   r}   r   systypingr   r   r   r   r   r	   r
   numpyr   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.utilsr   langchain_core.vectorstoresr   &langchain_community.vectorstores.utilsr   	frozensetr   r  r'   r"   iinfor   maxrz   finfor{   
float_infor   r   r%   r(   r,   r.   r0   r   r   r   <module>r$     s   , , " " " " " "   



 F F F F F F F F F F F F F F F F F F     - - - - - - 0 0 0 0 0 0 - - - - - - 3 3 3 3 3 3 M M M M M M	;-(("  RXhbhx(())-
rx++,,0N	   ( ( ( (
	+ 	+ 	+ 	+( ( ( (
+ + + +
zL zL zL zL zL[ zL zL zL zL zLr   