
    dh                    v    S SK Jr  S SKJrJrJrJrJrJr  S SK	J
r
  S SKJr  S SKJr  S SKJr   " S S\5      rg	)
    )annotations)AnyDictIterableListOptionalTuple)uuid4)Document)
Embeddings)VectorStorec                  Z  ^  \ rS rSrSr S     SU 4S jjjr S       SS jjr      SS jr S       SS jjr  S         SS jjr	SS jr
SS	 jrSSS
 jjr\        SS j5       r\  S           SS jj5       r\ S         SS jj5       rSrU =r$ )VLite   z?VLite is a simple and fast vector database for semantic search.c                   > [         TU ]  5         Xl        U=(       d    S[        5       R                   3U l         SSKJn  U" SSU R
                  0UD6U l        g ! [         a    [        S5      ef = f)Nvlite_r   )r   RCould not import vlite python package. Please install it with `pip install vlite`.
collection )	super__init__embedding_functionr
   hexr   vliter   ImportError)selfr   r   kwargsr   	__class__s        ^/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/vectorstores/vlite.pyr   VLite.__init__   st     	"4$>&(>	# @doo@@
  	> 	s   A A2c                   [        U5      nUR                  SU Vs/ sH  n[        [        5       5      PM     sn5      nU R                  R                  U5      nU(       d  U Vs/ sH  n0 PM     nn[        XXV5       VVV	V
s/ sH  u  pxpXxXS.PM     nn	nnn
U R                  R                  U5      nU Vs/ sH  oS   PM	     sn$ s  snf s  snf s  sn
n	nnf s  snf )a:  Run more texts through the embeddings and add to the vectorstore.

Args:
    texts: Iterable of strings to add to the vectorstore.
    metadatas: Optional list of metadatas associated with the texts.
    kwargs: vectorstore specific parameters

Returns:
    List of ids from adding the texts into the vectorstore.
ids)textmetadataid	embeddingr   )	listpopstrr
   r   embed_documentszipr   add)r   texts	metadatasr   _r"   
embeddingsr#   r$   r%   r&   data_pointsresultsresults                 r   	add_textsVLite.add_texts#   s      Ujju =u!UWu =>,,<<UC
%*+UUI+ 25Us1W
1W- rR1W 	 
 **..-(/0fq	00 !> ,

 1s   C
%CC
8Cc           
     ~   UR                  SU Vs/ sH  n[        [        5       5      PM     sn5      n/ n/ n[        X5       H  u  pxSU;   a   SSKJn	  U	" US   5      n
UR                  U
5        UR                  UR                  /[        U
5      -  5        UR                  [        [        U
5      5       Vs/ sH	  o SU 3PM     sn5        M  UR                  UR                  5        UR                  UR                  5        M     U R                  XVUS9$ s  snf ! [         a    [        S5      ef = fs  snf )a)  Add a list of documents to the vectorstore.

Args:
    documents: List of documents to add to the vectorstore.
    kwargs: vectorstore specific parameters such as "file_path" for processing
            directly with vlite.

Returns:
    List of ids from adding the documents into the vectorstore.
r"   	file_pathr   )process_filer   r/   )r"   )r(   r)   r
   r+   vlite.utilsr8   r   extendr$   lenrangeappendpage_contentr4   )r   	documentsr   r/   r"   r-   r.   docr%   r8   processed_datais               r   add_documentsVLite.add_documents?   s&    jjy Ay!UWy AB	9*GCf$8 ".f[.A!B^,  #,,#n2E!EF

s>7J1KL1KAd!A3K1KLMS--.  .! +" ~~eC~88) !B # %F  Ms   D
D!:D:
!D7c                X    U R                  XS9nU VVs/ sH  u  pVUPM	     snn$ s  snnf )zReturn docs most similar to query.

Args:
    query: Text to look up documents similar to.
    k: Number of Documents to return. Defaults to 4.

Returns:
    List of Documents most similar to the query.
)k)similarity_search_with_score)r   queryrF   r   docs_and_scoresr@   r/   s          r   similarity_searchVLite.similarity_searchd   s1     ;;E;G"12//222s   &c           
         U=(       d    0 nU R                   R                  U5      nU R                  R                  UUUSUS9nU VV	Vs/ sH  u  pn[	        XS9U	4PM     n
n	nnU
$ s  snn	nf )a  Return docs most similar to query.

Args:
    query: Text to look up documents similar to.
    k: Number of Documents to return. Defaults to 4.
    filter: Filter by metadata. Defaults to None.

Returns:
    List of Tuples of (doc, score), where score is the similarity score.
T)r#   top_kr$   return_scoresr&   r>   r$   )r   embed_queryr   retriever   )r   rH   rF   filterr   r$   r&   r2   r#   scoredocuments_with_scoress              r   rG   "VLite.similarity_search_with_scorev   s    " <R++77>	**%% & 
 *1!
)0%X 4;UC)0 	 !
 %$	!
s   
A'c                `    U R                   R                  XR                  UR                  S9  g)z/Update an existing document in the vectorstore.)r#   r$   N)r   updater>   r$   )r   document_iddocuments      r   update_documentVLite.update_document   s*    

33h>O>O 	 	
    c           	         U R                   R                  U5      nU VVs/ sH  u  p4[        X4S9PM     nnnU$ s  snnf )zGet documents by their IDs.rO   )r   getr   )r   r"   r2   r#   r$   r?   s         r   r^   	VLite.get   sE    **..%QX
QX~tH$:QX 	 
 
s   :c                F    Ub  U R                   R                  " U40 UD6  gg)zDelete by ids.NT)r   delete)r   r"   r   s      r   ra   VLite.delete   s$    ?JJc,V,r\   c                    U " SXS.UD6nU$ )zLoad an existing VLite index.

Args:
    embedding: Embedding function
    collection: Name of the collection to load.

Returns:
    VLite vector store.
r   r   r   r   )clsr&   r   r   r   s        r   from_existing_indexVLite.from_existing_index   s      RyR6Rr\   c                @    U " SX$S.UD6nUR                   " X40 UD6  U$ )a  Construct VLite wrapper from raw documents.

This is a user-friendly interface that:
1. Embeds documents.
2. Adds the documents to the vectorstore.

This is intended to be a quick way to get started.

Example:
.. code-block:: python

    from langchain import VLite
    from langchain.embeddings import OpenAIEmbeddings

    embeddings = OpenAIEmbeddings()
    vlite = VLite.from_texts(texts, embeddings)
rd   r   )r4   )re   r-   r&   r.   r   r   r   s          r   
from_textsVLite.from_texts   s,    4 RyR6R3F3r\   c                @    U " SX#S.UD6nUR                   " U40 UD6  U$ )a  Construct VLite wrapper from a list of documents.

This is a user-friendly interface that:
1. Embeds documents.
2. Adds the documents to the vectorstore.

This is intended to be a quick way to get started.

Example:
.. code-block:: python

    from langchain import VLite
    from langchain.embeddings import OpenAIEmbeddings

    embeddings = OpenAIEmbeddings()
    vlite = VLite.from_documents(documents, embeddings)
rd   r   )rC   )re   r?   r&   r   r   r   s         r   from_documentsVLite.from_documents   s.    2 RyR6RI00r\   )r   r   r   )N)r   r   r   Optional[str]r   r   )r-   zIterable[str]r.   Optional[List[dict]]r   r   return	List[str])r?   List[Document]r   r   rp   rq   )   )rH   r)   rF   intr   r   rp   rr   )rs   N)
rH   r)   rF   rt   rR   zOptional[Dict[str, str]]r   r   rp   zList[Tuple[Document, float]])rX   r)   rY   r   rp   None)r"   rq   rp   rr   )r"   zOptional[List[str]]r   r   rp   zOptional[bool])r&   r   r   r)   r   r   rp   r   )NN)r-   rq   r&   r   r.   ro   r   rn   r   r   rp   r   )
r?   rr   r&   r   r   rn   r   r   rp   r   )__name__
__module____qualname____firstlineno____doc__r   r4   rC   rJ   rG   rZ   r^   ra   classmethodrf   ri   rl   __static_attributes____classcell__)r   s   @r   r   r      s   I
 %)A&A "A 	A A, +/11 (1 	1
 
18#9!#9 #9 
	#9P 33 3 	3
 
3* +/	%% % )	%
 % 
&%@
   	
 
 $ 
 +/$(  (	
 "  
 : 
 %)	!  "	
  
 r\   r   N)
__future__r   typingr   r   r   r   r   r	   uuidr
   langchain_core.documentsr   langchain_core.embeddingsr   langchain_core.vectorstoresr   r   r   r\   r   <module>r      s,    " > =  . 0 3jK jr\   