
    Ig                       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 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\                  e/      Z0d*dZ1d+dZ2d,dZ3d-d.dZ4 G d de      Z5	 	 	 	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0dZ6	 	 	 	 	 	 	 	 	 d1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2dZ7	 	 	 	 	 	 d3dZ8dg df	 	 	 	 	 	 	 	 	 d4d Z9d5d!Z:d6d"Z;d7d#Z<d8d$Z=	 	 	 	 	 	 	 	 d9d%Z>d:d&Z?	 	 d;	 	 	 	 	 	 	 d<d'Z@d=d(ZAd>d)ZBy)?    )annotationsN)deepcopy)TYPE_CHECKINGAnyCallableDictIterableListLiteralOptionalSizedTupleTypeUnionget_args)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       b/var/www/html/answerous/venv/lib/python3.12/site-packages/langchain_community/vectorstores/vdms.py_len_check_if_sizedr0   >   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      r/   _results_to_docsr8   P   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)r5   	final_res	responsesblobsresult_entitiesentdistancetxt_contentspmkeymvalpropses                r/   r4   r4   T   s2   IQ"1:	5	NQ IaL0il+;<<'l+;<ZHO&  [!126"9~2 #ACxF#
 '*iik"d#99 $J    <%H(S"   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portrT   clients       r/   VDMS_ClientrZ   s   sO    
 TYY[F
NN4M  
8
 	

s	   + A c                  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r`   metric)_clientsimilarity_search_enginer_   r]   _check_required_inputsoverride_relevance_score_fnadd_set_collection_name)selfrY   r]   r^   r_   r`   ra   rb   s           r/   __init__zVDMS.__init__   sj     (.%!2"##O5IJ ,>( !%00)) !- !
r1   c                    | j                   S r3   )r]   rl   s    r/   
embeddingszVDMS.embeddings   s    ~~r1   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(   r]   r   embed_documentsr*   )rl   textsp_strs      r/   _embed_documentszVDMS._embed_documents   s@    dnnj1>>11%88@E22EU##r1   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` )r]   hasattrrw   r*   )rl   rx   kwargss      r/   _embed_videozVDMS._embed_video   sH    >>%'$..-*P-4>>--DEDVDDL r1   c                    | j                   2t        | j                   d      r| j                   j                  |      S t        d      )Nembed_imageurisz:Must provide `embedding` which has attribute `embed_image`)r]   rz   r~   r*   )rl   r   s     r/   _embed_imagezVDMS._embed_image   sA    >>%'$..-*P>>--4-88L r1   c                    t        | j                  t              r| j                  j                  |      S t	        d      )NzEMust provide `embedding` which is expected to be an Embeddings object)r(   r]   r   embed_queryr*   )rl   texts     r/   _embed_queryzVDMS._embed_query   s7    dnnj1>>--d33. r1   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 r3   ry   )r+   s    r/   <lambda>z1VDMS._select_relevance_score_fn.<locals>.<lambda>   s    Q r1   z=No supported normalization function for distance_strategy of z;.Consider providing relevance_score_fn to VDMS constructor.)ri   r_   lowerr*   ro   s    r/   _select_relevance_score_fnzVDMS._select_relevance_score_fn   sf     ++7333 !!'')\9--1-C-C,D EMM r1   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filterry   )ri   similarity_search_with_scorerC   )
rl   r   r   r   r   r{   docs_and_scoresdocs_and_rel_scoresr6   scores
             r/   (_similarity_search_with_relevance_scoresz-VDMS._similarity_search_with_relevance_scores  s     ++3+/F'(;$;; 
	

 
 *,) 	JC//7#**C<8#**$::5AB		 #"r1   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 )Nrs   rp   	metadatasidsr>   r]   documentr$   )r0   struuiduuid4zip_VDMS__get_add_queryrC   _VDMS__run_vdms_query)rl   r^   rs   rp   r   r   r7   all_queries	all_blobsinserted_idsmetaembr6   r$   r   r&   responseresponse_arrays                     r/   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valuerd   FailedCommandr   zFailed to add collection )_add_descriptorsetembedding_dimensiongetattrr   r*   )rl   r^   r`   re   r   r   r7   s          r/   rj   zVDMS.add_setD  ss     #$$67F367F3
 ++UG4!hqk)88IJKKr1   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refrQ   linkk_neighborsconstraintsr5   FindDescriptorSetT)
storeIndex)_VDMS__get_properties_add_descriptorrC   r   r   )rl   r^   r   r   r   r   collection_propertiesr5   r   r   r   responseSetr7   s                r/   __deletezVDMS.__deleteY  s     "$!	 $ 5 5o F01&q	2K(,ayK$?!%s1vK#

 	5!#'#8#8i#P . #T
 ..w	BQ8A;..r1   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_idrf   rA   printupdatekeysr   rC   r   embedding2bytes)rl   r^   r>   r]   r   r$   rQ   	id_existsr   prop_keyprop_valskipped_valuepstrr   r&   s                  r/   __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)rl   r^   r   r   
find_queryr   response_blobr   s           r/   __get_propertieszVDMS.__get_properties  sr     +=8

 #'"7"7"E-}!$.}Q/?$@$F$Fs$K! %$ %--?$@!$$r1   c                    | j                   j                  ||      \  }}t        ||      }|r| j                   j                          ||fS r3   )rf   r   _check_valid_responseprint_last_response)rl   r   r   r   r   r   r7   s          r/   __run_vdms_queryzVDMS.__run_vdms_query  sI     $(<<#5#5k9#M .!+x8LL,,.''r1   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   	documentsrp   Nr   r   r   r   r   r$   r:   r   r   )	r0   r   r   r   r   r   r   rC   _VDMS__update_properties)rl   r^   r   r   rp   r   r7   
orig_propsupdated_idsr   r   r6   r$   r5   r   r   r   r   r&   s                      r/   __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   rC   _build_property_queryr   )
rl   r^   current_collection_propertiesnew_collection_propertiesold_collection_propertiespropr   blob_arrr   r7   s
             r/   __update_propertieszVDMS.__update_properties  s     %0(01N(O%1 ?<<188>? -0II(=#!)#@)%X
 #33K(L! J 1r1   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   rs   rp   r   r   
batch_sizery   )	encode_image	enumeraterC   r   r   r   r   _validate_vdms_propertiesadd_from)rl   r   r   r   r   add_pathr{   uri	b64_textsmidxr7   rp   ms                r/   
add_imageszVDMS.add_images*  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_pathrx   r   ry   )r   rC   r   r   r   r|   r   )rl   rx   rs   r   r   r   r   r{   r7   r   pathrp   s               r/   
add_videoszVDMS.add_videosb  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   ry   )r   r   r   r   ru   r   r   )
rl   rs   r   r   r   r{   r7   rp   r   r   s
             r/   	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   )rp   rs   r   r   )	r   rk   ranger)   minr   extendr   r   )rl   rs   rp   r   r   r   r{   r   r   	start_idxend_idxbatch_textsbatch_embedding_vectors	batch_idsbatch_metadatasresults                   r/   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	
 r1   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~   rw   modelz>Embedding dimension needed. Please define embedding_dimensionsr   )rf   is_connectedr*   r_   r   rg   r   r]   r   rz   r)   r   r  token_embeddingembedding_dimr   r   r	  )rl   r^   rb   current_propss       r/   rh   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   rC   r   )rl   r^   r   r   r5   r   r   r   s           r/   r  z
VDMS.count   sy    !#!	/

 	5!#'#8#8i#P .{+,Z88r1   c                ,    t        j                  |      S r3   )base64	b64decode)rl   base64_images     r/   decode_imagezVDMS.decode_image6  s    --r1   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   )rk   _VDMS__delete)rl   r   r^   r   r{   names         r/   deletezVDMS.delete9  s+      #2"=4CXCX}}Ts}DDr1   c                    d}d}t        ||||      }| j                  |g|      \  }	}
|r||	d   v r|	d   |   d   d   d   }|	|
|fS )Nr   r:   )r   r5   r   r;   r   r#   )r   r   )rl   setnamer   r5   r   	normalizemax_distcommand_strr   r   r   s              r/   get_k_candidateszVDMS.get_k_candidatesL  sw     &	
 $(#8#8%)#L .3{;/
;B?LH11r1   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   r5   r   r  r;   z4Returned items < k_neighbors; Try increasing fetch_kg      ?r#   )
r   rC   r)  r   r   r)   r   npinfr   )rl   r(  r%  r   r   r   r5   query_embeddingr   r   r&   r   r   r'  r   rK   ids_of_interestnew_entitiesrt   ent_idxs                       r/   get_descriptor_responsezVDMS.get_descriptor_responsec  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)rl   r   fr&   s       r/   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.
        rY   )rY   rs   r   r]   r   r   r^   )
from_textsr=   r>   )	clsr   r]   r   r   r^   r{   rY   r6   s	            r/   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.
        rY   )r^   r]   rY   )rs   r   r   r   )r   r   r   r  )r<  rs   r]   r   r   r   r^   r{   rY   vdms_collectionr7   s              r/   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   rp   Tr&   r:   )r   r   r5   )r   r   rC   r   )rl   r^   r   rA  includer   r   r5   r   r   r   r   s               r/   getzVDMS.get   s    ( "$!	#*B-$GG  $($9$9/$J!3GFO 7""GFO#
 	5!#'#8#8i#P .''r1   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   rw   rx   (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   )
r]   r*   osr  isfilerz   r   r   r|   'max_marginal_relevance_search_by_vector)
rl   r   r   r   rK  r   r{   embedding_vector	error_msgdocss
             r/   max_marginal_relevance_searchz"VDMS.max_marginal_relevance_search2  s   4 >>!W  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'';;# < 
 r1   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   	distancesrp   )query_embeddings	n_resultsr   rB  r   r   dtype)r   rK  )
query_collection_embeddingsr)   r   _bytes2embeddingr   r,  arrayfloat32r8   r   )rl   r]   r   r   rK  r   r{   r5   r  embedding_listmmr_selected
candidatesirselected_resultss                  r/   rN  z,VDMS.max_marginal_relevance_search_by_vectorh  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 rE  )
r]   r*   rL  r  rM  rz   r   r   r|   2max_marginal_relevance_search_with_score_by_vector)
rl   r   r   r   rK  r   r{   r]   rP  rQ  s
             r/   (max_marginal_relevance_search_with_scorez-VDMS.max_marginal_relevance_search_with_score  s   4 >>!W  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 
 r1   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 rT  )
rZ  r)   r   r[  r   r,  r\  r]  r4   r   )rl   r]   r   r   rK  r   r{   r5   r  r^  r_  r`  ra  rb  src  s                   r/   re  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 )NrB  r   rp   )r   r&   r:   )r   r   r   r5   r   r.  )rk   rC  r   r2  rC   )rl   rV  r^   rW  r   r   r5   r   r{   all_responsesrB  qembr   r   s                 r/   rZ  z VDMS.query_collection_embeddings
  s     $&""33O#  **Y6?{g522$/G
 % 	=D'+'C'C %"#5 $ (D 	($Hn   (N!;<	= r1   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   )	rl   r   r   r   r   r{   r   r6   r7   s	            r/   similarity_searchzVDMS.similarity_search3  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.
        rV  rW  r   r   ry   )rZ  r8   rl   r]   r   r   r   r{   r5   s          r/   similarity_search_by_vectorz VDMS.similarity_search_by_vectorK  s@    " 3$22 
'[	

 
  ((r1   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   rw   rF  rG  rH  rI  rJ  ro  ry   )r]   r*   rL  r  rM  rz   r   r   r|   rZ  r4   )	rl   r   r   r   r   r{   r.  rP  r5   s	            r/   r   z!VDMS.similarity_search_with_scoref  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3r1   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.
        ro  ry   )rZ  r4   rp  s          r/   &similarity_search_with_score_by_vectorz+VDMS.similarity_search_with_score_by_vector  s@    0 3$22 
'[	

 
 +733r1   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)rl   r^   document_idr   s       r/   update_documentzVDMS.update_document  s     $$_{mhZPPr1   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   rp   r   N)r=   r   r>   ru   _VDMS__update)rl   r^   r   r   r   r   r>   rp   s           r/   rv  zVDMS.update_documents  s     7@@(%%@@IR
=E%h&7&78
 
 **40
! 	 	
 A
s
   A$A))rY   	vdms.vdmsr]   Optional[Embeddings]r^   r   r_   DISTANCE_METRICSr`   ENGINESra   z"Optional[Callable[[float], float]]rb   Optional[int]returnNone)r  r|  )rs   	List[str]r  List[List[float]])rx   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)r^   r   rs   r  rp   r  r   1Optional[Union[List[None], List[Dict[str, Any]]]]r   Optional[List[str]]r  r
   )r   r   )r^   r   r`   r~  re   r}  r  r   )r^   r   r   zUnion[None, List[str]]r   Union[None, Dict[str, Any]]r  bool)NNNN)r^   r   r>   Optional[Any]r]   Union[List[float], None]r   r  r$   Optional[str]r  z4Tuple[Dict[str, Dict[str, Any]], Union[bytes, None]]FF)r^   r   r   Optional[bool]r   r  r  r  )r   z
List[Dict]r   Optional[List]r   r  r  Tuple[Any, Any]r3   )r^   r   r   r  r   r  rp   r  r   r  r  r  )r^   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)rx   r  rs   r  r   r  r   r  r   r  r   r  r{   r   r  r  )rs   zIterable[str]r   r  r   r  r   r  r{   r   r  r  )rs   r  rp   r  r   r  r   r  r   r  r{   r   r  r  )r^   r   rb   zUnion[int, None]r  r  )r^   r   r  r  )r  r   r  bytes)NNN)
r   r  r^   r  r   Optional[Dict]r{   r   r  r  )NNF)r%  r   r   r  r5   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]r5   r  r.  zOptional[List[float]]r   r  r  z!Tuple[List[Dict[str, Any]], List])r   r   r  r   )r<  
Type[VDMS]r   List[Document]r]   r|  r   r  r   r  r^   r   r{   r   r  r\   )r<  r  rs   r  r]   r|  r   r  r   r  r   r  r^   r   r{   r   r  r\   )
r^   r   r   r  rA  r  rB  r  r  r  )r   r   r   r  r   r  rK  floatr   Optional[Dict[str, List]]r{   r   r  r  )r]   r  r   r  r   r  rK  r  r   r  r{   r   r  r  )r   r   r   r  r   r  rK  r  r   r  r{   r   r  r  )r]   r  r   r  r   r  rK  r  r   r  r{   r   r  r  )rV  zOptional[List[List[float]]]r^   r  rW  r  r   r  r   r  r5   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  )r]   r  r   r  r   r  r   r  r{   r   r  r  )r   r   r   r  r   r  r   r  r{   r   r  r  )r]   r  r   r  r   r  r   r  r{   r   r  r  )r^   r   rw  r   r   r   r  r  )r^   r   r   r  r   r  r  r  )3__name__
__module____qualname____doc__DEFAULT_COLLECTION_NAMErm   propertyrp   ru   r|   r   r   r   	DEFAULT_KDEFAULT_FETCH_Kr   r   rj   r!  r   r   r   rz  r   DEFAULT_INSERT_BATCH_SIZEr   r  r  r   rh   r  r  r#  r)  r2  r   classmethodr=  r;  rC  rR  rN  rf  re  rZ  rm  rq  r   rt  rx  rv  ry   r1   r/   r\   r\      s	   $T +/6.2%AE.2

 (	

 
 ,
 
 ?
 ,
 

8  $4 &+/## # 	#
 )# # 
&#D 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
	
r1   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   r5   )rB   r  )r(  r%  r   r   rQ   r   r   r   r5   entityr   s              r/   r   r     s     $W-Fw
v**$| 0v!8 #K 0}4J!J +}0F!F#y&!ELr1   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r3   ry   ).0vars     r/   	<genexpr>z%_add_descriptorset.<locals>.<genexpr>  s      141s   )r"  
dimensionsr`   re   r  r  r   r   r  r   r   r5   zUnknown command: )allr*   )r(  r"  num_dimsr`   re   r   rQ   r   r   r   r5   r  r   s                r/   r   r     s     ((S 1$((#31 . ""

 %F8%F8? F6Nr
"#(F< !F6N	+	+#-F< tRj($/F=! 'F9 ,[M:;;&!ELr1   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)r^   r   all_properties_str	querytyper  rQ   	byte_datar   s           r/   _add_entity_with_blobr  8  s     695H15L.1RTIF"F7OF6N#_5E*E&M)E) F<-.IEE))r1   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   rC   r  )	r^   r   r   r   r   r   choicesr   r  s	            r/   r   r   N  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!	"  r1   c                4    t        j                  | d      }|S )Nr]  rX  )r,  
frombuffer)r&   r   s     r/   r[  r[  q  s    
--I
.CJr1   c                "    | j                         S r3   )r8  )in_bytess    r/   r   r   v  s    ??r1   c           
         t        t        | D cg c]  }|j                         D ]  }|  c}}            S c c}}w r3   )r   r  r   )r   qr   s      r/   _get_cmds_from_queryr  z  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  Nry   )r  cmdr   s     r/   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    `  r/   r   r   ~  s<    #K0H8T* s 3 	3 0I r1   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   )	rY   r%  r$   r   findDescriptorr   resr7   r  s	            r/   r   r     sb    
 $$K$"-	N ""K\\+&FC%k37In$$r1   c                \    d}| 't        j                  | d      }|j                         }|S )zConvert embedding to bytes.Nr]  rX  )r,  r\  tobytes)r]   r&   r   s      r/   r   r     s/     Dhhy	2{{}Kr1   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   r5   r   r   r   r"  r   ry   )r^   r   r   r  r  r5   r   r   s           r/   r   r     s    
 IF"F7O(x GGFOGG kGFOF9"$K$(!9K 1K'F=EE)Lr1   c                ,    t         j                  |       S r3   )r   encode)in_strs    r/   r  r    s    ::fr1   c                x    i }| j                         D ]$  \  }}t        |t              r||t        |      <   & |S r3   )rA   r(   r   r   )r>   new_metadatakeyr   s       r/   r   r     sA    #%Lnn& +
U%&%*LS"+ r1   )
r+   r   r,   r   r-   r   r.   r   r  r  )r5   r   r  r  )r5   r   r  r  )	localhosti  )rW   r   rX   r  r  r{  )NNNNNNN)r(  r   r%  r   r   r  r   r  rQ   r  r   r  r   r  r   r  r5   r  r  Dict[str, Dict[str, Any]])	NNNNNNFNN)r(  r   r"  r   r  r  r`   r  re   r  r   r  rQ   r  r   r  r   r  r   r  r5   r  r  Dict[str, Any])r^   r   r   r
   r  zTuple[Dict[str, Any], bytes])
r^   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  )rY   r{  r%  r   r$   r   r  zTuple[bool, Any])r]   r  r  zUnion[bytes, None]r  )r^   r   r   r  r   r  r  r  )r  r   r  r  )r>   r  r  r   )C
__future__r   r  loggingrL  r   copyr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   numpyr,  langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.vectorstoresr   &langchain_community.vectorstores.utilsr   rT   r}  r   r   __annotations__r~  r   r  r  r  r  r   r@   rB   	getLoggerr  rE   r0   r8   r4   rZ   r\   r   r   r  r   r[  r   r  r   r   r   r   r  r   ry   r1   r/   <module>r     s   "   	        - 0 3 M 
  6:(CS:T5U 2 U
 $((9#: = :%  	a-3 < ,dB7  
		8	$$D>(N
; N
n*   !%"&"### # 
	#
 # # #  # # #R #   "&"44
4 4 	4
 4 
4 4 4 4  4 4 4n*.!0 	 ! ! !  ! 
	 !
  !F
A%%% 	% 	%& %*$!  	8r1   