§
    šŠtjáh  ã                  ó¼   — d dl mZ d dlZd dlmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ erd dlmZ dd	d
d
dœZ ej        e¦  «        Z G d„ de¦  «        ZdS )é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚDictÚIterableÚListÚOptionalÚTuple)ÚDocument)Ú
Embeddings)ÚVectorStore©ÚHippoClientÚ	localhostÚ7788Úadmin)ÚhostÚportÚusernameÚpasswordc                  óÐ   — e Zd ZdZ	 	 	 	 	 	 	 dBdCd„ZdDd„Z	 dEdFd„Z	 dGdHd!„ZdId"„ZdJd#„Z	dId$„Z
	 	 	 dKdLd.„Z	 	 	 	 dMdNd6„Z	 	 	 	 dMdOd8„Z	 	 	 	 dMdPd;„ZedddedddfdQdA„¦   «         ZdS )RÚHippoaá  `Hippo` vector store.

    You need to install `hippo-api` and run Hippo.

    Please visit our official website for how to run a Hippo instance:
    https://www.transwarp.cn/starwarp

    Args:
        embedding_function (Embeddings): Function used to embed the text.
        table_name (str): Which Hippo table to use. Defaults to
            "test".
        database_name (str): Which Hippo database to use. Defaults to
            "default".
        number_of_shards (int): The number of shards for the Hippo table.Defaults to
            1.
        number_of_replicas (int): The number of replicas for the Hippo table.Defaults to
            1.
        connection_args (Optional[dict[str, any]]): The connection args used for
            this class comes in the form of a dict.
        index_params (Optional[dict]): Which index params to use. Defaults to
            IVF_FLAT.
        drop_old (Optional[bool]): Whether to drop the current collection. Defaults
            to False.
        primary_field (str): Name of the primary key field. Defaults to "pk".
        text_field (str): Name of the text field. Defaults to "text".
        vector_field (str): Name of the vector field. Defaults to "vector".

    The connection args used for this class comes in the form of a dict,
    here are a few of the options:
        host (str): The host of Hippo instance. Default at "localhost".
        port (str/int): The port of Hippo instance. Default at 7788.
        user (str): Use which user to connect to Hippo instance. If user and
            password are provided, we will add related header in every RPC call.
        password (str): Required when user is provided. The password
            corresponding to the user.

    Example:
        .. code-block:: python

        from langchain_community.vectorstores import Hippo
        from langchain_community.embeddings import OpenAIEmbeddings

        embedding = OpenAIEmbeddings()
        # Connect to a hippo instance on localhost
        vector_store = Hippo.from_documents(
            docs,
            embedding=embeddings,
            table_name="langchain_test",
            connection_args=HIPPO_CONNECTION
        )

    Raises:
        ValueError: If the hippo-api python package is not installed.
    ÚtestÚdefaulté   NFÚembedding_functionr   Ú
table_nameÚstrÚdatabase_nameÚnumber_of_shardsÚintÚnumber_of_replicasÚconnection_argsúOptional[Dict[str, Any]]Úindex_paramsúOptional[dict]Údrop_oldúOptional[bool]c	                ó  — || _         || _        || _        || _        || _        || _        d| _        d| _        d| _        g | _	        |€t          }|                      |¦  «        | _        d | _        	 | j                             | j        | j        ¦  «        r'|r%| j                             | j        | j        ¦  «         n2# t           $ r%}	t#          j        d| j        › d|	› �¦  «         ‚ d }	~	ww xY w	 | j                             | j        | j        ¦  «        r*| j                             | j        | j        ¦  «        | _        n2# t           $ r%}	t#          j        d| j        › d|	› �¦  «         ‚ d }	~	ww xY w|                      ¦   «          d S )NÚpkÚtextÚvectorz+An error occurred while deleting the table z: z*An error occurred while getting the table )r    r"   Úembedding_funcr   r   r%   Ú_primary_fieldÚ_text_fieldÚ_vector_fieldÚfieldsÚDEFAULT_HIPPO_CONNECTIONÚ_create_connection_aliasÚhcÚcolÚcheck_table_existsÚdelete_tableÚ	ExceptionÚloggingÚerrorÚ	get_tableÚ_get_env)
Úselfr   r   r   r    r"   r#   r%   r'   Úes
             úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/vectorstores/hippo.pyÚ__init__zHippo.__init__P   s¼  € ð !1ˆÔØ"4ˆÔØ0ˆÔØ$ˆŒØ*ˆÔØ(ˆÔð #ˆÔà!ˆÔà%ˆÔØ!#ˆŒàÐ"Ý6ˆOØ×/Ò/°Ñ@Ô@ˆŒØˆŒð
	à”×*Ò*¨4¬?¸DÔ<NÑOÔOðJàðJð ”×$Ò$ T¤_°dÔ6HÑIÔIÐIøøÝð 	ð 	ð 	ÝŒMØT¸d¼oÐTÐTÐQRÐTÐTñô ð ð øøøøð		øøøð	ØŒw×)Ò)¨$¬/¸4Ô;MÑNÔNð RØœ7×,Ò,¨T¬_¸dÔ>PÑQÔQ�”øøÝð 	ð 	ð 	ÝŒMØS¸T¼_ÐSÐSÐPQÐSÐSñô ð ð øøøøð		øøøð 	�Š‰Œˆˆˆs2   Á2AB? Â?
C.Ã	 C)Ã)C.Ã2AE Å
E1Å E,Å,E1ÚdictÚreturnr   c                ó¢  ‡	— 	 ddl m} n"# t          $ r}t          d¦  «        |‚d}~ww xY w|                     dd¦  «        }|                     dd¦  «        Š	|                     dd¦  «        }|                     d	d¦  «        }|�`‰	�^d
|v r7|                     d
¦  «        }d
                     ˆ	fd„|D ¦   «         ¦  «        }n2t          |¦  «        dz   t          ‰	¦  «        z   }nt          d¦  «        ‚	 t           	                    d|› d�¦  «          ||g||¬¦  «        S # t          $ r!}t                               d¦  «         |‚d}~ww xY w)z*Create the connection to the Hippo server.r   r   zQUnable to import transwarp_hipp_api, please install with `pip install hippo-api`.Nr   r   r   Úshivar   ú,c                ó   •— g | ]	}|› d ‰› �‘Œ
S )ú:© )Ú.0Úhr   s     €r?   ú
<listcomp>z2Hippo._create_connection_alias.<locals>.<listcomp>�   s#   ø€ Ð)GÐ)GÐ)G¸A¨Q¨-¨-°¨-¨-Ð)GÐ)GÐ)Gó    rG   z/Missing standard address type for reuse attemptzcreate HippoClient[ú])r   ÚpwdzFailed to create new connection)Ú transwarp_hippo_api.hippo_clientr   ÚImportErrorÚgetÚsplitÚjoinr   Ú
ValueErrorÚloggerÚinfor8   r:   )
r=   r#   r   r>   r   r   r   ÚhostsÚgiven_addressr   s
            @r?   r3   zHippo._create_connection_alias‰   s™  ø€ ð	ØDÐDÐDÐDÐDÐDÐDøÝð 	ð 	ð 	Ýð+ñô ð ðøøøøð	øøøð .×1Ò1°&¸$Ñ?Ô?ˆØ-×1Ò1°&¸$Ñ?Ô?ˆØ'×+Ò+¨J¸Ñ@Ô@ˆØ'×+Ò+¨J¸Ñ@Ô@ˆð Ð Ð 0Ø�dˆ{ˆ{ØŸ
š
 3™œ�Ø #§¢Ð)GÐ)GÐ)GÐ)GÀÐ)GÑ)GÔ)GÑ HÔ H��å # D¡	¤	¨C¡µ#°d±)´)Ñ ;��åÐNÑOÔOÐOð	Ý�KŠKÐ>¨mÐ>Ð>Ð>Ñ?Ô?Ð?Ø�; ˜¸ÀxÐPÑPÔPÐPøÝð 	ð 	ð 	Ý�LŠLÐ:Ñ;Ô;Ð;ØˆGøøøøð	øøøs(   ƒ
 Š
)”$¤)Ã6,D# Ä#
EÄ-E	Å	EÚ
embeddingsúOptional[list]Ú	metadatasúOptional[List[dict]]ÚNonec                óî   — t                                d¦  «         |�0t                                d¦  «         |                      ||¦  «         |                      ¦   «          |                      ¦   «          d S )Nzinit ...zcreate collection)rU   rV   Ú_create_collectionÚ_extract_fieldsÚ_create_index)r=   rY   r[   s      r?   r<   zHippo._get_envª   so   € õ 	�Š�JÑÔÐØÐ!Ý�KŠKÐ+Ñ,Ô,Ð,Ø×#Ò# J°	Ñ:Ô:Ð:Ø×ÒÑÔÐØ×ÒÑÔÐÐÐrL   Úlistc           
     ó   — ddl m} ddlm} t	          |d         ¦  «        }t
                               d|› �¦  «         g }|                      || j        d|j	        ¦  «        ¦  «         |                      || j
        d|j	        ¦  «        ¦  «         |                      || j        d|j        d|i¬¦  «        ¦  «         |r“|d                              ¦   «         D ]x\  }}t          |t          ¦  «        r9t	          |¦  «        }	|                      ||d|j        d|	i¬¦  «        ¦  «         ŒS|                      ||d|j	        ¦  «        ¦  «         Œyt
                               d	|› �¦  «         | j                             | j        d|| j        | j        | j        ¬
¦  «         | j                             | j        | j        ¦  «        | _        t
                               d| j        › d| j        › d�¦  «         d S )Nr   )Ú
HippoField)Ú	HippoTypez[_create_collection] dim: TFÚ	dimension)Útype_paramsz[_create_collection] fields: )ÚnameÚauto_idr1   r   r    r"   z$[_create_collection] : create table z in z successfully)rO   rd   Útranswarp_hippo_api.hippo_typere   ÚlenrU   ÚdebugÚappendr.   ÚSTRINGr/   r0   ÚFLOAT_VECTORÚitemsÚ
isinstancerb   r4   Úcreate_tabler   r   r    r"   r;   r5   rV   )
r=   rY   r[   rd   re   Údimr1   ÚkeyÚvalueÚ	value_dims
             r?   r_   zHippo._create_collection´   sp  € ð 	@Ð?Ð?Ð?Ð?Ð?Ø<Ð<Ð<Ð<Ð<Ð<õ �*˜Q”-Ñ Ô ˆÝ�ŠÐ7°#Ð7Ð7Ñ8Ô8Ð8Øˆð 	�Š�j�j Ô!4°d¸IÔ<LÑMÔMÑNÔNÐNð 	�Š�j�j Ô!1°5¸)Ô:JÑKÔKÑLÔLÐLð 	�ŠØˆJØÔ"ØØÔ&Ø(¨#Ð.ð	ñ ô ñ	
ô 	
ð 	
ð ð 	Là'¨œl×0Ò0Ñ2Ô2ð Lð L‘
��Uå˜e¥TÑ*Ô*ð LÝ # E¡
¤
�IØ—M’MØ"˜
ØØ!Ø%Ô2Ø)4°iÐ(@ð	ñ ô ñô ð ð ð —M’M * *¨S°%¸Ô9IÑ"JÔ"JÑKÔKÐKÐKå�ŠÐ=°VÐ=Ð=Ñ>Ô>Ð>ð 	Œ×ÒØ”ØØØÔ,Ø!Ô2Ø#Ô6ð 	ñ 	
ô 	
ð 	
ð ”7×$Ò$ T¤_°dÔ6HÑIÔIˆŒÝ�ŠðSØ œOðSð SØ15Ô1CðSð Sð Sñ	
ô 	
ð 	
ð 	
ð 	
rL   c                ó  — ddl m} t          | j        |¦  «        rq| j        j        }t
                               d|› �¦  «         |D ]!}| j                             |j	        ¦  «         Œ"t
                               d| j        › �¦  «         dS dS )z,Grab the existing fields from the Collectionr   ©Ú
HippoTablez[_extract_fields] schema:z04 [_extract_fields] fields:N)
rO   ry   rq   r5   ÚschemarU   rl   r1   rm   rh   )r=   ry   rz   Úxs       r?   r`   zHippo._extract_fieldsõ   s¦   € à?Ð?Ð?Ð?Ð?Ð?å�d”h 
Ñ+Ô+ð 	GØ”X”_ˆFÝ�LŠLÐ=°VÐ=Ð=Ñ>Ô>Ð>Øð +ð +�Ø”×"Ò" 1¤6Ñ*Ô*Ð*Ð*Ý�LŠLÐE¸¼ÐEÐEÑFÔFÐFÐFÐFð	Gð 	GrL   c                óÂ  — ddl m} t          | j        |¦  «        rÃ| j                             | j        | j        ¦  «                             | j        i ¦  «        }|                     dd¦  «        }|€dS | j                             | j        | j        ¦  «        | j                 d         D ]4}t           
                    d|› �¦  «         |d         | j        k    r|c S Œ5dS )z0Return the vector index information if it existsr   rx   Úembedding_indexesNz[_get_index] embedding_indexes Úcolumn)rO   ry   rq   r5   r4   Úget_table_infor   r   rQ   rU   rl   r0   )r=   ry   Ú
table_infor}   r{   s        r?   Ú
_get_indexzHippo._get_index  sú   € à?Ð?Ð?Ð?Ð?Ð?å�d”h 
Ñ+Ô+ð 	!Øœ×/Ò/Ø” Ô!3ñô çŠc�$”/ 2Ñ&Ô&ð ð !+§¢Ð/BÀDÑ IÔ IÐØ Ð(Ø�tàœ×/Ò/°´ÀÔASÑTÔTØ”Oôà%ô'ð !ð !�Aõ —L’LÐ!VÐCTÐ!VÐ!VÑWÔWÐWØ˜”{ dÔ&8Ò8Ð8Ø ˜˜˜ð 9àˆtrL   c                óh
  — ddl m} ddlm}m} t          | j        |¦  «        �r	|                      ¦   «         �€ö|                      ¦   «         �€ã| j        €¿d|j	        |j
        ddœ| _        | j                             | j        | j        d         | j        d	         | j        d
         | j        d         ¬¦  «         t                               | j                             | j        d         ¦  «        ¦  «         t                               d¦  «         dS |j
        |j        |j        |j        |j        dœ}|j        |j        |j	        |j	        dœ}|| j        d
                  | j        d
<   | j        d	         dk    r�|| j        d	                  | j        d	<   | j                             | j        | j        d         | j        d	         | j        d
         ¦  «         t                               | j                             | j        d         ¦  «        ¦  «         dS | j        d	         dk    s| j        d	         dk    rÒ|| j        d	                  | j        d	<   | j                             | j        | j        d         | j        d	         | j        d
         | j                             dd¦  «        | j                             dd¦  «        ¬¦  «         t                               | j                             | j        d         ¦  «        ¦  «         dS | j        d	         dk    �r|| j        d	                  | j        d	<   | j                             | j        | j        d         | j        d	         | j        d
         | j                             dd¦  «        | j                             dd¦  «        | j                             dd¦  «        | j                             d¦  «        ¬¦  «         t                               | j                             | j        d         ¦  «        ¦  «         dS | j        d	         dk    ré|| j        d	                  | j        d	<   | j                             | j        | j        d         | j        d	         | j        d
         | j                             d¦  «        | j                             d¦  «        | j                             d¦  «        ¬¦  «         t                               | j                             | j        d         ¦  «        ¦  «         dS t/          d¦  «        ‚dS dS dS ) z Create a index on the collectionr   rx   )Ú	IndexTypeÚ
MetricTypeNÚlangchain_auto_createé
   )Ú
index_nameÚmetric_typeÚ
index_typeÚnlistr‡   r‰   rˆ   rŠ   )rŠ   zcreate index successfully)ÚIVF_FLATÚFLATÚIVF_SQÚIVF_PQÚHNSW)ÚipÚIPÚl2ÚL2rŒ   r‹   r�   Únprobe)rŠ   r”   rŽ   Únbitsé   Úm)rŠ   r”   r•   r—   r�   ÚMÚef_constructionÚ	ef_search)r˜   r™   rš   zeIndex name does not match, please enter the correct index name. (FLAT, IVF_FLAT, IVF_PQ,IVF_SQ, HNSW))rO   ry   rj   rƒ   r„   rq   r5   r�   r%   r“   r‹   Úcreate_indexr0   rU   rl   Úactivate_indexrV   rŒ   r�   rŽ   r�   r‘   rQ   rT   )r=   ry   rƒ   r„   Ú
index_dictÚmetric_dicts         r?   ra   zHippo._create_index  sr  € à?Ð?Ð?Ð?Ð?Ð?ØHÐHÐHÐHÐHÐHÐHÐHå�d”h 
Ñ+Ô+ñ m	°·²Ñ0AÔ0AÑ0IØ�ŠÑ Ô Ñ(ØÔ$Ð,à&=Ø'1¤}Ø&/Ô&8Ø!#ð	)ð )�DÔ%ð ”H×)Ò)ØÔ*ØÔ)¨,Ô7ØÔ)¨,Ô7ØÔ)¨-Ô8Ø"Ô/°Ô8ð *ñ ô ð õ —L’LØœ×/Ò/°Ô0AÀ,Ô0OÑPÔPñô ð õ —K’KÐ ;Ñ<Ô<Ð<Ð<Ð<ð %.Ô$6Ø )¤Ø"+Ô"2Ø"+Ô"2Ø )¤ð"ð "�Jð )œmØ(œmØ(œmØ(œmð	#ð #�Kð 8CØÔ)¨-Ô8ô8�DÔ% mÑ4ð Ô(¨Ô6¸&Ò@Ð@Ø:DØ Ô-¨lÔ;ô;˜Ô)¨,Ñ7ð œ×-Ò-Ø Ô.Ø Ô-¨lÔ;Ø Ô-¨lÔ;Ø Ô-¨mÔ<ñ	ô ð õ ŸšØ œH×3Ò3°DÔ4EÀlÔ4SÑTÔTñô ð ð ð ð Ô)¨,Ô7¸:ÒEÐEØÔ,¨\Ô:¸hÒFÐFà:DØ Ô-¨lÔ;ô;˜Ô)¨,Ñ7ð œ×-Ò-Ø Ô.Ø Ô-¨lÔ;Ø Ô-¨lÔ;Ø Ô-¨mÔ<Ø"&Ô"3×"7Ò"7¸ÀÑ"DÔ"DØ#'Ô#4×#8Ò#8¸À2Ñ#FÔ#Fð .ñ ô ð õ ŸšØ œH×3Ò3°DÔ4EÀlÔ4SÑTÔTñô ð ð ð ð Ô*¨<Ô8¸HÒDÑDØ:DØ Ô-¨lÔ;ô;˜Ô)¨,Ñ7ð œ×-Ò-Ø Ô.Ø Ô-¨lÔ;Ø Ô-¨lÔ;Ø Ô-¨mÔ<Ø"&Ô"3×"7Ò"7¸ÀÑ"DÔ"DØ#'Ô#4×#8Ò#8¸À2Ñ#FÔ#FØ"&Ô"3×"7Ò"7¸ÀÑ"CÔ"CØ"Ô/×3Ò3°CÑ8Ô8ð .ñ 	ô 	ð 	õ ŸšØ œH×3Ò3°DÔ4EÀlÔ4SÑTÔTñô ð ð ð ð Ô*¨<Ô8¸FÒBÐBØ:DØ Ô-¨lÔ;ô;˜Ô)¨,Ñ7ð œ×-Ò-Ø Ô.Ø Ô-¨lÔ;Ø Ô-¨lÔ;Ø Ô-¨mÔ<Ø"Ô/×3Ò3°CÑ8Ô8Ø,0Ô,=×,AÒ,AÐBSÑ,TÔ,TØ&*Ô&7×&;Ò&;¸KÑ&HÔ&Hð .ñ ô ð õ ŸšØ œH×3Ò3°DÔ4EÀlÔ4SÑTÔTñô ð ð ð õ )ðDñô ð ðSm	ð m	Ð0IÐ0IØ(Ð(rL   éè  ÚtextsúIterable[str]ÚtimeoutúOptional[int]Ú
batch_sizeÚkwargsr   ú	List[str]c                óì  ‡ ‡‡‡— ddl m} |rt          d„ |D ¦   «         ¦  «        rt                               d¦  «         g S t          |¦  «        }t                               d|› �¦  «         	 ‰ j                             |¦  «        }n# t          $ r ˆ fd„|D ¦   «         }Y nw xY wt          |¦  «        dk    rt                               d¦  «         g S t                               dt          |¦  «        › �¦  «         t          ‰ j        |¦  «        s‰                      ||¦  «         ‰ j        |‰ j        |iŠt                               d|› �¦  «         t                               d	‰ j        › �¦  «         |�Q|D ]N}|                     ¦   «         D ]7\  }	}
|	‰ j        v r)‰                     |	g ¦  «                             |
¦  «         Œ8ŒOt                               ‰‰ j                 ¦  «         ‰‰ j                 }t          |¦  «        }d‰ j        v r‰ j                             d¦  «         t                               d|› �¦  «         t)          d||¦  «        D ]’Št+          ‰|z   |¦  «        Šˆˆˆfd„‰ j        D ¦   «         }	 ‰ j                             |¦  «        }t                               d|› �¦  «         Œc# t0          $ r#}t                               d‰|¦  «         |‚d
}~ww xY wdgS )a£  
        Add text to the collection.

        Args:
            texts: An iterable that contains the text to be added.
            metadatas: An optional list of dictionaries,
            each dictionary contains the metadata associated with a text.
            timeout: Optional timeout, in seconds.
            batch_size: The number of texts inserted in each batch, defaults to 1000.
            **kwargs: Other optional parameters.

        Returns:
            A list of strings, containing the unique identifiers of the inserted texts.

        Note:
            If the collection has not yet been created,
            this method will create a new collection.
        r   rx   c              3  ó"   K  — | ]
}|d k    V — ŒdS )Ú NrH   )rI   Úts     r?   ú	<genexpr>z"Hippo.add_texts.<locals>.<genexpr>©  s&   è è € Ð3Ð3¨˜A šGÐ3Ð3Ð3Ð3Ð3Ð3rL   zNothing to insert, skipping.z[add_texts] texts: c                óD   •— g | ]}‰j                              |¦  «        ‘ŒS rH   )r-   Úembed_query)rI   r{   r=   s     €r?   rK   z#Hippo.add_texts.<locals>.<listcomp>³  s*   ø€ ÐLÐLÐLÀ˜$Ô-×9Ò9¸!Ñ<Ô<ÐLÐLÐLrL   z[add_texts] len_embeddings:z[add_texts] metadatas:z[add_texts] fields:Nr*   z[add_texts] total_count:c                ó0   •— g | ]}‰|         ‰‰…         ‘ŒS rH   rH   )rI   r{   ÚendÚiÚinsert_dicts     €€€r?   rK   z#Hippo.add_texts.<locals>.<listcomp>Ú  s&   ø€ ÐFÐFÐF°Q˜; qœ>¨!¨C¨%Ô0ÐFÐFÐFrL   z05 [add_texts] insert z0Failed to insert batch starting at entity: %s/%sr©   )rO   ry   ÚallrU   rl   rb   r-   Úembed_documentsÚNotImplementedErrorrk   rq   r5   r<   r/   r0   r1   rp   Ú
setdefaultrm   ÚremoveÚrangeÚminÚinsert_rowsrV   r8   r:   )r=   r    r[   r¢   r¤   r¥   ry   rY   Údrt   ru   ÚvectorsÚtotal_countÚinsert_listÚresr>   r¯   r°   r±   s   `               @@@r?   Ú	add_textszHippo.add_texts�  sU  øøøø€ ð4 	@Ð?Ð?Ð?Ð?Ð?àð 	�Ð3Ð3¨UÐ3Ñ3Ô3Ñ3Ô3ð 	Ý�LŠLÐ7Ñ8Ô8Ð8ØˆIÝ�U‘”ˆå�ŠÐ2¨5Ð2Ð2Ñ3Ô3Ð3ð	MØÔ,×<Ò<¸UÑCÔCˆJˆJøÝ"ð 	Mð 	Mð 	MØLÐLÐLÐLÀeÐLÑLÔLˆJˆJˆJð	Møøøõ ˆz‰?Œ?˜aÒÐÝ�LŠLÐ7Ñ8Ô8Ð8ØˆIå�ŠÐDµ3°z±?´?ÐDÐDÑEÔEÐEõ ˜$œ( JÑ/Ô/ð 	1Ø�MŠM˜* iÑ0Ô0Ð0ð Ô˜eØÔ 
ð(
ˆõ 	�ŠÐ9¨iÐ9Ð9Ñ:Ô:Ð:Ý�ŠÐ8¨4¬;Ð8Ð8Ñ9Ô9Ð9ØÐ Øð Fð F�Ø"#§'¢'¡)¤)ð Fð F‘J�C˜Ø˜dœkÐ)Ð)Ø#×.Ò.¨s°BÑ7Ô7×>Ò>¸uÑEÔEÐEøðFõ 	�Š�[ Ô!1Ô2Ñ3Ô3Ð3ð $ DÔ$6Ô7ˆÝ˜'‘l”lˆà�4”;ÐÐØŒK×Ò˜tÑ$Ô$Ð$å�ŠÐ=°Ð=Ð=Ñ>Ô>Ð>Ý�q˜+ zÑ2Ô2ð 	ð 	ˆAå�a˜*‘n kÑ2Ô2ˆCàFÐFÐFÐFÐFÐF¸$¼+ÐFÑFÔFˆKðØ”h×*Ò*¨;Ñ7Ô7�Ý—’Ð:°SÐ:Ð:Ñ;Ô;Ð;Ð;øÝð ð ð Ý—’ØFÈÈ;ñô ð ð �øøøøð	øøøð
 ˆtˆs*   Á/B
 Â
B%Â$B%Ê7KË
K0ËK+Ë+K0é   ÚqueryÚkÚparamÚexprúOptional[str]úList[Document]c           	     ó†   — | j         €t                               d¦  «         g S  | j        d|||||dœ|¤Ž}d„ |D ¦   «         S )a„  
        Perform a similarity search on the query string.

        Args:
            query (str): The text to search for.
            k (int, optional): The number of results to return. Default is 4.
            param (dict, optional): Specifies the search parameters for the index.
            Defaults to None.
            expr (str, optional): Filtering expression. Defaults to None.
            timeout (int, optional): Time to wait before a timeout error.
            Defaults to None.
            kwargs: Keyword arguments for Collection.search().

        Returns:
            List[Document]: The document results of the search.
        Nú!No existing collection to search.)rÁ   rÂ   rÃ   rÄ   r¢   c                ó   — g | ]\  }}|‘ŒS rH   rH   )rI   ÚdocÚ_s      r?   rK   z+Hippo.similarity_search.<locals>.<listcomp>  s   € Ð&Ð&Ð&™˜˜Q�Ð&Ð&Ð&rL   rH   )r5   rU   rl   Úsimilarity_search_with_score)r=   rÁ   rÂ   rÃ   rÄ   r¢   r¥   r¾   s           r?   Úsimilarity_searchzHippo.similarity_searchå  sk   € ð4 Œ8ÐÝ�LŠLÐ<Ñ=Ô=Ð=ØˆIØ/ˆdÔ/ð 
Ø˜1 E°¸gð
ð 
ØIOð
ð 
ˆð 'Ð& #Ð&Ñ&Ô&Ð&rL   úList[Tuple[Document, float]]c           	     ó¦   — | j         €t                               d¦  «         g S | j                             |¦  «        } | j        d|||||dœ|¤Ž}|S )a˜  
        Performs a search on the query string and returns results with scores.

        Args:
            query (str): The text being searched.
            k (int, optional): The number of results to return.
            Default is 4.
            param (dict): Specifies the search parameters for the index.
            Default is None.
            expr (str, optional): Filtering expression. Default is None.
            timeout (int, optional): The waiting time before a timeout error.
            Default is None.
            kwargs: Keyword arguments for Collection.search().

        Returns:
            List[float], List[Tuple[Document, any, any]]:
        NrÈ   )Ú	embeddingrÂ   rÃ   rÄ   r¢   rH   )r5   rU   rl   r-   r­   Ú&similarity_search_with_score_by_vector)	r=   rÁ   rÂ   rÃ   rÄ   r¢   r¥   rÐ   Úrets	            r?   rÌ   z"Hippo.similarity_search_with_score  st   € ð6 Œ8ÐÝ�LŠLÐ<Ñ=Ô=Ð=ØˆIð Ô'×3Ò3°EÑ:Ô:ˆ	à9ˆdÔ9ð 
Ø 1¨E¸Àgð
ð 
ØQWð
ð 
ˆð ˆ
rL   rÐ   úList[float]c                óÖ  ‡— | j         €t                               d¦  «         g S | j        dd…         }|                     | j        ¦  «         t                               d| j        › �¦  «         t                               d|g› �¦  «         t                               d|› �¦  «         t                               d|› �¦  «         t                               d|› �¦  «         | j                              | j        |g|||¬¦  «        Št                               d	‰› �¦  «         | j        d
z   }g }	d}
t          ˆfd„|D ¦   «         Ž D ]ž}d„ t          ||¦  «        D ¦   «         }t          | 
                    | j        ¦  «        |¬¦  «        }t                               d‰d         |         › �¦  «         ‰d         |         |
         }|
dz  }
|	                     ||f¦  «         ŒŸ|	S )aÀ  
        Performs a search on the query string and returns results with scores.

        Args:
            embedding (List[float]): The embedding vector being searched.
            k (int, optional): The number of results to return.
            Default is 4.
            param (dict): Specifies the search parameters for the index.
            Default is None.
            expr (str, optional): Filtering expression. Default is None.
            timeout (int, optional): The waiting time before a timeout error.
            Default is None.
            kwargs: Keyword arguments for Collection.search().

        Returns:
            List[Tuple[Document, float]]: Resulting documents and scores.
        NrÈ   zsearch_field:zvectors:zoutput_fields:ztopk:zdsl:)Úsearch_fieldr»   Úoutput_fieldsÚtopkÚdslz-[similarity_search_with_score_by_vector] res:z%scoresr   c                ó,   •— g | ]}‰d          |         ‘ŒS )r   rH   )rI   Úfieldr¾   s     €r?   rK   z@Hippo.similarity_search_with_score_by_vector.<locals>.<listcomp>f  s!   ø€ ÐDÐDÐD¨U˜3˜qœ6 %œ=ÐDÐDÐDrL   c                ó   — i | ]\  }}||“Œ	S rH   rH   )rI   rÚ   ru   s      r?   ú
<dictcomp>z@Hippo.similarity_search_with_score_by_vector.<locals>.<dictcomp>g  s   € ÐOÐOÐO¡\ U¨E�E˜5ÐOÐOÐOrL   )Úpage_contentÚmetadataz;[similarity_search_with_score_by_vector] res[0][score_col]:r   )r5   rU   rl   r1   r¶   r0   rÁ   r/   Úzipr   Úpoprm   )r=   rÐ   rÂ   rÃ   rÄ   r¢   r¥   rÖ   Ú	score_colrÒ   Úcountrp   ÚmetarÊ   Úscorer¾   s                  @r?   rÑ   z,Hippo.similarity_search_with_score_by_vector.  s  ø€ ð4 Œ8ÐÝ�LŠLÐ<Ñ=Ô=Ð=ØˆIð œ A A AœˆØ×Ò˜TÔ/Ñ0Ô0Ð0õ 	�ŠÐ9 TÔ%7Ð9Ð9Ñ:Ô:Ð:Ý�ŠÐ-  Ð-Ð-Ñ.Ô.Ð.Ý�ŠÐ5 mÐ5Ð5Ñ6Ô6Ð6Ý�Š�[˜Q�[�[Ñ!Ô!Ð!Ý�Š�]˜D�]�]Ñ#Ô#Ð#àŒh�nŠnØÔ+Ø�KØ'ØØð ñ 
ô 
ˆõ 	�ŠÐJÀSÐJÐJÑKÔKÐKØÔ$ yÑ0ˆ	ØˆØˆÝÐDÐDÐDÐD°mÐDÑDÔDÐEð 		%ð 		%ˆEØOÐOµS¸ÈÑ5NÔ5NÐOÑOÔOˆDÝ¨¯ª°Ô1AÑ(BÔ(BÈTÐRÑRÔRˆCÝ�LŠLð9Ø%(¨¤V¨IÔ%6ð9ð 9ñô ð ð ˜”F˜9Ô% eÔ,ˆEØ�Q‰JˆEØ�JŠJ˜˜U�|Ñ$Ô$Ð$Ð$àˆ
rL   úDict[str, Any]úOptional[Dict[Any, Any]]Úsearch_paramsÚboolú'Hippo'c
           
     ó  — |€i }t                                d¦  «          | d||||||	dœ|
¤Ž}t                                d|› �¦  «         t                                d|› �¦  «         |                     ||¬¦  «         |S )a´  
        Creates an instance of the VST class from the given texts.

        Args:
            texts (List[str]): List of texts to be added.
            embedding (Embeddings): Embedding model for the texts.
            metadatas (List[dict], optional):
            List of metadata dictionaries for each text.Defaults to None.
            table_name (str): Name of the table. Defaults to "test".
            database_name (str): Name of the database. Defaults to "default".
            connection_args (dict[str, Any]): Connection parameters.
            Defaults to DEFAULT_HIPPO_CONNECTION.
            index_params (dict): Indexing parameters. Defaults to None.
            search_params (dict): Search parameters. Defaults to an empty dictionary.
            drop_old (bool): Whether to drop the old collection. Defaults to False.
            kwargs: Other arguments.

        Returns:
            Hippo: An instance of the VST class.
        Nz'00 [from_texts] init the class of Hippo)r   r   r   r#   r%   r'   z[from_texts] texts:z[from_texts] metadatas:)r    r[   rH   )rU   rV   rl   r¿   )Úclsr    rÐ   r[   r   r   r#   r%   rç   r'   r¥   Ú	vector_dbs               r?   Ú
from_textszHippo.from_textss  s±   € ðF Ð ØˆMÝ�ŠÐ=Ñ>Ô>Ð>Ø�Cð 
Ø(Ø!Ø'Ø+Ø%Øð
ð 
ð ð
ð 
ˆ	õ 	�ŠÐ2¨5Ð2Ð2Ñ3Ô3Ð3Ý�ŠÐ:¨yÐ:Ð:Ñ;Ô;Ð;Ø×Ò %°9ÐÑ=Ô=Ð=ØÐrL   )r   r   r   r   NNF)r   r   r   r   r   r   r    r!   r"   r!   r#   r$   r%   r&   r'   r(   )r#   rA   rB   r   )NN)rY   rZ   r[   r\   rB   r]   )N)rY   rb   r[   r\   rB   r]   )rB   r]   )rB   r$   )NNrŸ   )r    r¡   r[   r\   r¢   r£   r¤   r!   r¥   r   rB   r¦   )rÀ   NNN)rÁ   r   rÂ   r!   rÃ   r&   rÄ   rÅ   r¢   r£   r¥   r   rB   rÆ   )rÁ   r   rÂ   r!   rÃ   r&   rÄ   rÅ   r¢   r£   r¥   r   rB   rÎ   )rÐ   rÓ   rÂ   r!   rÃ   r&   rÄ   rÅ   r¢   r£   r¥   r   rB   rÎ   )r    r¦   rÐ   r   r[   r\   r   r   r   r   r#   rå   r%   ræ   rç   r$   r'   rè   r¥   r   rB   ré   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r@   r3   r<   r_   r`   r�   ra   r¿   rÍ   rÌ   rÑ   Úclassmethodr2   rí   rH   rL   r?   r   r      sÎ  € € € € € ð5ð 5ðt !Ø&Ø !Ø"#Ø48Ø'+Ø#(ð7ð 7ð 7ð 7ð 7ðrð ð ð ðD TXðð ð ð ð ð CGð?
ð ?
ð ?
ð ?
ð ?
ðB	Gð 	Gð 	Gð 	Gðð ð ð ð*rð rð rð rðn +/Ø!%ØðVð Vð Vð Vð Vðv Ø $Ø"Ø!%ð 'ð  'ð  'ð  'ð  'ðJ Ø $Ø"Ø!%ð%ð %ð %ð %ð %ðT Ø $Ø"Ø!%ðCð Cð Cð Cð CðJ ð
 +/Ø Ø&Ø*BØ15Ø26Øð1ð 1ð 1ð 1ñ „[ð1ð 1ð 1rL   r   )Ú
__future__r   r9   Útypingr   r   r   r   r   r	   r
   Úlangchain_core.documentsr   Úlangchain_core.embeddingsr   Úlangchain_core.vectorstoresr   rO   r   r2   Ú	getLoggerrî   rU   r   rH   rL   r?   ú<module>rù      s  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ Là -Ð -Ð -Ð -Ð -Ð -Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3àð =Ø<Ð<Ð<Ð<Ð<Ð<ð ØØØð	ð Ð ð 
ˆÔ	˜8Ñ	$Ô	$€ðM
ð M
ð M
ð M
ð M
ˆKñ M
ô M
ð M
ð M
ð M
rL   