Ë
    µŒjá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y)é    )Ú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	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Z	 d	 	 	 	 	 dd„Z	 d	 	 	 	 	 dd	„Zdd
„Zdd„Z	dd„Z
	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d d„Zedddedddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d„«       Zy)"Ú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ÚdefaultNFc	                óh  — || _         || _        || _        || _        || _        || _        d| _        d| _        d| _        g | _	        |€t        }| j                  |«      | _        d | _        	 | j                  j                  | j                  | j                  «      r2|r0| j                  j                  | j                  | j                  «       	 | j                  j                  | j                  | j                  «      r5| j                  j'                  | j                  | j                  «      | _        | j)                  «        y # t         $ r+}	t#        j$                  d| j                  › d|	› �«       ‚ d }	~	ww xY w# t         $ r+}	t#        j$                  d| j                  › d|	› �«       ‚ d }	~	ww xY w)NÚpkÚtextÚvectorz+An error occurred while deleting the table z: z*An error occurred while getting the table )Únumber_of_shardsÚnumber_of_replicasÚembedding_funcÚ
table_nameÚdatabase_nameÚindex_paramsÚ_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)
ÚselfÚembedding_functionr"   r#   r   r    Úconnection_argsr$   Údrop_oldÚes
             úp/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/vectorstores/hippo.pyÚ__init__zHippo.__init__P   s~  € ð !1ˆÔØ"4ˆÔØ0ˆÔØ$ˆŒØ*ˆÔØ(ˆÔð #ˆÔà!ˆÔà%ˆÔØ!#ˆŒàÐ"Ü6ˆOØ×/Ñ/°Ó@ˆŒØˆŒð
	à—‘×*Ñ*¨4¯?©?¸D×<NÑ<NÔOÙà—‘×$Ñ$ T§_¡_°d×6HÑ6HÔIð	Ø�w‰w×)Ñ)¨$¯/©/¸4×;MÑ;MÔNØŸ7™7×,Ñ,¨T¯_©_¸d×>PÑ>PÓQ�”ð 	�‰�øô! ò 	Ü�M‰MØ=¸d¿o¹oÐ=NÈbÐQRÐPSÐTôð ûð		ûô ò 	Ü�M‰MØ<¸T¿_¹_Ð<MÈRÐPQÈsÐSôð ûð		ús2   Á-A"E ÃA%E= Å	E:Å&E5Å5E:Å=	F1Æ&F,Æ,F1c                óH  — 	 ddl m} |j                  dd«      }|j                  dd«      }|j                  dd«      }|j                  d	d«      }|�W|�Ud
|v r6|j	                  d
«      }d
j                  |D �	cg c]	  }	|	› d|› �‘Œ c}	«      }
n&t        |«      dz   t        |«      z   }
nt        d«      ‚	 t        j                  d|
› d�«        ||
g||¬«      S # t        $ r}t        d«      |‚d}~ww xY wc c}	w # t        $ r}t        j                  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   Ú,Ú: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ÚjoinÚstrÚ
ValueErrorÚloggerÚinfor/   r1   )r4   r6   r   r8   r   r   r   r   ÚhostsÚhÚgiven_addresss              r9   r*   zHippo._create_connection_alias‰   s<  € ð	ÝDð .×1Ñ1°&¸$Ó?ˆØ-×1Ñ1°&¸$Ó?ˆØ'×+Ñ+¨J¸Ó@ˆØ'×+Ñ+¨J¸Ó@ˆð Ð Ð 0Ø�d‰{ØŸ
™
 3›�Ø #§¡ÁÓ)GÁ¸A¨Q¨C¨q°°ª-ÀÑ)GÓ H‘ä # D£	¨C¡´#°d³)Ñ ;‘äÐNÓOÐOð	Ü�K‰KÐ-¨m¨_¸AÐ>Ô?Ù ˜¸ÀxÔPÐPøô/ ò 	Üð+óð ðûð	üò *Høô ò 	Ü�L‰LÐ:Ô;ØˆGûð	ús5   ‚C Á8C7Â5$C< Ã	C4Ã#C/Ã/C4Ã<	D!ÄDÄD!c                óÀ   — t         j                  d«       |�'t         j                  d«       | j                  ||«       | j                  «        | j	                  «        y )Nzinit ...zcreate collection)rH   rI   Ú_create_collectionÚ_extract_fieldsÚ_create_index)r4   Ú
embeddingsÚ	metadatass      r9   r3   zHippo._get_envª   sK   € ô 	�‰�JÔØÐ!Ü�K‰KÐ+Ô,Ø×#Ñ# J°	Ô:Ø×ÑÔØ×ÑÕó    c           
     ó  — ddl m} ddlm} t	        |d   «      }t
        j                  d|› �«       g }|j                   || j                  d|j                  «      «       |j                   || j                  d|j                  «      «       |j                   || j                  d|j                  d|i¬«      «       |r�|d   j                  «       D ]k  \  }}t        |t        «      r3t	        |«      }	|j                   ||d|j                  d|	i¬«      «       ŒI|j                   ||d|j                  «      «       Œm t
        j                  d	|› �«       | j                   j#                  | j$                  d|| j&                  | j(                  | j*                  ¬
«       | j                   j-                  | j$                  | j&                  «      | _        t
        j1                  d| j$                  › d| j&                  › d�«       y )Nr   )Ú
HippoField)Ú	HippoTypez[_create_collection] dim: TFÚ	dimension)Útype_paramsz[_create_collection] fields: )ÚnameÚauto_idr(   r#   r   r    z$[_create_collection] : create table z in z successfully)rA   rU   Útranswarp_hippo_api.hippo_typerV   ÚlenrH   ÚdebugÚappendr%   ÚSTRINGr&   r'   ÚFLOAT_VECTORÚitemsÚ
isinstanceÚlistr+   Úcreate_tabler"   r#   r   r    r2   r,   rI   )
r4   rQ   rR   rU   rV   Údimr(   ÚkeyÚvalueÚ	value_dims
             r9   rN   zHippo._create_collection´   sÓ  € õ 	@Ý<ô �*˜Q‘-Ó ˆÜ�‰Ð1°#°Ð7Ô8Øˆð 	�‰‘j ×!4Ñ!4°d¸I×<LÑ<LÓMÔNð 	�‰‘j ×!1Ñ!1°5¸)×:JÑ:JÓKÔLð 	�‰ÙØ×"Ñ"ØØ×&Ñ&Ø(¨#Ð.ô	ô	
ñ à'¨™l×0Ñ0Ö2‘
��Uä˜e¤TÔ*Ü # E£
�IØ—M‘MÙ"ØØ!Ø%×2Ñ2Ø)4°iÐ(@ô	õð —M‘M¡*¨S°%¸×9IÑ9IÓ"JÕKð 3ô 	�‰Ð4°V°HÐ=Ô>ð 	�‰×ÑØ—‘ØØØ×,Ñ,Ø!×2Ñ2Ø#×6Ñ6ð 	ô 	
ð —7‘7×$Ñ$ T§_¡_°d×6HÑ6HÓIˆŒÜ�‰ðØ ŸO™OÐ,¨D°×1CÑ1CÐ0DÀMðSõ	
rS   c                ó6  — ddl m} t        | j                  |«      r}| j                  j                  }t
        j                  d|› �«       |D ]'  }| j                  j                  |j                  «       Œ) t
        j                  d| j                  › �«       yy)z,Grab the existing fields from the Collectionr   ©Ú
HippoTablez[_extract_fields] schema:z04 [_extract_fields] fields:N)
rA   rk   rb   r,   ÚschemarH   r]   r(   r^   rY   )r4   rk   rl   Úxs       r9   rO   zHippo._extract_fieldsõ   sq   € å?ä�d—h‘h 
Ô+Ø—X‘X—_‘_ˆFÜ�L‰LÐ4°V°HÐ=Ô>Û�Ø—‘×"Ñ" 1§6¡6Õ*ð ä�L‰LÐ7¸¿¹°}ÐEÕFð ,rS   c                óà  — ddl m} t        | j                  |«      rÒ| j                  j                  | j                  | j                  «      j                  | j                  i «      }|j                  dd«      }|€y| j                  j                  | j                  | j                  «      | j                     d   D ]0  }t        j                  d|› �«       |d   | j                  k(  sŒ.|c S  y)z0Return the vector index information if it existsr   rj   Úembedding_indexesNz[_get_index] embedding_indexes Úcolumn)rA   rk   rb   r,   r+   Úget_table_infor"   r#   rC   rH   r]   r'   )r4   rk   Ú
table_inforo   rm   s        r9   Ú
_get_indexzHippo._get_index  sÓ   € å?ä�d—h‘h 
Ô+ØŸ™×/Ñ/Ø—‘ ×!3Ñ!3óç‰c�$—/‘/ 2Ó&ð ð !+§¡Ð/BÀDÓ IÐØ Ð(ØàŸ™×/Ñ/°·±À×ASÑASÓTØ—O‘Oñà%ô'�Aô —L‘LÐ#BÐCTÐBUÐ!VÔWØ˜‘{ d×&8Ñ&8Ó8Ø šð'ð rS   c                ó\  — ddl m} ddlm}m} t        | j                  |«      �r‡| j                  «       �€u| j                  «       �€c| j                  €Ïd|j                  |j                  ddœ| _        | j                  j                  | j                  | j                  d   | j                  d	   | j                  d
   | j                  d   ¬«       t        j                  | j                  j                  | j                  d   «      «       t        j!                  d«       y|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                  | j                  d   | j                  d	   | j                  d
   «       t        j                  | j                  j                  | j                  d   «      «       y| j                  d	   dk(  s| j                  d	   dk(  rá|| j                  d	      | j                  d	<   | j                  j                  | j                  | j                  d   | j                  d	   | j                  d
   | j                  j-                  dd«      | j                  j-                  dd«      ¬«       t        j                  | j                  j                  | j                  d   «      «       y| j                  d	   dk(  �r|| j                  d	      | j                  d	<   | j                  j                  | j                  | j                  d   | j                  d	   | j                  d
   | j                  j-                  dd«      | j                  j-                  dd«      | j                  j-                  dd«      | j                  j-                  d«      ¬«       t        j                  | j                  j                  | j                  d   «      «       y| j                  d	   dk(  rù|| j                  d	      | j                  d	<   | j                  j                  | j                  | j                  d   | j                  d	   | j                  d
   | j                  j-                  d«      | j                  j-                  d«      | j                  j-                  d«      ¬«       t        j                  | j                  j                  | j                  d   «      «       yt/        d«      ‚yyy) z Create a index on the collectionr   rj   )Ú	IndexTypeÚ
MetricTypeNÚlangchain_auto_createé
   )Ú
index_nameÚmetric_typeÚ
index_typeÚnlistry   r{   rz   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))rA   rk   r[   ru   rv   rb   r,   rs   r$   r…   r}   Úcreate_indexr'   rH   r]   Úactivate_indexrI   r~   r   r€   r�   rƒ   rC   rG   )r4   rk   ru   rv   Ú
index_dictÚmetric_dicts         r9   rP   zHippo._create_index  s  € å?ßHä�d—h‘h 
Õ+°·±Ó0AÑ0IØ�‰Ó Ñ(Ø×$Ñ$Ð,à&=Ø'1§}¡}Ø&/×&8Ñ&8Ø!#ñ	)�DÔ%ð —H‘H×)Ñ)Ø×*Ñ*Ø×)Ñ)¨,Ñ7Ø×)Ñ)¨,Ñ7Ø×)Ñ)¨-Ñ8Ø"×/Ñ/°Ñ8ð *ô ô —L‘LØŸ™×/Ñ/°×0AÑ0AÀ,Ñ0OÓPôô —K‘KÐ ;Õ<ð %.×$6Ñ$6Ø )§¡Ø"+×"2Ñ"2Ø"+×"2Ñ"2Ø )§¡ñ"�Jð )Ÿm™mØ(Ÿm™mØ(Ÿm™mØ(Ÿm™mñ	#�Kð 8CØ×)Ñ)¨-Ñ8ñ8�D×%Ñ% mÑ4ð ×(Ñ(¨Ñ6¸&Ò@Ø:DØ ×-Ñ-¨lÑ;ñ;˜×)Ñ)¨,Ñ7ð Ÿ™×-Ñ-Ø ×.Ñ.Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨mÑ<ô	ô Ÿ™Ø ŸH™H×3Ñ3°D×4EÑ4EÀlÑ4SÓTõð ×)Ñ)¨,Ñ7¸:ÒEØ×,Ñ,¨\Ñ:¸hÒFà:DØ ×-Ñ-¨lÑ;ñ;˜×)Ñ)¨,Ñ7ð Ÿ™×-Ñ-Ø ×.Ñ.Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨mÑ<Ø"&×"3Ñ"3×"7Ñ"7¸ÀÓ"DØ#'×#4Ñ#4×#8Ñ#8¸À2Ó#Fð .ô ô Ÿ™Ø ŸH™H×3Ñ3°D×4EÑ4EÀlÑ4SÓTõð ×*Ñ*¨<Ñ8¸HÓDØ:DØ ×-Ñ-¨lÑ;ñ;˜×)Ñ)¨,Ñ7ð Ÿ™×-Ñ-Ø ×.Ñ.Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨mÑ<Ø"&×"3Ñ"3×"7Ñ"7¸ÀÓ"DØ#'×#4Ñ#4×#8Ñ#8¸À2Ó#FØ"&×"3Ñ"3×"7Ñ"7¸ÀÓ"CØ"×/Ñ/×3Ñ3°CÓ8ð .ô 	ô Ÿ™Ø ŸH™H×3Ñ3°D×4EÑ4EÀlÑ4SÓTõð ×*Ñ*¨<Ñ8¸FÒBØ:DØ ×-Ñ-¨lÑ;ñ;˜×)Ñ)¨,Ñ7ð Ÿ™×-Ñ-Ø ×.Ñ.Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨lÑ;Ø ×-Ñ-¨mÑ<Ø"×/Ñ/×3Ñ3°CÓ8Ø,0×,=Ñ,=×,AÑ,AÐBSÓ,TØ&*×&7Ñ&7×&;Ñ&;¸KÓ&Hð .ô ô Ÿ™Ø ŸH™H×3Ñ3°D×4EÑ4EÀlÑ4SÓTõô )ðDóð ðQ )ð 1JÐ+rS   c                óÊ  — ddl m} |rt        d„ |D «       «      rt        j	                  d«       g S t        |«      }t        j	                  d|› �«       	 | j                  j                  |«      }t        |«      dk(  rt        j	                  d«       g S t        j	                  dt        |«      › �«       t        | j                  |«      s| j                  ||«       | j                  || j                  |i}	t        j	                  d|› �«       t        j	                  d| j                   › �«       |�O|D ]J  }
|
j#                  «       D ]5  \  }}|| j                   v sŒ|	j%                  |g «      j'                  |«       Œ7 ŒL t        j	                  |	| j                     «       |	| j                     }t        |«      }d
| j                   v r| j                   j)                  d
«       t        j	                  d|› �«       t+        d||«      D ]d  }t-        ||z   |«      }| j                   D �cg c]
  }|	|   || ‘Œ }}	 | j                  j/                  |«      }t        j1                  d|› �«       Œf dgS # t        $ r2 |D �cg c]  }| j                  j                  |«      ‘Œ nc c}w }}Y �ŒAw xY wc c}w # t2        $ r}t        j5                  d||«       |‚d	}~ww xY w)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   rj   c              3  ó&   K  — | ]	  }|d k(  –— Œ y­w)Ú N© )Ú.0Úts     r9   Ú	<genexpr>z"Hippo.add_texts.<locals>.<genexpr>©  s   è ø€ Ð3©U¨˜A �G©Uùs   ‚zNothing to insert, skipping.z[add_texts] texts: z[add_texts] len_embeddings:z[add_texts] metadatas:z[add_texts] fields:Nr   z[add_texts] total_count:z05 [add_texts] insert z0Failed to insert batch starting at entity: %s/%sr“   )rA   rk   ÚallrH   r]   rc   r!   Úembed_documentsÚNotImplementedErrorÚembed_queryr\   rb   r,   r3   r&   r'   r(   ra   Ú
setdefaultr^   ÚremoveÚrangeÚminÚinsert_rowsrI   r/   r1   )r4   ÚtextsrR   ÚtimeoutÚ
batch_sizeÚkwargsrk   rQ   rm   Úinsert_dictÚdrf   rg   ÚvectorsÚtotal_countÚiÚendÚinsert_listÚresr8   s                       r9   Ú	add_textszHippo.add_texts�  s¢  € õ4 	@áœÑ3©UÓ3Ô3Ü�L‰LÐ7Ô8ØˆIÜ�U“ˆä�‰Ð*¨5¨'Ð2Ô3ð	MØ×,Ñ,×<Ñ<¸UÓCˆJô ˆz‹?˜aÒÜ�L‰LÐ7Ô8ØˆIä�‰Ð2´3°z³?Ð2CÐDÔEô ˜$Ÿ(™( JÔ/Ø�M‰M˜* iÔ0ð ×Ñ˜eØ×Ñ 
ð(
ˆô 	�‰Ð-¨i¨[Ð9Ô:Ü�‰Ð*¨4¯;©;¨-Ð8Ô9ØÐ Û�Ø"#§'¡'¦)‘J�C˜Ø˜dŸk™kÒ)Ø#×.Ñ.¨s°BÓ7×>Ñ>¸uÕEñ #,ð ô
 	�‰�[ ×!1Ñ!1Ñ2Ô3ð $ D×$6Ñ$6Ñ7ˆÜ˜'“lˆà�4—;‘;ÑØ�K‰K×Ñ˜tÔ$ä�‰Ð/°¨}Ð=Ô>Ü�q˜+ zÖ2ˆAä�a˜*‘n kÓ2ˆCà:>¿+º+ÓF¹+°Q˜; q™>¨!¨CÒ0¸+ˆKÐFðØ—h‘h×*Ñ*¨;Ó7�Ü—‘Ð4°S°EÐ:Õ;ð 3ð ˆtˆøôc #ò 	MÙFKÓLÁeÀ˜$×-Ñ-×9Ñ9¸!Õ<ÁeùÒLˆJÓLð	MüòP Gøô ò Ü—‘ØFÈÈ;ôð �ûð	ús<   ÁI8 È.J6É 3J;É8J3Ê"J(Ê'J3Ê2J3Ê;	K"ËKËK"c           	     ó®   — | j                   €t        j                  d«       g S  | j                  d|||||dœ|¤Ž}|D ��	cg c]  \  }}	|‘Œ	 c}	}S c c}	}w )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.
        ú!No existing collection to search.)ÚqueryÚkÚparamÚexprr¢   r”   )r,   rH   r]   Úsimilarity_search_with_score)
r4   r°   r±   r²   r³   r¢   r¤   r¬   ÚdocÚ_s
             r9   Úsimilarity_searchzHippo.similarity_searchå  sh   € ð4 �8‰8ÐÜ�L‰LÐ<Ô=ØˆIØ/ˆd×/Ñ/ð 
Ø˜1 E°¸gñ
ØIOñ
ˆñ #&Ô&¡#™˜˜Q’ #Ò&Ð&ùÓ&s   ÁAc           	     ó²   — | j                   €t        j                  d«       g S | j                  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]]:
        r¯   )Ú	embeddingr±   r²   r³   r¢   r”   )r,   rH   r]   r!   r›   Ú&similarity_search_with_score_by_vector)	r4   r°   r±   r²   r³   r¢   r¤   r¹   Úrets	            r9   r´   z"Hippo.similarity_search_with_score  si   € ð6 �8‰8ÐÜ�L‰LÐ<Ô=ØˆIð ×'Ñ'×3Ñ3°EÓ:ˆ	à9ˆd×9Ñ9ð 
Ø 1¨E¸Àgñ
ØQWñ
ˆð ˆ
rS   c                ó¶  — | j                   €t        j                  d«       g S | j                  dd }|j	                  | j
                  «       t        j                  d| j
                  › �«       t        j                  d|g› �«       t        j                  d|› �«       t        j                  d|› �«       t        j                  d|› �«       | j                   j                  | j
                  |g|||¬«      }t        j                  d	|› �«       | j                  d
z   }	g }
d}t        |D �cg c]
  }|d   |   ‘Œ c}Ž D ]ˆ  }t        ||«      D ��ci c]  \  }}||“Œ
 }}}t        |j                  | j                  «      |¬«      }t        j                  d|d   |	   › �«       |d   |	   |   }|dz  }|
j                  ||f«       ŒŠ |
S c c}w c c}}w )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   )Úpage_contentÚmetadataz;[similarity_search_with_score_by_vector] res[0][score_col]:é   )r,   rH   r]   r(   r�   r'   r°   r&   Úzipr   Úpopr^   )r4   r¹   r±   r²   r³   r¢   r¤   r¾   r¬   Ú	score_colr»   ÚcountÚfieldra   rg   Úmetarµ   Úscores                     r9   rº   z,Hippo.similarity_search_with_score_by_vector.  sÓ  € ð4 �8‰8ÐÜ�L‰LÐ<Ô=ØˆIð Ÿ™¡A˜ˆØ×Ñ˜T×/Ñ/Ô0ô 	�‰�} T×%7Ñ%7Ð$8Ð9Ô:Ü�‰�x  ˜}Ð-Ô.Ü�‰�~ m _Ð5Ô6Ü�‰�u˜Q˜C�[Ô!Ü�‰�t˜D˜6�]Ô#à�h‰h�n‰nØ×+Ñ+Ø�KØ'ØØð ó 
ˆô 	�‰ÐDÀSÀEÐJÔKØ×$Ñ$ yÑ0ˆ	ØˆØˆÜ±mÓD±m¨U˜3˜q™6 %›=°mÑDÓEˆEÜ58¸ÈÔ5NÔOÑ5N¡\ U¨E�E˜5‘LÐ5NˆDÑOÜ¨¯©°×1AÑ1AÓ(BÈTÔRˆCÜ�L‰Lð%Ø%(¨¡V¨IÑ%6Ð$7ð9ôð ˜‘F˜9Ñ% eÑ,ˆEØ�Q‰JˆEØ�J‰J˜˜U�|Õ$ð Fð ˆ
ùò EùÛOs   Ä0GÅGc
           
     óÜ   — |€i }t         j                  d«        | d||||||	dœ|
¤Ž}t         j                  d|› �«       t         j                  d|› �«       |j                  ||¬«       |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.
        z'00 [from_texts] init the class of Hippo)r5   r"   r#   r6   r$   r7   z[from_texts] texts:z[from_texts] metadatas:)r¡   rR   r”   )rH   rI   r]   r­   )Úclsr¡   r¹   rR   r"   r#   r6   r$   Úsearch_paramsr7   r¤   Ú	vector_dbs               r9   Ú
from_textszHippo.from_textss  s‹   € ðF Ð ØˆMÜ�‰Ð=Ô>Ùð 
Ø(Ø!Ø'Ø+Ø%Øñ
ð ñ
ˆ	ô 	�‰Ð*¨5¨'Ð2Ô3Ü�‰Ð.¨y¨kÐ:Ô;Ø×Ñ %°9ÐÔ=ØÐrS   )r   r   rÃ   rÃ   NNF)r5   r   r"   rF   r#   rF   r   Úintr    rÐ   r6   úOptional[Dict[str, Any]]r$   úOptional[dict]r7   zOptional[bool])r6   ÚdictÚreturnr   )NN)rQ   zOptional[list]rR   úOptional[List[dict]]rÔ   ÚNone)N)rQ   rc   rR   rÕ   rÔ   rÖ   )rÔ   rÖ   )rÔ   rÑ   )NNiè  )r¡   zIterable[str]rR   rÕ   r¢   úOptional[int]r£   rÐ   r¤   r   rÔ   ú	List[str])é   NNN)r°   rF   r±   rÐ   r²   rÒ   r³   úOptional[str]r¢   r×   r¤   r   rÔ   zList[Document])r°   rF   r±   rÐ   r²   rÒ   r³   rÚ   r¢   r×   r¤   r   rÔ   úList[Tuple[Document, float]])r¹   zList[float]r±   rÐ   r²   rÒ   r³   rÚ   r¢   r×   r¤   r   rÔ   rÛ   )r¡   rØ   r¹   r   rR   rÕ   r"   rF   r#   rF   r6   zDict[str, Any]r$   zOptional[Dict[Any, Any]]rÍ   rÑ   r7   Úboolr¤   r   rÔ   z'Hippo')Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   r*   r3   rN   rO   rs   rP   r­   r·   r´   rº   Úclassmethodr)   rÏ   r”   rS   r9   r   r      sÍ  „ ñ5ðt !Ø&Ø !Ø"#Ø48Ø'+Ø#(ð7à&ð7ð ð7ð ð	7ð
 ð7ð  ð7ð 2ð7ð %ð7ð !ó7órðD TXðØ(ðØ<Pðà	óð CGð?
Øð?
Ø+?ð?
à	ó?
óB	Góó*rðn +/Ø!%ØðVàðVð (ðVð ð	Vð
 ðVð ðVð 
óVðv Ø $Ø"Ø!%ð 'àð 'ð ð 'ð ð	 'ð
 ð 'ð ð 'ð ð 'ð 
ó 'ðJ Ø $Ø"Ø!%ð%àð%ð ð%ð ð	%ð
 ð%ð ð%ð ð%ð 
&ó%ðT Ø $Ø"Ø!%ðCàðCð ðCð ð	Cð
 ðCð ðCð ðCð 
&óCðJ ð
 +/Ø Ø&Ø*BØ15Ø26Øð1àð1ð ð1ð (ð	1ð
 ð1ð ð1ð (ð1ð /ð1ð 0ð1ð ð1ð ð1ð 
ò1ó ñ1rS   r   )Ú
__future__r   r0   Útypingr   r   r   r   r   r	   r
   Úlangchain_core.documentsr   Úlangchain_core.embeddingsr   Úlangchain_core.vectorstoresr   rA   r   r)   Ú	getLoggerrÝ   rH   r   r”   rS   r9   Ú<module>rè      s[   ðÝ "ã ß L× LÑ Lå -Ý 0Ý 3áÝ<ð ØØØñ	Ð ð 
ˆ×	Ñ	˜8Ó	$€ôM
ˆKõ M
rS   