
    h                       U d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZmZmZmZ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	rd dl"Z"ed
   Z# e$ ee#            Z%de&d<   ed   Z' e$ ee'            Z(de&d<   dZ)dZ*dZ+e+dz  Z,g dZ-g dZ.ddi gZ/ ej`                  e1      Z2d/dZ3d0dZ4d1dZ5d2d3dZ6 eddd       G d d e             Z7	 	 	 	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5d!Z8	 	 	 	 	 	 	 	 	 d6	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7d"Z9	 	 	 	 	 	 d8d#Z:d$g df	 	 	 	 	 	 	 	 	 d9d%Z;d:d&Z<d;d'Z=d<d(Z>d=d)Z?	 	 	 	 	 	 	 	 d>d*Z@d?d+ZA	 	 d@	 	 	 	 	 	 	 dAd,ZBdBd-ZCdCd.ZDy)D    )annotationsN)deepcopy)TYPE_CHECKINGAnyCallableDictIterableListLiteralOptionalSizedTupleTypeUnionget_args)
deprecated)Document)
Embeddings)VectorStore)maximal_marginal_relevance)L2IPzList[DISTANCE_METRICS]AVAILABLE_DISTANCE_METRICS)TileDBDenseTileDBSparse	FaissFlatFaissIVFFlatFlinngzList[ENGINES]AVAILABLE_ENGINES	langchain          )	_distanceidcontent)r$   r&   blobzMissing propertyc                    t        | t              rUt        |t              rEt        |       t        |      k7  r.t        | d| d| dt        |        d| dt        |             y)z
    Check that sizes of two variables are the same

    Args:
        x: Variable to compare
        y: Variable to compare
        x_name: Name for variable x
        y_name: Name for variable y
    z and z% expected to be equal length but len(z)=z	 and len(N)
isinstancer   len
ValueError)xyx_namey_names       c/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/vectorstores/vdms.py_len_check_if_sizedr1   ?   sm     !U
1e 4Q3q69IheF8 $("SVHIfXRAxA
 	
     c                J    t        |       D cg c]  \  }}|	 c}}S c c}}w N)_results_to_docs_and_scores)resultsdoc_s      r0   _results_to_docsr9   Q   s    9'BCFCCCCCs   c                   g }	 | d   \  }}t        |      dkD  rd|d   v rd|d   d   v r|d   d   d   }|D ]r  }t        |d   d      }|d   }t        D ]
  }||v s||=  |j                         D 	
ci c]  \  }	}
|
t        vr|	|
 }}	}
|j                  t        ||      |f       t |S c c}
}	w # t        $ r#}t        j                  d|        Y d }~|S d }~ww xY w)	Nr   FindDescriptorentitiesr$   
   r&   )page_contentmetadataz2No results returned. Error while parsing results: )
r*   roundINVALID_DOC_METADATA_KEYSitemsINVALID_METADATA_VALUEappendr   	Exceptionloggerwarning)r6   	final_res	responsesblobsresult_entitiesentdistancetxt_contentspmkeymvalpropses                r0   r5   r5   U   s5   IQ"1:	5	NQ IaL0il+;<<'l+;<ZHO&  [!126"9~2 #ACxF#
 '*iik"d#99 $J     lUK (   QKA3OPPQs0   AB5 B5 5B/
#B5 /B5 5	C!>CC!c                    	 ddl } |j                          }|j                  | |       |S # t        $ r t        d      w xY w)zVDMS client for the VDMS server.

    Args:
        host: IP or hostname of VDMS server
        port: Port to connect to VDMS server
    r   NzOCould not import vdms python package. Please install it with `pip install vdms.)vdmsImportErrorconnect)hostportrU   clients       r0   VDMS_Clientr[   w   sO    
 TYY[F
NN4M  
8
 	

s	   + A z0.3.18z1.0.0zlangchain_vdms.VDMS)sinceremovalalternative_importc                  D   e Zd ZdZdeddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3dZed4d       Zd5dZd6d	Z	d7d
Z
d8dZd9dZeedf	 	 	 	 	 	 	 	 	 	 	 d:dZ	 	 d;	 	 	 	 	 	 	 	 	 	 	 d<dZ	 	 d=	 	 	 	 	 	 	 d>dZ	 	 d;	 	 	 	 	 	 	 d?dZ	 	 	 	 d@	 	 	 	 	 	 	 	 	 	 	 dAdZ	 	 dB	 	 	 	 	 	 	 dCdZg df	 	 	 	 	 	 	 dDdZ	 dE	 	 	 	 	 	 	 	 	 	 	 dFdZ	 	 	 	 	 	 	 	 dGdZddedf	 	 	 	 	 	 	 	 	 	 	 	 	 dHdZ	 	 	 	 	 dI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dJdZddef	 	 	 	 	 	 	 	 	 	 	 dKdZdef	 	 	 	 	 	 	 	 	 	 	 	 	 dLdZ	 	 	 	 	 	 dMdZdNdZdOdZ	 	 	 dP	 	 	 	 	 	 	 	 	 dQd Z 	 	 	 dR	 	 	 	 	 	 	 	 	 	 	 dSd!Z!eeddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dTd"Z"dUd#Z#e$ddeef	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dVd$       Z%e$dddeef	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dWd%       Z&dddgf	 	 	 	 	 	 	 	 	 dXd&Z'eed'df	 	 	 	 	 	 	 	 	 	 	 	 	 dYd(Z(eed'df	 	 	 	 	 	 	 	 	 	 	 	 	 dZd)Z)eed'df	 	 	 	 	 	 	 	 	 	 	 	 	 d[d*Z*eed'df	 	 	 	 	 	 	 	 	 	 	 	 	 d\d+Z+ddeedddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d]d,Z,eedf	 	 	 	 	 	 	 	 	 	 	 d^d-Z-eedf	 	 	 	 	 	 	 	 	 	 	 d_d.Z.eedf	 	 	 	 	 	 	 	 	 	 	 d`d/Z/eedf	 	 	 	 	 	 	 	 	 	 	 dad0Z0	 	 	 	 	 	 	 	 dbd1Z1	 	 	 	 	 	 	 	 dcd2Z2y)dVDMSa  Intel Lab's VDMS for vector-store workloads.

    To use, you should have both:
    - the ``vdms`` python package installed
    - a host (str) and port (int) associated with a deployed VDMS Server

    Visit https://github.com/IntelLabs/vdms/wiki more information.

    IT IS HIGHLY SUGGESTED TO NORMALIZE YOUR DATA.

    Args:
        client: VDMS Client used to connect to VDMS server
        collection_name: Name of data collection [Default: langchain]
        distance_strategy: Method used to calculate distances. VDMS supports
            "L2" (euclidean distance) or "IP" (inner product) [Default: L2]
        engine: Underlying implementation for indexing and computing distances.
            VDMS supports TileDBDense, TileDBSparse, FaissFlat, FaissIVFFlat,
            and Flinng [Default: FaissFlat]
        embedding: Any embedding function implementing
            `langchain_core.embeddings.Embeddings` interface.
        relevance_score_fn: Function for obtaining relevance score

    Example:
        .. code-block:: python

            from langchain_huggingface import HuggingFaceEmbeddings
            from langchain_community.vectorstores.vdms import VDMS, VDMS_Client

            model_name = "sentence-transformers/all-mpnet-base-v2"
            vectorstore = VDMS(
                client=VDMS_Client("localhost", 55555),
                embedding=HuggingFaceEmbeddings(model_name=model_name),
                collection_name="langchain-demo",
                distance_strategy="L2",
                engine="FaissFlat",
            )
    Nr   r   )	embeddingcollection_namedistance_strategyenginerelevance_score_fnembedding_dimensionsc                   || _         || _        || _        || _        | j	                  ||       || _        | j                  || j                  | j                        | _        y )Nrd   metric)_clientsimilarity_search_enginerc   ra   _check_required_inputsoverride_relevance_score_fnadd_set_collection_name)selfrZ   ra   rb   rc   rd   re   rf   s           r0   __init__zVDMS.__init__   sj     (.%!2"##O5IJ ,>( !%00)) !- !
r2   c                    | j                   S r4   )ra   rp   s    r0   
embeddingszVDMS.embeddings   s    ~~r2   c                    t        | j                  t              r| j                  j                  |      S d}|dz  }t	        |      )Nz*Must provide `embedding` which is expectedz to be an Embeddings object)r)   ra   r   embed_documentsr+   )rp   textsp_strs      r0   _embed_documentszVDMS._embed_documents   s@    dnnj1>>11%88@E22EU##r2   c                    | j                   4t        | j                   d      r | j                   j                  dd|i|S t        d      )Nembed_videopathsz:Must provide `embedding` which has attribute `embed_video` )ra   hasattrr{   r+   )rp   r|   kwargss      r0   _embed_videozVDMS._embed_video   sH    >>%'$..-*P-4>>--DEDVDDL r2   c                    | j                   2t        | j                   d      r| j                   j                  |      S t        d      )Nembed_imageurisz:Must provide `embedding` which has attribute `embed_image`)ra   r~   r   r+   )rp   r   s     r0   _embed_imagezVDMS._embed_image   sA    >>%'$..-*P>>--4-88L r2   c                    t        | j                  t              r| j                  j                  |      S t	        d      )NzEMust provide `embedding` which is expected to be an Embeddings object)r)   ra   r   embed_queryr+   )rp   texts     r0   _embed_queryzVDMS._embed_query   s5    dnnj1>>--d33W r2   c                    | j                   | j                   S | j                  j                         dv rd S t        d| j                   d      )a8  
        The 'correct' relevance function
        may differ depending on a few things, including:
        - the distance / similarity metric used by the VectorStore
        - the scale of your embeddings (OpenAI's are unit normed. Many others are not!)
        - embedding dimensionality
        - etc.
        )ipl2c                    | S r4   r}   )r,   s    r0   <lambda>z1VDMS._select_relevance_score_fn.<locals>.<lambda>  s    Q r2   z=No supported normalization function for distance_strategy of z;.Consider providing relevance_score_fn to VDMS constructor.)rm   rc   lowerr+   rs   s    r0   _select_relevance_score_fnzVDMS._select_relevance_score_fn   sf     ++7333 !!'')\9--1-C-C,D EMM r2   c                    | j                   d|d<    | j                  d||||d|}g }|D ]G  \  }}	| j                   |j                  ||	f       &|j                  || j                  |	      f       I |S )z?Return docs and their similarity scores on a scale from 0 to 1.Tnormalize_distance)querykfetch_kfilterr}   )rm   similarity_search_with_scorerD   )
rp   r   r   r   r   r   docs_and_scoresdocs_and_rel_scoresr7   scores
             r0   (_similarity_search_with_relevance_scoresz-VDMS._similarity_search_with_relevance_scores
  s     ++3+/F'(;$;; 
	

 
 *,) 		JC//7#**C<8#**88?			 #"r2   c                   t        ||dd       ||n|D cg c]  }d  c}}t        ||dd       ||n*|D cg c]  }t        t        j                               ! c}}t        ||dd       g }g }g }	t	        ||||      D ]V  \  }
}}}| j                  ||
|||      \  }}|$|j                  |       |j                  |       |	j                  |       X | j                  ||      \  }}|	S c c}w c c}w )Nrw   rt   	metadatasidsr?   ra   documentr%   )r1   struuiduuid4zip_VDMS__get_add_queryrD   _VDMS__run_vdms_query)rp   rb   rw   rt   r   r   r8   all_queries	all_blobsinserted_idsmetaembr7   r%   r   r'   responseresponse_arrays                     r0   addzVDMS.add*  s    	E:wE!*!6I5<QaT<Q	E9g{C_ce*L3tzz|+<*LE37!#!	"$"%iUC"H 	(D#sB..$#PR / KE4 ""5)  &##B'	( $(#8#8i#P .+ =R +Ms
   	C2$C7c                    t        d|| j                  t        |d|      t        |d|            }| j                  |g      \  }}d|d   v rt	        d|       |S )NAddDescriptorSetvaluerh   FailedCommandr   zFailed to add collection )_add_descriptorsetembedding_dimensiongetattrr   r+   )rp   rb   rd   ri   r   r   r8   s          r0   rn   zVDMS.add_setK  ss     #$$67F367F3
 ++UG4!hqk)88IJKKr2   c                6   g }g }| j                  |      }d|i}|dddgi}nddg|d<   |
d|d   g|d<   t        d|ddddd||		      }|j                  |       | j                  ||      \  }	}
t	        d
|d      }| j                  |g|      \  }}d|	d   v S )zA
        Deletes entire collection if id is not provided
        listN	_deletion==   r   r%   r;   labelrefrR   linkk_neighborsconstraintsr6   FindDescriptorSetT)
storeIndex)_VDMS__get_properties_add_descriptorrD   r   r   )rp   rb   r   r   r   r   collection_propertiesr6   r   r   r   responseSetr8   s                r0   __deletezVDMS.__delete`  s     "$!	 $ 5 5o F01&q	2K(,ayK$?!%s1vK#

 	5!#'#8#8i#P . #T
 ..w	BQ8A;..r2   r?   c                   |i }ntd|i}t        | j                  ||      \  }}|rT|d   d   j                         D 	
ci c]  \  }	}
|	|
d    }}	}
d| d}|dz  }t        |       t        d|        |d fS |r|j	                  |       |d	vr||d
<   |j                         D ],  }|| j                  vs| j                  j                  |       . t        d|d d |d d d d 	      }t        |      }||fS c c}
}	w )Nr%   r;   r   z[!] Embedding with id (z) exists in DB;z#Therefore, skipped and not insertedz	Skipped values are: )N r&   AddDescriptorr   )
_check_descriptor_exists_by_idrj   rB   printupdatekeysr   rD   r   embedding2bytes)rp   rb   r?   ra   r   r%   rR   	id_existsr   prop_keyprop_valskipped_valuepstrr   r'   s                  r0   __get_add_queryzVDMS.__get_add_query  sV    :$&E2JE=or Iu  /44D.E%/eg	!*( hrl*! ! 1OD==d.}o>?d{"LL":%'E) 	5A222**11!4	5  

 y) 
 	
G!s   C8Fc                    t        |||      }| j                  |g      \  }}t        |      dkD  rt        |d         j	                  d      }|S t        t              }|S )N)unique_entitydeletionr   ,)_find_property_entityr   r*   
_bytes2strsplitr   DEFAULT_PROPERTIES)rp   rb   r   r   
find_queryr   response_blobr   s           r0   __get_propertieszVDMS.__get_properties  sr     +=8

 #'"7"7"E-}!$.}Q/?$@$F$Fs$K! %$ %--?$@!$$r2   c                    | j                   j                  ||      \  }}t        ||      }|r| j                   j                          ||fS r4   )rj   r   _check_valid_responseprint_last_response)rp   r   r   r   r   r   r8   s          r0   __run_vdms_queryzVDMS.__run_vdms_query  sI     $(<<#5#5k9#M .!+x8LL,,.''r2   c                .   t        ||dd       t        ||dd       ||n|D cg c]  }d c}}t        ||dd       | j                  |      }g }t        ||||      D ]  \  }	}
}}d| j                  i}ddd	gi}|d|g|d
<   t	        d|ddddd||	      }| j                  |g      \  }}| j                  ||	|
||      \  }}|j| j                  |g|g      \  }}|j                  |        | j                  ||| j                         yc c}w )z
        Updates (find, delete, add) a collection based on id.
        If more than one collection returned with id, error occuers
        r   	documentsrt   Nr   r   r   r   r   r%   r;   r   r   )	r1   r   r   r   r   r   r   rD   _VDMS__update_properties)rp   rb   r   r   rt   r   r8   
orig_propsupdated_idsr   r   r7   r%   r6   r   r   r   r   r'   s                      r0   __updatezVDMS.__update  sj    	CE;?CULA!*!6I3<OaT<O	CE;?**?;
!#"%iY"L 	'D#sBt99:G&q	2K~%)2JD!#  '
E (,'<'<eW'E$Hn.. / KE4 +/+@+@%4&+Q(.""2&?	'B 	  Z)C)C	
O =Ps   	Dc                    |Vt        |      }|D ]  }||vs|j                  |        ||k7  r(t        |d|      \  }}| j                  ||g      \  }}	y y y )Nr   )command_typeall_properties)r   rD   _build_property_queryr   )
rp   rb   current_collection_propertiesnew_collection_propertiesold_collection_propertiespropr   blob_arrr   r8   s
             r0   __update_propertieszVDMS.__update_properties  s     %0(01N(O%1 ?<<188>? -0II(=#!)#@)%X
 #33K(L! J 1r2   Tc           	        |D cg c]  }| j                  |       }}|r|rt        |      D ]  \  }	}|||	   d<    n|rg }|D ]  }|j                  d|i        ||n*|D 
cg c]  }
t        t	        j
                               ! c}
}| j                  |      }||D 
cg c]  }
i  }}
n|D cg c]  }t        |       }} | j                  d|||||d| |S c c}w c c}
w c c}
w c c}w )a  Run more images through the embeddings and add to the vectorstore.

        Images are added as embeddings (AddDescriptor) instead of separate
        entity (AddImage) within VDMS to leverage similarity search capability

        Args:
            uris: List of paths to the images to add to the vectorstore.
            metadatas: Optional list of metadatas associated with the images.
            ids: Optional list of unique IDs.
            batch_size (int): Number of concurrent requests to send to the server.
            add_path: Bool to add image path as metadata

        Returns:
            List of ids from adding images into the vectorstore.
        )
image_pathr   r   rw   rt   r   r   
batch_sizer}   )	encode_image	enumeraterD   r   r   r   r   _validate_vdms_propertiesadd_from)rp   r   r   r   r   add_pathr   uri	b64_textsmidxr8   rt   ms                r0   
add_imageszVDMS.add_images1  s,   2 CGG3T&&#&6G	G	&t_ 4	c03	$-4I 6  ,!456 _cd*K3tzz|+<*K &&D&1
%)**I*?HI!215III 	
!!	
 	
 
; H +L +Is   C#&$C(%	C-5C2c           	        ||D cg c]  }d }}|r|rt        |      D ]  \  }	}
|
||	   d<    n|rg }|D ]  }
|j                  d|
i        ||n*|D cg c]  }t        t        j                               ! c}} | j
                  dd|i|}||D cg c]  }i  }} | j                  d|||||d| |S c c}w c c}w c c}w )a  Run videos through the embeddings and add to the vectorstore.

        Videos are added as embeddings (AddDescriptor) instead of separate
        entity (AddVideo) within VDMS to leverage similarity search capability

        Args:
            paths: List of paths to the videos to add to the vectorstore.
            metadatas: Optional list of text associated with the videos.
            metadatas: Optional list of metadatas associated with the videos.
            ids: Optional list of unique IDs.
            batch_size (int): Number of concurrent requests to send to the server.
            add_path: Bool to add video path as metadata

        Returns:
            List of ids from adding videos into the vectorstore.
        r   
video_pathr|   r   r}   )r   rD   r   r   r   r   r   )rp   r|   rw   r   r   r   r   r   r8   r  pathrt   s               r0   
add_videoszVDMS.add_videosi  s   4 =!&'AR'E'	'. 5
d04	$-5I 7  ,!567 _ce*L3tzz|+<*L 'T&&=U=f=
%*++I+ 	
!!	
 	
 
7 ( +M ,s   	B>$C	Cc           	     8   t        |      }|*|D cg c]  }t        t        j                               ! }}| j	                  |      }||D cg c]  }i  }}n|D cg c]  }t        |       }} | j                  d|||||d|}	|	S c c}w c c}w c c}w )a  Run more texts through the embeddings and add to the vectorstore.

        Args:
            texts: List of strings to add to the vectorstore.
            metadatas: Optional list of metadatas associated with the texts.
            ids: Optional list of unique IDs.
            batch_size (int): Number of concurrent requests to send to the server.

        Returns:
            List of ids from adding the texts into the vectorstore.
        r   r}   )r   r   r   r   ry   r   r   )
rp   rw   r   r   r   r   r8   rt   r  r   s
             r0   	add_textszVDMS.add_texts  s    ( U;.343tzz|$4C4**51
%*++I+?HI!215III$t}} 
!!
 
 # 5
 ,Is   $B	BBc                   | j                  | j                        }g }t        dt        |      |      D ]a  }	t	        |	|z   t        |            }
||	|
 }||	|
 }||	|
 }|r||	|
 }| j                  | j                  |||      }|j                  |       c | j                  | j                  || j                         |S )Nr   )rt   rw   r   r   )	r   ro   ranger*   minr   extendr   r   )rp   rw   rt   r   r   r   r   r   r   	start_idxend_idxbatch_textsbatch_embedding_vectors	batch_idsbatch_metadatasresults                   r0   r   zVDMS.add_from  s     **4+@+@A
"$q#e*j9 	(I)j0#e*=G	'2K&07&C#Ig.I"+Ig">XX%%2!)  F '#	(( 	  !!:t/I/I	
 r2   c                L   | j                   j                         st        d      | j                  t        vrt        d      | j
                  t        vrt        d      | j                  t        d      ||| _        n| j                  6t        | j                  d      r t        | j                  d            | _        n| j                  ~t        | j                  d      st        | j                  d      rRt        | j                  d	      r1	 | j                  j                  j                  j                  | _        nt        d
      | j                  |      }t        | d      r| j                   j#                  |       y || _        y # t        $ r t        d
      w xY w)Nz_VDMS client must be connected to a VDMS server.Please use VDMS_Client to establish a connectionz-distance_strategy must be either 'L2' or 'IP'z]engine must be either 'TileDBDense', 'TileDBSparse', 'FaissFlat', 'FaissIVFFlat', or 'Flinng'Must provide embedding functionr   zThis is a sample sentence.r   r{   modelz>Embedding dimension needed. Please define embedding_dimensionsr   )rj   is_connectedr+   rc   r   rk   r   ra   r   r~   r*   r   r  token_embeddingembedding_dimr   r   r  )rp   rb   rf   current_propss       r0   rl   zVDMS._check_required_inputs  s    ||((*E  !!)CCLMM ((0AA=  >>!>??+';D$^^'GDNNM,R'*!!">?(D$ ^^'DNNM2t~~}5t~~w/,,<<JJ , !T 
 --o>401&&--m<4AD& " $X s   /F F#c                    g }g }ddgd}t        d|d d d d d d |	      }|j                  |       | j                  ||      \  }}|d   d   d   S )Nr   r%   )countr   r;   r   r   returned)r   rD   r   )rp   rb   r   r   r6   r   r   r   s           r0   r  z
VDMS.count'  sy    !#!	/

 	5!#'#8#8i#P .{+,Z88r2   c                ,    t        j                  |      S r4   )base64	b64decode)rp   base64_images     r0   decode_imagezVDMS.decode_image=  s    --r2   c                J    ||n| j                   }| j                  |||      S )zDelete by ID. These are the IDs in the vectorstore.

        Args:
            ids: List of ids to delete.

        Returns:
            Optional[bool]: True if deletion is successful,
            False otherwise, None if not implemented.
        )r   r   )ro   _VDMS__delete)rp   r   rb   r   r   names         r0   deletezVDMS.delete@  s+      #2"=4CXCX}}Ts}DDr2   c                    d}d}t        ||||      }| j                  |g|      \  }	}
|r||	d   v r|	d   |   d   d   d   }|	|
|fS )Nr   r;   )r   r6   r   r<   r   r$   )r   r   )rp   setnamer   r6   r   	normalizemax_distcommand_strr   r   r   s              r0   get_k_candidateszVDMS.get_k_candidatesS  sw     &	
 $(#8#8%)#L .3{;/
;B?LH11r2   c	                   g }	t        |      }
|
|	j                  |
       || j                  ||||	|      \  }}}n5|ddgi}n&d|vrdg|d<   nd|d   vr|d   j                  d       t        ||||      }| j	                  |g      \  }}||d   v r*|d   |   d   dkD  r|d   |   d   D cg c]  }|d   	 }}ng g fS | j                  ||||	|      \  }}}||d   vs||d   v r|d   |   d   dk(  rg g fS g }|d   |   d   D ]*  }|d   |v r|j                  |       t        |      |k(  s* n ||d   |   d<   t        |      |d   |   d<   t        |      |k  rd}t        |       |rS|dt        j                  fv rd	n|}t        |d   |   d         D ]$  \  }}|d
   |z  |d
<   |d
   |d   |   d   |   d
<   & ||fS c c}w )N)r*  r   r%   r   r6   r   r  r<   z4Returned items < k_neighbors; Try increasing fetch_kg      ?r$   )
r   rD   r-  r   r   r*   r   npinfr   )rp   r,  r)  r   r   r   r6   query_embeddingr   r   r'   r   r   r+  r   rL   ids_of_interestnew_entitiesrx   ent_idxs                       r0   get_descriptor_responsezVDMS.get_descriptor_responsej  s     "	/T"151F1FgyDV 2G 2.Hnh !D6*w&#'&WV_,&&t, $'	E (,'<'<eW'E$Hnhqk)hqk+.Fz.RUV.V)1![)A*)M#"%CI# # 2v 261F1F'9@R 2G 2.Hnh (1+-x{*x{;/G
/SWX/X2v (*L{;/
; t9/ '',|$3	
 4@HQK$Z036|3DHQK$Z0< ;.Ne&1bff+5s8H )(1+k*B:*N O #&{#3h#>K MPNK(4W=kJ ''I#s   3Gc                    t        |d      5 }|j                         }t        j                  |      j	                  d      cd d d        S # 1 sw Y   y xY w)Nrbzutf-8)openreadr   	b64encodedecode)rp   r   fr'   s       r0   r   zVDMS.encode_image  sG    *d# 	:q668D##D)009	: 	: 	:s   4AAc           	         |d   }| j                  ||D cg c]  }|j                   c}|D cg c]  }|j                   c}||||      S c c}w c c}w )a  Create a VDMS vectorstore from a list of documents.

        Args:
            collection_name (str): Name of the collection to create.
            documents (List[Document]): List of documents to add to vectorstore.
            embedding (Embeddings): Embedding function. Defaults to None.
            ids (Optional[List[str]]): List of document IDs. Defaults to None.
            batch_size (int): Number of concurrent requests to send to the server.

        Returns:
            VDMS: VDMS vectorstore.
        rZ   )rZ   rw   r   ra   r   r   rb   )
from_textsr>   r?   )	clsr   ra   r   r   rb   r   rZ   r7   s	            r0   from_documentszVDMS.from_documents  s_    , #8,~~/893##9/89s||9!+  	
 		
99s
   A
Ac                    |d   } | |||      }	|*|D 
cg c]  }
t        t        j                               ! }}
|	j                  ||||       |	S c c}
w )aH  Create a VDMS vectorstore from a raw documents.

        Args:
            texts (List[str]): List of texts to add to the collection.
            embedding (Embeddings): Embedding function. Defaults to None.
            metadatas (Optional[List[dict]]): List of metadatas. Defaults to None.
            ids (Optional[List[str]]): List of document IDs. Defaults to None.
            batch_size (int): Number of concurrent requests to send to the server.
            collection_name (str): Name of the collection to create.

        Returns:
            VDMS: VDMS vectorstore.
        rZ   )rb   ra   rZ   )rw   r   r   r   )r   r   r   r	  )r@  rw   ra   r   r   r   rb   r   rZ   vdms_collectionr8   s              r0   r?  zVDMS.from_texts  sr    0 #8,+
 ;.343tzz|$4C4!!!	 	" 	
  5s   $Ac                    g }g }ddi}|||d<   d|v r| j                  |      }||d<   d|v rd|d	<   t        d
|d||      }	|j                  |	       | j                  ||      \  }
}|
|fS )a  Gets the collection.
        Get embeddings and their associated data from the data store.
        If no constraints provided returns all embeddings up to limit.

        Args:
            constraints: A dict used to filter results by.
                   E.g. `{"color" : ["==", "red"], "price": [">", 4.00]}`. Optional.
            limit: The number of documents to return. Optional.
            include: A list of what to include in the results.
                     Can contain `"embeddings"`, `"metadatas"`, `"documents"`.
                     Ids are always included.
                     Defaults to `["metadatas", "documents"]`. Optional.
        r  r   Nlimitr?   r   rt   Tr'   r;   )r   r   r6   )r   r   rD   r   )rp   rb   r   rE  includer   r   r6   r   r   r   r   s               r0   getzVDMS.get  s    ( "$!	#*B-$GG  $($9$9/$J!3GFO 7""GFO#
 	5!#'#8#8i#P .''r2   g      ?c                T   | j                   t        d      t        j                  j	                  |      s(t        | j                   d      r| j                  |      }nt        j                  j	                  |      r-t        | j                   d      r| j                  |g      d   }ngt        j                  j	                  |      r-t        | j                   d      r| j                  |g      d   }nd| d	}|d
z  }|dz  }t        |      | j                  |||||      }	|	S aR  Return docs selected using the maximal marginal relevance.
        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            query (str): Query to look up. Text or path for image or video.
            k: Number of Documents to return. Defaults to 4.
            fetch_k: Number of Documents to fetch 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.
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.

        Returns:
            List of Documents selected by maximal marginal relevance.
        zBFor MMR search, you must specify an embedding function oncreation.r   r   r   r   r{   r|   (Could not generate embedding for query ''.9If using path for image or video, verify embedding model 6has callable functions 'embed_image' or 'embed_video'.)lambda_multr   )
ra   r+   osr  isfiler~   r   r   r   'max_marginal_relevance_search_by_vector)
rp   r   r   r   rO  r   r   embedding_vector	error_msgdocss
             r0   max_marginal_relevance_searchz"VDMS.max_marginal_relevance_search9  s   4 >>!T  ww~~e$)O#007WW^^E"wt~~}'M#00ug0>qAWW^^E"wt~~}'M#00w0?BB5'LITTIQQIY'';;# < 
 r2   c                   | j                  |g||g d      }t        |d   d         dk(  rg S |d   d   D cg c]  }t        t        |             }	}t	        t        j                  |t
        j                        |	||      }
t        |      }t        |      D cg c]  \  }}||
v s| }}}|S c c}w c c}}w aH  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 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.
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.

        Returns:
            List of Documents selected by maximal marginal relevance.
        )r   r   	distancesrt   )query_embeddings	n_resultsr   rF  r   r   dtype)r   rO  )
query_collection_embeddingsr*   r   _bytes2embeddingr   r0  arrayfloat32r9   r   )rp   ra   r   r   rO  r   r   r6   r  embedding_listmmr_selected
candidatesirselected_resultss                  r0   rR  z,VDMS.max_marginal_relevance_search_by_vectoro  s    4 22'[I	 3 
 wqz!}"I >EQZ]39%f-.N  6"**5'	L *'2J (
3 aqL7H    $#! s   B7!B<.B<c                T   | j                   t        d      t        j                  j	                  |      s(t        | j                   d      r| j                  |      }nt        j                  j	                  |      r-t        | j                   d      r| j                  |g      d   }ngt        j                  j	                  |      r-t        | j                   d      r| j                  |g      d   }nd| d	}|d
z  }|dz  }t        |      | j                  |||||      }	|	S rI  )
ra   r+   rP  r  rQ  r~   r   r   r   2max_marginal_relevance_search_with_score_by_vector)
rp   r   r   r   rO  r   r   ra   rT  rU  s
             r0   (max_marginal_relevance_search_with_scorez-VDMS.max_marginal_relevance_search_with_score  s   4 >>!T  ww~~e$)O))%0IWW^^E"wt~~}'M))w)7:IWW^^E"wt~~}'M)))8;IB5'LITTIQQIY''FF# G 
 r2   c                   | j                  |g||g d      }t        |d   d         dk(  rg S |d   d   D cg c]  }t        t        |             }	}t	        t        j                  |t
        j                        |	||      }
t        |      }t        |      D cg c]  \  }\  }}||
v s||f }}}}|S c c}w c c}}}w rX  )
r^  r*   r   r_  r   r0  r`  ra  r5   r   )rp   ra   r   r   rO  r   r   r6   r  rb  rc  rd  re  rf  srg  s                   r0   ri  z7VDMS.max_marginal_relevance_search_with_score_by_vector  s    4 22'[I	 3 
 wqz!}"I >EQZ]39%f-.N  6"**5'	L 5W=J )2*(=   $1fq!lARA    $#! s   B>"C2Cc                    g }	|| j                   }||	S |j                  ddg      }
|d|
v r| j                  d|
v d}|D ]1  }| j                  d|||||||      \  }}|	j	                  ||g       3 |	S )NrF  r   rt   )r   r'   r;   )r   r   r   r6   r   r2  )ro   rG  r   r6  rD   )rp   rZ  rb   r[  r   r   r6   r   r   all_responsesrF  qembr   r   s                 r0   r^  z VDMS.query_collection_embeddings  s     $&""33O#  **Y6?{g522$/G
 % 	=D'+'C'C %"#5 $ (D 	($Hn   (N!;<	= r2   c                f     | j                   |f|||d|}|D cg c]  \  }}|	 c}}S c c}}w )a  Run similarity search with VDMS.

        Args:
            query (str): Query to look up. Text or path for image or video.
            k (int): Number of results to return. Defaults to 3.
            fetch_k (int): Number of candidates to fetch for knn (>= k).
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.

        Returns:
            List[Document]: List of documents most similar to the query text.
        )r   r   r   )r   )	rp   r   r   r   r   r   r   r7   r8   s	            r0   similarity_searchzVDMS.similarity_search:  sG    & <$;;

:@
 #22Q222s   -c                H     | j                   d|g|||d|}t        |      S )a  Return docs most similar to embedding vector.
        Args:
            embedding (List[float]): Embedding to look up documents similar to.
            k (int): Number of Documents to return. Defaults to 3.
            fetch_k (int): Number of candidates to fetch for knn (>= k).
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.
        Returns:
            List of Documents most similar to the query vector.
        rZ  r[  r   r   r}   )r^  r9   rp   ra   r   r   r   r   r6   s          r0   similarity_search_by_vectorz VDMS.similarity_search_by_vectorR  s@    " 3$22 
'[	

 
  ((r2   c                j   | j                   t        d      t        j                  j	                  |      s(t        | j                   d      r| j                  |      }nt        j                  j	                  |      r-t        | j                   d      r| j                  |g      d   }ngt        j                  j	                  |      r-t        | j                   d      r| j                  |g      d   }nd| d	}|d
z  }|dz  }t        |       | j                  d|g|||d|}t        |      S )aE  Run similarity search with VDMS with distance.

        Args:
            query (str): Query to look up. Text or path for image or video.
            k (int): Number of results to return. Defaults to 3.
            fetch_k (int): Number of candidates to fetch for knn (>= k).
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.

        Returns:
            List[Tuple[Document, float]]: List of documents most similar to
            the query text and cosine distance in float for each.
            Lower score represents more similarity.
        r  r   r   r   r   r{   rJ  rK  rL  rM  rN  rs  r}   )ra   r+   rP  r  rQ  r~   r   r   r   r^  r5   )	rp   r   r   r   r   r   r2  rT  r6   s	            r0   r   z!VDMS.similarity_search_with_scorem  s!   * >>!>??77>>%(WT^^]-S/3/@/@/G&74>>=+Q"&"3"3%"3"A!"D&74>>=+Q"&"3"35'"3"B1"EFugRP	XX	UU	 ++6d66 "1!2	
 G +733r2   c                H     | j                   d|g|||d|}t        |      S )a6  
        Return docs most similar to embedding vector and similarity score.

        Args:
            embedding (List[float]): Embedding to look up documents similar to.
            k (int): Number of Documents to return. Defaults to 3.
            fetch_k (int): Number of candidates to fetch for knn (>= k).
            filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.

        Returns:
            List[Tuple[Document, float]]: List of documents most similar to
            the query text. Lower score represents more similarity.
        rs  r}   )r^  r5   rt  s          r0   &similarity_search_with_score_by_vectorz+VDMS.similarity_search_with_score_by_vector  s@    0 3$22 
'[	

 
 +733r2   c                ,    | j                  ||g|g      S )zUpdate a document in the collection.

        Args:
            document_id (str): ID of the document to update.
            document (Document): Document to update.
        )update_documents)rp   rb   document_idr   s       r0   update_documentzVDMS.update_document  s     $$_{mhZPPr2   c                    |D cg c]  }|j                    }}|D cg c]  }t        |j                         }}| j                  |      }| j	                  |||||       yc c}w c c}w )zUpdate a document in the collection.

        Args:
            ids (List[str]): List of ids of the document to update.
            documents (List[Document]): List of documents to update.
        )r   rt   r   N)r>   r   r?   ry   _VDMS__update)rp   rb   r   r   r   r   r?   rt   s           r0   rz  zVDMS.update_documents  s     7@@(%%@@IR
=E%h&7&78
 
 **40
! 	 	
 A
s
   A$A))rZ   	vdms.vdmsra   Optional[Embeddings]rb   r   rc   DISTANCE_METRICSrd   ENGINESre   z"Optional[Callable[[float], float]]rf   Optional[int]returnNone)r  r  )rw   	List[str]r  List[List[float]])r|   r  r   r   r  r  )r   r  r  r  )r   r   r  List[float])r  zCallable[[float], float])r   r   r   intr   r  r   Optional[Dict[str, Any]]r   r   r  List[Tuple[Document, float]])NN)rb   r   rw   r  rt   r  r   1Optional[Union[List[None], List[Dict[str, Any]]]]r   Optional[List[str]]r  r
   )r   r   )rb   r   rd   r  ri   r  r  r   )rb   r   r   zUnion[None, List[str]]r   Union[None, Dict[str, Any]]r  bool)NNNN)rb   r   r?   Optional[Any]ra   Union[List[float], None]r   r  r%   Optional[str]r  z4Tuple[Dict[str, Dict[str, Any]], Union[bytes, None]]FF)rb   r   r   Optional[bool]r   r  r  r  )r   z
List[Dict]r   Optional[List]r   r  r  Tuple[Any, Any]r4   )rb   r   r   r  r   r  rt   r  r   r  r  r  )rb   r   r   r
   r   r  r  r  )r   r  r   Optional[List[dict]]r   r  r   r  r   r  r   r   r  r  )NNNr   T)r|   r  rw   r  r   r  r   r  r   r  r   r  r   r   r  r  )rw   zIterable[str]r   r  r   r  r   r  r   r   r  r  )rw   r  rt   r  r   r  r   r  r   r  r   r   r  r  )rb   r   rf   zUnion[int, None]r  r  )rb   r   r  r  )r"  r   r  bytes)NNN)
r   r  rb   r  r   Optional[Dict]r   r   r  r  )NNF)r)  r   r   r  r6   r  r   r  r*  r  r  z(Tuple[List[Dict[str, Any]], List, float])r,  r   r)  r   r   r  r   r  r   Optional[dict]r6   r  r2  zOptional[List[float]]r   r  r  z!Tuple[List[Dict[str, Any]], List])r   r   r  r   )r@  
Type[VDMS]r   List[Document]ra   r  r   r  r   r  rb   r   r   r   r  r`   )r@  r  rw   r  ra   r  r   r  r   r  r   r  rb   r   r   r   r  r`   )
rb   r   r   r  rE  r  rF  r  r  r  )r   r   r   r  r   r  rO  floatr   Optional[Dict[str, List]]r   r   r  r  )ra   r  r   r  r   r  rO  r  r   r  r   r   r  r  )r   r   r   r  r   r  rO  r  r   r  r   r   r  r  )ra   r  r   r  r   r  rO  r  r   r  r   r   r  r  )rZ  zOptional[List[List[float]]]rb   r  r[  r  r   r  r   r  r6   r  r   r  r   r   r  z!List[Tuple[Dict[str, Any], List]])r   r   r   r  r   r  r   r  r   r   r  r  )ra   r  r   r  r   r  r   r  r   r   r  r  )r   r   r   r  r   r  r   r  r   r   r  r  )ra   r  r   r  r   r  r   r  r   r   r  r  )rb   r   r{  r   r   r   r  r  )rb   r   r   r  r   r  r  r  )3__name__
__module____qualname____doc__DEFAULT_COLLECTION_NAMErq   propertyrt   ry   r   r   r   r   	DEFAULT_KDEFAULT_FETCH_Kr   r   rn   r%  r   r   r   r~  r   DEFAULT_INSERT_BATCH_SIZEr  r  r	  r   rl   r  r#  r'  r-  r6  r   classmethodrA  r?  rG  rV  rR  rj  ri  r^  rq  ru  r   rx  r|  rz  r}   r2   r0   r`   r`      s	   $T +/6.2%AE.2

 (	

 
 ,
 
 ?
 ,
 

8  $4 &+/## # 	#
 )# # 
&#J HL#'  &	
 E ! 
H &#'	  !	
 
0 '+37	+/+/ $+/ 1	+/
 
+/` #'.2"& 6
6
  6
 ,	6

  6
 6
 
>6
v ).#(	%% &% !	%
 
%& %'.3	(( "( ,	(
 
(& HL9
9
 9
 	9

 &9
 E9
 
9
vMM (,M $2	M
 
M. +/#'3#'66 (6 !	6
 6 !6 6 
6v &**.#'#'66 #6 (	6
 !6 6 !6 6 
6v +/#'3'' (' !	'
 ' ' 
'\ +/3## &# 	#
 (# # # 
#J6B"6B:J6B	6Bp9,.
 $()-&*	E E 'E $	E
 E 
E. -1$($)22 2 *	2
 "2 "2 
226 %&&*,015#(J(J( J( 	J(
 J( $J( *J( /J( !J( 
+J(X:
  +/#'36 
 
! 
 ( 
 !	 

  
  
  
 
 
  
D  +/*.#'36&&& (& (	&
 !& & & & 
& &V '+#(\0(0( $0( 	0(
 0( 
0(j & ,044 4 	4
 4 *4 4 
4r & ,05$5$ 5$ 	5$
 5$ *5$ 5$ 
5$t & ,022 2 	2
 2 *2 2 
&2n & ,05$5$ 5$ 	5$
 5$ *5$ 5$ 
&5$r 9=)-"&.2/3#('5' '' 	'
 ' ,' -' !' ' 
+'X &,033 3 	3
 *3 3 
36 &,0)) ) 	)
 *) ) 
)< &,0,4,4 ,4 	,4
 *,4 ,4 
&,4b &,044 4 	4
 *4 4 
&4B	Q"	Q14	Q@H	Q		Q
"
)2
?M
	
r2   r`   c	                    d|i}	d| v r|r||	d<   |||	d<   |t         vr||	d<   d| v r|||	d<   d| v r|t        |      |	d<   d| v r|t         vr||	d	<   d| v r|t         vr||	d
<   | |	i}
|
S )NsetAddr   _ref
propertiesr   Findr   r   r6   )rC   r  )r,  r)  r   r   rR   r   r   r   r6   entityr   s              r0   r   r     s     $W-Fw
v**$| 0v!8 #K 0}4J!J +}0F!F#y&!ELr2   c                    | dk(  rAt        d ||fD              r-||d}|||d<   |||d<   |||d<   |d i fvr||d<   |7||d<   n1| d	k(  rd
|i}|r||d<   |	d i fvr|	|d<   |
|
|d<   nt        d|        | |i}|S )Nr   c              3  $   K   | ]  }|d u 
 y wr4   r}   ).0vars     r0   	<genexpr>z%_add_descriptorset.<locals>.<genexpr>  s      141s   )r&  
dimensionsrd   ri   r  r  r   r   r  r   r   r6   zUnknown command: )allr+   )r,  r&  num_dimsrd   ri   r   rR   r   r   r   r6   r  r   s                r0   r   r     s     ((S 1$((#31 . ""

 %F8%F8? F6Nr
"#(F< !F6N	+	+#-F< tRj($/F=! 'F9 ,[M:;;&!ELr2   c                    t        |      dkD  rdj                  |      nd}d}i }d|d<   d|d<   d	| i}d
|d<   ||d<   ||d<   t        |      }i }|||<   ||fS )Nr   r   r   	AddEntityr  classTr'   r&  zqueryable propertiestyper&   )r*   join
_str2bytes)rb   r   all_properties_str	querytyper  rR   	byte_datar   s           r0   _add_entity_with_blobr  ?  s     695H15L.1RTIF"F7OF6N#_5E*E&M)E) F<-.IEE))r2   findc                N   g }g }g d}|j                         |vr)t        dj                  dj                  |                  |j                         dk(  r"t	        | d      }|j                  |       ||fS |j                         dk(  r5t        | |      \  }}|j                  |       |j                  |       ||fS |j                         dk(  rOt	        | d	      }|j                  |       t        | |      \  }}|j                  |       |j                  |       ||fS )
N)r  r   r   z"[!] Invalid type. Choices are : {}r   r  T)r   r   r   )r   )r   r+   formatr  r   rD   r  )	rb   r   r   r   r   r   choicesr   r  s	            r0   r   r   U  s,     KH'G7*=DDSXXgEVWXXv%%oTJ5!"    
				&0.Qy5!	"    
				)%oE5! 1.Qy5!	"  r2   c                4    t        j                  | d      }|S )Nra  r\  )r0  
frombuffer)r'   r   s     r0   r_  r_  x  s    
--I
.CJr2   c                "    | j                         S r4   )r<  )in_bytess    r0   r   r   }  s    ??r2   c           
         t        t        | D cg c]  }|j                         D ]  }|  c}}            S c c}}w r4   )r   r  r   )r   qr   s      r0   _get_cmds_from_queryr    s2    >1QVVX>Q>Q>?@@>s   :c                j    t        |       }t        t              xr t        fd|D              }|S )Nc              3  d   K   | ]'  }|d    v xr dd    |   v xr d    |   d   d kD   ) yw)r   r  Nr}   )r  cmdr   s     r0   r  z(_check_valid_response.<locals>.<genexpr>  sZ      3  	x{ 	-(1+c**	-QKZ(1,	-3s   -0)r  r)   r   any)r   r   cmd_list	valid_ress    `  r0   r   r     s<    #K0H8T* s 3 	3 0I r2   c                    dd|gi}t        d||dgdd      }|g}| j                  |      \  }}t        ||      }||fS )Nr%   r   r;   r   )r   r  r/  )r   r   r   )	rZ   r)  r%   r   findDescriptorr   resr8   r  s	            r0   r   r     sb    
 $$K$"-	N ""K\\+&FC%k37In$$r2   c                \    d}| 't        j                  | d      }|j                         }|S )zConvert embedding to bytes.Nra  r\  )r0  r`  tobytes)ra   r'   r   s      r0   r   r     s/     Dhhy	2{{}Kr2   c                    d}i }d|d<   |r||d<   i }d|d<   d|d<   d	g|d
<   ||d<   i }|rddg|d<   d| g|d<   ||d<   i }|||<   |S )N
FindEntityr  r  uniqueTr'   r   r  r&   r   r6   r   r   r   r&  r   r}   )rb   r   r   r  r  r6   r   r   s           r0   r   r     s    
 IF"F7O(x GGFOGG kGFOF9"$K$(!9K 1K'F=EE)Lr2   c                ,    t         j                  |       S r4   )r   encode)in_strs    r0   r  r    s    ::fr2   c                x    i }| j                         D ]$  \  }}t        |t              r||t        |      <   & |S r4   )rB   r)   r   r   )r?   new_metadatakeyr   s       r0   r   r     sA    #%Lnn& +
U%&%*LS"+ r2   )
r,   r   r-   r   r.   r   r/   r   r  r  )r6   r   r  r  )r6   r   r  r  )	localhosti  )rX   r   rY   r  r  r  )NNNNNNN)r,  r   r)  r   r   r  r   r  rR   r  r   r  r   r  r   r  r6   r  r  Dict[str, Dict[str, Any]])	NNNNNNFNN)r,  r   r&  r   r  r  rd   r  ri   r  r   r  rR   r  r   r  r   r  r   r  r6   r  r  Dict[str, Any])rb   r   r   r
   r  zTuple[Dict[str, Any], bytes])
rb   r   r   r   r   r
   r   r  r  r  )r'   r  r  r   )r  r  r  r   )r   r   r  r  )r   z
List[dict]r   r   r  r  )rZ   r  r)  r   r%   r   r  zTuple[bool, Any])ra   r  r  zUnion[bytes, None]r  )rb   r   r   r  r   r  r  r  )r  r   r  r  )r?   r  r  r   )E
__future__r   r   loggingrP  r   copyr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   numpyr0  langchain_core._api.deprecationr   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.vectorstoresr   &langchain_community.vectorstores.utilsr   rU   r  r   r   __annotations__r  r   r  r  r  r  r   rA   rC   	getLoggerr  rF   r1   r9   r5   r[   r`   r   r   r  r   r_  r   r  r   r   r   r   r  r   r}   r2   r0   <module>r     s   "   	        6 - 0 3 M 
  6:(CS:T5U 2 U
 $((9#: = :%  	a-3 < ,dB7  
		8	$$DD( (G@UVP
; P
 WP
r*   !%"&"### # 
	#
 # # #  # # #R #   "&"44
4 4 	4
 4 
4 4 4 4  4 4 4n*.!0 	 ! ! !  ! 
	 !
  !F
A%%% 	% 	%& %*$!  	8r2   