
    dh?                        S SK Jr  S SK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  \(       a  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)    )annotationsN)TYPE_CHECKINGAnyIterableListOptionalTuple)Document)
Embeddings)VectorStore)TigrisClient)Filterc                  
   \ rS rSrSrSS jr\SS j5       r\SS j5       r  S         SS jjr	  S         SS jjr
  S       SS	 jjr\    S               SS
 jj5       r        SS jrSrg)Tigris   z`Tigris` vector store.c                     SSK nX l        [        UR	                  5       U5      U l        g! [         a    [        S5      ef = f)zInitialize Tigris vector store.r   NzWCould not import tigrisdb python package. Please install it with `pip install tigrisdb`)tigrisdbImportError	_embed_fnTigrisVectorStore
get_search_vector_store)selfclient
embeddings
index_namer   s        _/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/vectorstores/tigris.py__init__Tigris.__init__   sM    	 $.v/@/@/BJO  	@ 	s	   , Ac                    U R                   $ N)r   r   s    r   r   Tigris.embeddings!   s    ~~    c                    U R                   $ r!   )r   r"   s    r   search_indexTigris.search_index%   s    !!!r$   Nc                    U R                  XU5      nU R                  R                  U5      nU Vs/ sH  owR                  PM     sn$ 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.
    ids: Optional list of ids for documents.
        Ids will be autogenerated if not provided.
    kwargs: vectorstore specific parameters

Returns:
    List of ids from adding the texts into the vectorstore.
)
_prep_docsr&   add_documentsid)r   texts	metadatasidskwargsdocsresultrs           r   	add_textsTigris.add_texts)   sD    & u5""006$%ff%%%s   A	c                ^    U R                  XU5      nU VVs/ sH  u  pgUPM	     snn$ s  snnf )z"Return docs most similar to query.)similarity_search_with_score)r   querykfilterr/   docs_with_scoresdoc_s           r   similarity_searchTigris.similarity_search@   s3      <<UvN"23"2"2333s   )c           	        U R                   R                  U5      nU R                  R                  XBUS9n/ nU HN  nUR	                  [        UR                  S   UR                  R                  S5      S9UR                  45        MP     U$ )ad  Run similarity search with Chroma with distance.

Args:
    query (str): Query text to search for.
    k (int): Number of results to return. Defaults to 4.
    filter (Optional[TigrisFilter]): Filter by metadata. Defaults to None.

Returns:
    List[Tuple[Document, float]]: List of documents most similar to the query
        text with distance in float.
)vectorr8   	filter_bytextmetadata)page_contentrC   )	r   embed_queryr&   r=   appendr
   r;   getscore)r   r7   r8   r9   r@   r1   r0   r2   s           r   r6   #Tigris.similarity_search_with_scoreK   s    " ++E2""44& 5 
 .0AKK%&UU6]QUUYYz=R GG	  r$   c                ~    U(       d  [        S5      eU(       d
  [        5       nU " XRU5      nUR                  XUS9  U$ )z9Return VectorStore initialized from texts and embeddings.z`index_name` is required)r,   r-   r.   )
ValueErrorr   r3   )	clsr,   	embeddingr-   r.   r   r   r/   stores	            r   
from_textsTigris.from_textsl   s>     788!^FFz2ecBr$   c                4   U R                   R                  [        U5      5      n/ n[        R                  " X=(       d    / U=(       d    / U=(       d    / 5       H:  u  pgpUU=(       d    / U=(       d    0 S.n
U	(       a  XS'   UR                  U
5        M<     U$ )N)rB   r   rC   r+   )r   embed_documentslist	itertoolszip_longestrF   )r   r,   r-   r.   r   r0   tme_idr;   s              r   r)   Tigris._prep_docs   s     )-(F(FtE{(S
%'%11?J$4"ciR
LA! g2G#C
 D	KK
 r$   )r   r   )r   r   r   r   r   str)returnr   )r\   r   )NN)
r,   Iterable[str]r-   Optional[List[dict]]r.   Optional[List[str]]r/   r   r\   	List[str])   N)
r7   r[   r8   intr9   Optional[TigrisFilter]r/   r   r\   zList[Document])r7   r[   r8   rb   r9   rc   r\   zList[Tuple[Document, float]])NNNN)r,   r`   rM   r   r-   r^   r.   r_   r   zOptional[TigrisClient]r   zOptional[str]r/   r   r\   r   )r,   r]   r-   r^   r.   r_   r\   zList[TigrisDocument])__name__
__module____qualname____firstlineno____doc__r   propertyr   r&   r3   r=   r6   classmethodrO   r)   __static_attributes__ r$   r   r   r      s|    P   " " +/#'	&& (& !	&
 & 
&4 )-		4	4 	4 '		4
 	4 
	4 )-	  '	
 
&B 
 +/#')-$(  (	
 ! ' "  
 ( ( !	
 
r$   r   )
__future__r   rT   typingr   r   r   r   r   r	   langchain_core.documentsr
   langchain_core.embeddingsr   langchain_core.vectorstoresr   r   r   r   tigrisdb.types.filtersr   TigrisFiltertigrisdb.types.vectorTigrisDocumentr   rl   r$   r   <module>rv      s7    "  F F - 0 3%9=@C[ Cr$   