Ë
    µŒjÜc  ã                  óÞ   — d Z 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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 ddlmZ  ej0                  e«      Z G d	„ d
e«      ZdZ G d„ d«      Zy)z,Module providing Infinispan as a VectorStoreé    )ÚannotationsN)ÚAnyÚIterableÚListÚOptionalÚTupleÚTypeÚUnionÚcast)ÚResponse)ÚDocument)Ú
Embeddings)ÚVectorStorec                  ód  — e Zd ZdZ	 	 d	 	 	 	 	 dd„Zdd„Zdd„Zdd„Zdd„Zdd„Z	dd d	„Z
dd
„Z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	 d#	 	 	 	 	 d'd„Z	 	 	 	 d(d„Zd)d„Zd*d„Ze	 	 	 	 d+	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,d„«       Zy)-ÚInfinispanVSaè  `Infinispan` VectorStore interface.

        This class exposes the method to present Infinispan as a
        VectorStore. It relies on the Infinispan class (below) which takes care
        of the REST interface with the server.

    Example:
        ... code-block:: python
            from langchain_community.vectorstores import InfinispanVS
            from mymodels import RGBEmbeddings
            ...
            vectorDb = InfinispanVS.from_documents(docs,
                            embedding=RGBEmbeddings(),
                            output_fields=["texture", "color"],
                            lambda_key=lambda text,meta: str(meta["_key"]),
                            lambda_content=lambda item: item["color"])

        or an empty InfinispanVS instance can be created if preliminary setup
        is required before populating the store

        ... code-block:: python
            from langchain_community.vectorstores import InfinispanVS
            from mymodels import RGBEmbeddings
            ...
            ispnVS = InfinispanVS()
            # configure Infinispan here
            # i.e. create cache and schema

            # then populate the store
            vectorDb = InfinispanVS.from_documents(docs,
                            embedding=RGBEmbeddings(),
                            output_fields: ["texture", "color"],
                            lambda_key: lambda text,meta: str(meta["_key"]),
                            lambda_content: lambda item: item["color"])
    Nc                óx  ‡ — t        di |¤Ž‰ _        |‰ _        t        ‰ j                  j	                  dd«      «      ‰ _        t        ‰ j                  j	                  dd«      «      ‰ _        |‰ _        ‰ j                  j	                  dd«      ‰ _        ‰ j                  dk(  r"‰ j                  j	                  dd«      ‰ _        nt        j                  dt        «       ‰ j                  j	                  d	d«      ‰ _        ‰ j                  dk(  r"‰ j                  j	                  d
d«      ‰ _        nt        j                  dt        «       ‰ j                  j	                  dˆ fd„«      ‰ _        ‰ j                  j	                  dˆ fd„«      ‰ _        ‰ j                  j	                  d«      ‰ _        |‰ _        y)at  
        Parameters
        ----------
        cache_name: str
            Embeddings cache name. Default "vector"
        entity_name: str
            Protobuf entity name for the embeddings. Default "vector"
        text_field: str
            Protobuf field name for text. Default "text"
        vector_field: str
            Protobuf field name for vector. Default "vector"
        lambda_content: lambda
            Lambda returning the content part of an item. Default returns text_field
        lambda_metadata: lambda
            Lambda returning the metadata part of an item. Default returns items
            fields excepts text_field, vector_field, _type
        output_fields: List[str]
            List of fields to be returned from item, if None return all fields.
            Default None
        kwargs: Any
            Rest of arguments passed to Infinispan. See docsÚ
cache_nameÚvectorÚentity_nameÚ	textfieldÚ Ú
text_fieldÚtextz9`textfield` is deprecated. Please use `text_field` param.ÚvectorfieldÚvector_fieldz=`vectorfield` is deprecated. Please use `vector_field` param.Úlambda_contentc                ó&   •— ‰j                  | «      S ©N)Ú_default_content©ÚitemÚselfs    €úw/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/vectorstores/infinispanvs.pyÚ<lambda>z'InfinispanVS.__init__.<locals>.<lambda>i   s   ø€ ¨4×+@Ñ+@ÀÔ+Fó    Úlambda_metadatac                ó&   •— ‰j                  | «      S r   )Ú_default_metadatar    s    €r#   r$   z'InfinispanVS.__init__.<locals>.<lambda>l   s   ø€ ¨D×,BÑ,BÀ4Ô,Hr%   Úoutput_fieldsN© )Ú
InfinispanÚispnÚ_configurationÚstrÚgetÚ_cache_nameÚ_entity_nameÚ
_embeddingÚ
_textfieldÚwarningsÚwarnÚDeprecationWarningÚ_vectorfieldÚ_to_contentÚ_to_metadataÚ_output_fieldsÚ_ids)r"   Ú	embeddingÚidsÚkwargss   `   r#   Ú__init__zInfinispanVS.__init__8   sq  ø€ ô6 Ñ( Ñ(ˆŒ	Ø$ˆÔÜ˜t×2Ñ2×6Ñ6°|ÀXÓNÓOˆÔÜ × 3Ñ 3× 7Ñ 7¸ÀxÓ PÓQˆÔØ#ˆŒØ×-Ñ-×1Ñ1°+¸rÓBˆŒØ�?‰?˜bÒ Ø"×1Ñ1×5Ñ5°lÀFÓKˆD�Oä�M‰MØKÜ"ôð !×/Ñ/×3Ñ3°MÀ2ÓFˆÔØ×Ñ Ò"Ø $× 3Ñ 3× 7Ñ 7¸ÈÓ QˆDÕä�M‰MØOÜ"ôð  ×.Ñ.×2Ñ2ØÓFó
ˆÔð !×/Ñ/×3Ñ3ØÓHó
ˆÔð #×1Ñ1×5Ñ5°oÓFˆÔØˆ�	r%   c                ó°   — t        |«      }|j                  | j                  d «       |j                  | j                  d «       |j                  dd «       |S ©NÚ_type)ÚdictÚpopr7   r3   )r"   r!   Úmetas      r#   r(   zInfinispanVS._default_metadataq   sD   € Ü�D‹zˆØ�‰�×"Ñ" DÔ)Ø�‰�—‘ $Ô'Ø�‰�˜$ÔØˆr%   c                ó8   — |j                  | j                  «      S r   )r/   r3   )r"   r!   s     r#   r   zInfinispanVS._default_contentx   s   € Ø�x‰x˜Ÿ™Ó(Ð(r%   c                óT  — d}|| j                   || j                  fz  }d}|j                  «       D ]ï  \  }}t        |t        «      r|d|z   dz   t	        |«      z   dz   z  }nºt        |t
        «      r|d|z   dz   t	        |«      z   dz   z  }n�t        |t        «      r|d|z   dz   t	        |«      z   dz   z  }ndt        |t        «      r|d|z   dz   t	        |«      z   dz   z  }n9t        |t        «      r|d	|z   dz   t	        |«      z   dz   z  }nt        d
|z   «      ‚|dz  }Œñ |dz  }|S )NzV
/**
* @Indexed
*/
message %s {
/**
* @Vector(dimension=%d)
*/
repeated float %s = 1;
é   zoptional string z = z;
zoptional int64 zoptional double zoptional bytes zoptional bool zEUnable to build proto schema for metadata. Unhandled type for field: é   z}
)
r1   r7   ÚitemsÚ
isinstancer.   ÚintÚfloatÚbytesÚboolÚ	Exception)r"   ÚtemplÚ	dimensionÚmetadata_proto_tplÚmetadata_protoÚidxÚfÚvs           r#   Úschema_builderzInfinispanVS.schema_builder{   sc  € ð	Ðð ,Ø×ÑØØ×Ñð/
ñ 
ˆð
 ˆØ—K‘K–M‰DˆAˆqÜ˜!œSÔ!ØÐ"4°qÑ"8¸5Ñ"@Ä3ÀsÃ8Ñ"KÈeÑ"SÑS‘Ü˜AœsÔ#ØÐ"3°aÑ"7¸%Ñ"?Ä#ÀcÃ(Ñ"JÈUÑ"RÑR‘Ü˜AœuÔ%ØÐ"4°qÑ"8¸5Ñ"@Ä3ÀsÃ8Ñ"KÈeÑ"SÑS‘Ü˜AœuÔ%ØÐ"3°aÑ"7¸%Ñ"?Ä#ÀcÃ(Ñ"JÈUÑ"RÑR‘Ü˜AœtÔ$ØÐ"2°QÑ"6¸Ñ">ÄÀSÃÑ"IÈEÑ"QÑQ‘äð1Ø34ñ5óð ð �1‰H‰Cð! "ð" 	˜%ÑˆØÐr%   c                óT   — | j                   j                  | j                  dz   |«      S )z·Deploy the schema for the vector db
        Args:
            proto(str): protobuf schema
        Returns:
            An http Response containing the result of the operation
        ú.proto)r,   Úschema_postr1   )r"   Úprotos     r#   Úschema_createzInfinispanVS.schema_create    s&   € ð �y‰y×$Ñ$ T×%6Ñ%6¸Ñ%AÀ5ÓIÐIr%   c                óR   — | j                   j                  | j                  dz   «      S )z�Delete the schema for the vector db
        Returns:
            An http Response containing the result of the operation
        rZ   )r,   Úschema_deleter1   ©r"   s    r#   r_   zInfinispanVS.schema_delete©   s$   € ð
 �y‰y×&Ñ& t×'8Ñ'8¸8Ñ'CÓDÐDr%   c                ó|   — |dk(  rd| j                   z   dz   }| j                  j                  | j                  |«      S )zÃCreate the cache for the vector db
        Args:
            config(str): configuration of the cache.
        Returns:
            An http Response containing the result of the operation
        r   aZ  
            {
  "distributed-cache": {
    "owners": "2",
    "mode": "SYNC",
    "statistics": true,
    "encoding": {
      "media-type": "application/x-protostream"
    },
    "indexing": {
      "enabled": true,
      "storage": "filesystem",
      "startup-mode": "AUTO",
      "indexing-mode": "AUTO",
      "indexed-entities": [
        "z"
      ]
    }
  }
}
)r1   r,   Ú
cache_postr0   )r"   Úconfigs     r#   Úcache_createzInfinispanVS.cache_create°   sN   € ð �RŠ<ðð  ×#Ñ#ñ!$ð"ñ#ð ð2 �y‰y×#Ñ# D×$4Ñ$4°fÓ=Ð=r%   c                óL   — | j                   j                  | j                  «      S )z€Delete the cache for the vector db
        Returns:
            An http Response containing the result of the operation
        )r,   Úcache_deleter0   r`   s    r#   rf   zInfinispanVS.cache_deleteÓ   ó   € ð
 �y‰y×%Ñ% d×&6Ñ&6Ó7Ð7r%   c                óL   — | j                   j                  | j                  «      S )zClear the cache for the vector db
        Returns:
            An http Response containing the result of the operation
        )r,   Úcache_clearr0   r`   s    r#   ri   zInfinispanVS.cache_clearÚ   ó   € ð
 �y‰y×$Ñ$ T×%5Ñ%5Ó6Ð6r%   c                óL   — | j                   j                  | j                  «      S )zOChecks if the cache exists
        Returns:
            true if exists
        )r,   Úcache_existsr0   r`   s    r#   rl   zInfinispanVS.cache_existsá   rg   r%   c                óL   — | j                   j                  | j                  «      S )zClear the index for the vector db
        Returns:
            An http Response containing the result of the operation
        )r,   Úindex_clearr0   r`   s    r#   Úcache_index_clearzInfinispanVS.cache_index_clearè   rj   r%   c                óL   — | j                   j                  | j                  «      S )z{Rebuild the for the vector db
        Returns:
            An http Response containing the result of the operation
        )r,   Úindex_reindexr0   r`   s    r#   Úcache_index_reindexz InfinispanVS.cache_index_reindexï   s   € ð
 �y‰y×&Ñ& t×'7Ñ'7Ó8Ð8r%   c                óz  — g }t        |«      }|r|j                  «        | j                  j                  |«      }|r|j	                  |«       |s|D �cg c]  }i ‘Œ }}| j
                  xs+ |D �cg c]  }t        t        j                  «       «      ‘Œ! c}}	t        t        |||	«      «      }
|
D ]~  \  }}}d| j                  | j                  |i}|j                  |«       t        j                  |«      }| j                  j!                  ||| j"                  «       |j	                  |«       Œ€ |S c c}w c c}w rA   )ÚlistrD   r2   Úembed_documentsÚappendr;   r.   ÚuuidÚuuid4Úzipr1   r7   ÚupdateÚjsonÚdumpsr,   Úputr0   )r"   ÚtextsÚ	metadatasÚlast_vectorr>   ÚresultÚtexts_lÚembedsÚ_r=   Ú
data_inputÚmetadataÚembedÚkeyÚdataÚdata_strs                   r#   Ú	add_textszInfinispanVS.add_textsö   s  € ð ˆÜ�u“+ˆÙØ�K‰KŒMØ—‘×0Ñ0°Ó9ˆÙØ�M‰M˜+Ô&ÙÙ%*Ó+¡U š UˆIÐ+Ø�i‰iÒ=±uÓ=±u°!œC¤§
¡
£Õ-°uÑ=ˆÜœ#˜i¨°Ó5Ó6ˆ
Û$.Ñ ˆH�e˜SØ˜T×.Ñ.°×0AÑ0AÀ5ÐIˆDØ�K‰K˜Ô!Ü—z‘z $Ó'ˆHØ�I‰I�M‰M˜#˜x¨×)9Ñ)9Ô:Ø�M‰M˜#Õð %/ð ˆùò ,ùÚ=s   Á	D3Á1$D8c                ó^   — | j                  ||¬«      }|D ��cg c]  \  }}|‘Œ	 c}}S c c}}w )z"Return docs most similar to query.)ÚqueryÚk)Úsimilarity_search_with_score)r"   r�   rŽ   r>   Ú	documentsÚdocr„   s          r#   Úsimilarity_searchzInfinispanVS.similarity_search  s5   € ð ×5Ñ5¸EÀQÐ5ÓGˆ	Ù"+Ô,¡)™˜˜Q’ )Ò,Ð,ùÓ,s   ™)c                ób   — | j                   j                  |«      }| j                  ||¬«      }|S )a  Perform a search on a query string and return results with score.

        Args:
            query (str): The text being searched.
            k (int, optional): The amount of results to return. Defaults to 4.

        Returns:
            List[Tuple[Document, float]]
        )r<   rŽ   )r2   Úembed_queryÚ&similarity_search_with_score_by_vector)r"   r�   rŽ   r>   r‡   r�   s         r#   r�   z)InfinispanVS.similarity_search_with_score  s4   € ð —‘×+Ñ+¨EÓ2ˆØ×?Ñ?È%ÐSTÐ?ÓUˆ	ØÐr%   c                ó\   — | j                  ||«      }|D ��cg c]  \  }}|‘Œ	 c}}S c c}}w r   )r•   )r"   r<   rŽ   r>   Úresr‘   r„   s          r#   Úsimilarity_search_by_vectorz(InfinispanVS.similarity_search_by_vector'  s2   € ð ×9Ñ9¸)ÀQÓGˆÙ"%Ô&¡#™˜˜Q’ #Ò&Ð&ùÓ&s   ˜(c                óV  — | j                   €Hd| j                  z   dz   | j                  z   dz   t        j                  |«      z   dz   t        |«      z   }n€d}| j                   dd D ]  }|dz   |z   d	z   }Œ |dz   | j                   d   z   }|d
z   | j                  z   dz   | j                  z   dz   t        j                  |«      z   dz   t        |«      z   }| j                  j                  || j                  «      }t        j                  |j                  «      }| j                  |«      S )a$  Return docs most similar to embedding vector.

        Args:
            embedding: Embedding to look up documents similar to.
            k: Number of Documents to return. Defaults to 4.

        Returns:
            List of pair (Documents, score) most similar to the query vector.
        Nzselect v, score(v) from z v where v.z <-> Ú~zselect éÿÿÿÿzv.Ú,z, score(v) from )r:   r1   r7   r{   r|   r.   r,   Ú	req_queryr0   Úloadsr   Ú_query_result_to_docs)r"   r<   rŽ   Ú	query_strÚ
query_projÚfieldÚ	query_resr�   s           r#   r•   z3InfinispanVS.similarity_search_with_score_by_vector-  sm  € ð ×ÑÐ&à*Ø×#Ñ#ñ$àñ ð ×#Ñ#ñ$ð ñ	ô
 —*‘*˜YÓ'ñ(ð ñô �a“&ññ ð #ˆJØ×,Ñ,¨S¨bÓ1�Ø'¨$Ñ.°Ñ6¸Ñ<‘
ð 2à# dÑ*¨T×-@Ñ-@ÀÑ-DÑDˆJàØ$ñ%à×#Ñ#ñ$ð  ñ ð ×#Ñ#ñ	$ð
 ñô —*‘*˜YÓ'ñ(ð ñô �a“&ñð ð —I‘I×'Ñ'¨	°4×3CÑ3CÓDˆ	Ü—‘˜IŸN™NÓ+ˆØ×)Ñ)¨&Ó1Ð1r%   c                ó2  — g }|d   D ]‡  }|d   xs i }| j                   €|d   }n)| j                   D �ci c]  }||j                  |«      “Œ }}t        | j                  |«      | j	                  |«      ¬«      }|j                  ||d   f«       Œ‰ |S c c}w )NÚhitsÚhitÚ*)Úpage_contentr†   zscore())r:   r/   r   r8   r9   rv   )r"   r�   r�   Úrowr¦   Úentityrˆ   r‘   s           r#   rŸ   z"InfinispanVS._query_result_to_docsX  s°   € ð ˆ	Ø˜&”>ˆCØ�e‘*Ò" ˆCØ×"Ñ"Ð*Ø˜S™‘à7;×7JÒ7JÓKÑ7J°˜#˜sŸw™w s›|Ñ+Ð7J�ÐKÜØ!×-Ñ-¨fÓ5Ø×*Ñ*¨6Ó2ôˆCð ×Ñ˜c 3 y¡>Ð2Õ3ð "ð Ðùò Ls   ´Bc                óÈ  — | j                  ||«      }| j                  |«      }|j                  | j                  j                  j
                  k(  sJ d«       ‚	 t        j                  |j                  «      d   �J ‚| j                  «       sV| j                  «       }|j                  | j                  j                  j
                  k(  sJ d«       ‚	 | j                  «        y y )Nz)Unable to create schema. Already exists? Úerrorz(Unable to create cache. Already exists? )rX   r]   Ústatus_coder,   ÚCodesÚOKr{   rž   r   rl   rd   ro   )r"   r†   rR   ÚschemaÚoutputs        r#   Ú	configurezInfinispanVS.configurei  sÏ   € Ø×$Ñ$ X¨yÓ9ˆØ×#Ñ# FÓ+ˆØ×!Ñ! T§Y¡Y§_¡_×%7Ñ%7Ò7ð 	
Ø7ó	
Ð7ð 	(Ü�z‰z˜&Ÿ+™+Ó& wÑ/Ð7Ð7Ð7Ø× Ñ Ô"Ø×&Ñ&Ó(ˆFØ×%Ñ%¨¯©¯©×);Ñ);Ò;ð Ø:óÐ;ð ,à×"Ñ"Õ$ð #r%   c                óD   — | j                  «        | j                  «        y r   )r_   rf   r`   s    r#   Úconfig_clearzInfinispanVS.config_clearz  s   € Ø×ÑÔØ×ÑÕr%   c                ó¤  —  | d||dœ|¤Ž}|rzt        |xs g «      dkD  rh|r|j                  «        |j                  |t        |«      dz
     «      }	t        t        t
           |«      }|j                  |d   t        |	«      «       n2|r|j                  «        |j                  |t        |«      dz
     «      }	|r|j                  |||	¬«       |S )aØ  Return VectorStore initialized from texts and embeddings.

        In addition to parameters described by the super method, this
        implementation provides other configuration params if different
        configuration from default is needed.

        Parameters
        ----------
        ids : List[str]
            Additional list of keys associated to the embedding. If not
            provided UUIDs will be generated
        clear_old : bool
            Whether old data must be deleted. Default True
        auto_config: bool
            Whether to do a complete server setup (caches,
            protobuf definition...). Default True
        kwargs: Any
            Rest of arguments passed to InfinispanVS. See docs)r<   r=   r   rI   )r   r*   )	Úlenr´   r”   r   r   rC   r²   ri   r‹   )
Úclsr~   r<   r   r=   Ú	clear_oldÚauto_configr>   ÚinfinispanvsÚvecs
             r#   Ú
from_textszInfinispanVS.from_texts~  sÉ   € ñ: ÐB Y°CÑB¸6ÑBˆÙœ3˜yš¨BÓ/°!Ò3ÙØ×)Ñ)Ô+Ø×'Ñ'¨¬c°%«j¸1©nÑ(=Ó>ˆCÜœT¤$™Z¨Ó3ˆIØ×"Ñ" 9¨Q¡<´°S³Õ:áØ×(Ñ(Ô*Ø×'Ñ'¨¬c°%«j¸1©nÑ(=Ó>ˆCÙØ×"Ñ" 5¨)¸CÐ"Ô@ØÐr%   )NN)r<   zOptional[Embeddings]r=   úOptional[List[str]]r>   r   )r!   rC   ÚreturnrC   )r!   údict[str, Any]r¾   r   )rQ   rC   rR   rL   r¾   r.   )r\   r.   r¾   r   )r¾   r   )r   )rc   r.   r¾   r   )r¾   rO   )
r~   zIterable[str]r   úOptional[List[dict]]r€   zOptional[List[float]]r>   r   r¾   ú	List[str])é   )r�   r.   rŽ   rL   r>   r   r¾   úList[Document])r�   r.   rŽ   rL   r>   r   r¾   úList[Tuple[Document, float]])r<   úList[float]rŽ   rL   r>   r   r¾   rÃ   )r<   rÅ   rŽ   rL   r¾   rÄ   )r�   r¿   r¾   rÄ   )r†   rC   rR   rL   r¾   ÚNone)r¾   rÆ   )NNTT)r·   zType[InfinispanVS]r~   rÁ   r<   r   r   rÀ   r=   r½   r¸   úOptional[bool]r¹   rÇ   r>   r   r¾   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r?   r(   r   rX   r]   r_   rd   rf   ri   rl   ro   rr   r‹   r’   r�   r˜   r•   rŸ   r²   r´   Úclassmethodr¼   r*   r%   r#   r   r      sâ  „ ñ"ðL +/Ø#'ð7à'ð7ð !ð7ð ó	7óró)ó#óJJóEô!>óF8ó7ó8ó7ó9ð +/Ø-1ð	àðð (ðð +ð	ð
 ðð 
óð6 $%ð-Øð-Ø ð-Ø03ð-à	ó-ð $%ðØðØ ðØ03ðà	%óð" 01ð'Ø$ð'Ø),ð'Ø<?ð'à	ó'ð 01ð)2Ø$ð)2Ø),ð)2à	%ó)2ðVØ$ðà	%óó"%ó"ð ð
 +/Ø#'Ø$(Ø&*ð)Øð)àð)ð ð)ð (ð	)ð
 !ð)ð "ð)ð $ð)ð ð)ð 
ò)ó ñ)r%   r   é
   c            	      óò   — e Zd ZdZddddgdddddf		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zddd	„Z	 d	 	 	 	 	 	 	 dd
„Z	 d	 	 	 	 	 	 	 dd„Zdd„Zdd„Z	dd„Z
dd„Zd d„Zd!d„Zd!d„Zd"d„Zd#d„Zd$d„Zd"d„Zd"d„Zy)%r+   a>  Helper class for `Infinispan` REST interface.

    This class exposes the Infinispan operations needed to
    create and set up a vector db.

    You need a running Infinispan (15+) server without authentication.
    You can easily start one, see:
    https://github.com/rigazilla/infinispan-vector#run-infinispan
    Úhttpr   z127.0.0.1:11222z/rest/v2/cachesz/rest/v2/schemasTc
                ó°  — 	 ddl }|j                  | _        |
| _        || _        || _        || _        |d   | _        | j
                  dz   | j                  z   | _	        || _
        || _        || _        || _        | j                  r‹| j                  r| j
                  dk(  r(|j                  | j                  | j                  ¬«      }n| j                  | j                  f}|j                  | j                  | j                   ||	¬«      | _        y|j                  | j                  | j                   |	¬«      | _        y# t        $ r t        d«      ‚w xY w)	aK  
        Parameters
        ----------
        schema: str
            Schema for HTTP request: "http" or "https". Default "http"
        user, password: str
            User and password if auth is required. Default None
        hosts: List[str]
            List of server addresses. Default ["127.0.0.1:11222"]
        cache_url: str
            URL endpoint for cache API. Default "/rest/v2/caches"
        schema_url: str
            URL endpoint for schema API. Default "/rest/v2/schemas"
        use_post_for_query: bool
            Whether POST method should be used for query. Default True
        http2: bool
            Whether HTTP/2 protocol should be used. `pip install "httpx[http2]"` is
            needed for HTTP/2. Default True
        verify:  bool
            Whether TLS certificate must be verified. Default True
        r   Nz„Could not import httpx python package. Please install it with `pip install httpx`or `pip install "httpx[http2]"` if you need HTTP/2.z://rÏ   )ÚusernameÚpassword)Úhttp2Úhttp1ÚauthÚverify)rÓ   rÔ   rÖ   )ÚhttpxÚImportErrorÚcodesr®   r-   Ú_schemaÚ_userÚ	_passwordÚ_hostÚ_default_nodeÚ
_cache_urlÚ_schema_urlÚ_use_post_for_queryÚ_http2Ú
DigestAuthÚClientÚ_h2c)r"   r°   ÚuserrÒ   ÚhostsÚ	cache_urlÚ
schema_urlÚuse_post_for_queryrÓ   rÖ   r>   r×   rÕ   s                r#   r?   zInfinispan.__init__¹  sD  € ðF	Ûð —[‘[ˆŒ
à$ˆÔØˆŒØˆŒ
Ø!ˆŒØ˜1‘XˆŒ
Ø!Ÿ\™\¨EÑ1°D·J±JÑ>ˆÔØ#ˆŒØ%ˆÔØ#5ˆÔ ØˆŒØ�:Š:˜$Ÿ.š.Ø�|‰|˜vÒ%ØAF×AQÑAQØ!ŸZ™Z°$·.±.ð BRó B‘ð Ÿ
™
 D§N¡NÐ3�ØŸ™Ø—k‘kØŸ+™+�oØØð	 %ó ˆD�Ið Ÿ™Ø—k‘kØŸ+™+�oØð %ó ˆD�IøôC ò 	ÜðFóð ð	ús   ‚E  Å Ec                óf   — | j                   r| j                  |||«      S | j                  |||«      S )a  Request a query
        Args:
            query(str): query requested
            cache_name(str): name of the target cache
            local(boolean): whether the query is local to clustered
        Returns:
            An http Response containing the result set or errors
        )rá   Ú_query_postÚ
_query_get)r"   r�   r   Úlocals       r#   r�   zInfinispan.req_query  s5   € ð ×#Ò#Ø×#Ñ# E¨:°uÓ=Ð=Ø�‰˜u j°%Ó8Ð8r%   c                óÞ   — | j                   | j                  z   dz   |z   dz   t        |«      z   }d|i}t        j                  |«      }| j
                  j                  ||ddit        ¬«      }|S )NÚ/z?action=search&local=r�   úContent-Typeúapplication/json©ÚcontentÚheadersÚtimeout)rÞ   rß   r.   r{   r|   rå   ÚpostÚREST_TIMEOUT)r"   r    r   rî   Úapi_urlr‰   Ú	data_jsonÚresponses           r#   rì   zInfinispan._query_post  s’   € ð ×ÑØ�o‰oñàñð ñð &ñ	&ô
 �%‹jñð 	ð ˜Ð#ˆÜ—J‘J˜tÓ$ˆ	Ø—9‘9—>‘>ØØØ#Ð%7Ð8Ü ð	 "ó 
ˆð ˆr%   c                ó°   — | j                   | j                  z   dz   |z   dz   |z   dz   t        |«      z   }| j                  j	                  |t
        ¬«      }|S )Nrð   z?action=search&query=z&local=©rö   )rÞ   rß   r.   rå   r/   rø   )r"   r    r   rî   rù   rû   s         r#   rí   zInfinispan._query_get'  sy   € ð ×ÑØ�o‰oñàñð ñð &ñ	&ð
 ñð ñô �%‹jñð 	ð —9‘9—=‘= ´,�=Ó?ˆØˆr%   c                óš   — | j                   | j                  z   dz   |z   dz   |z   }| j                  j                  ||ddit        ¬«      }|S )a  Post an entry
        Args:
            key(str): key of the entry
            data(str): content of the entry in json format
            cache_name(str): target cache
        Returns:
            An http Response containing the result of the operation
        rð   rñ   rò   ró   ©rÞ   rß   rå   r÷   rø   ©r"   rˆ   r‰   r   rù   rû   s         r#   r÷   zInfinispan.post7  s]   € ð ×$Ñ$ t§¡Ñ6¸Ñ<¸zÑIÈCÑOÐRUÑUˆØ—9‘9—>‘>ØØØ#Ð%7Ð8Ü ð	 "ó 
ˆð ˆr%   c                óš   — | j                   | j                  z   dz   |z   dz   |z   }| j                  j                  ||ddit        ¬«      }|S )a  Put an entry
        Args:
            key(str): key of the entry
            data(str): content of the entry in json format
            cache_name(str): target cache
        Returns:
            An http Response containing the result of the operation
        rð   rñ   rò   ró   )rÞ   rß   rå   r}   rø   r   s         r#   r}   zInfinispan.putI  s]   € ð ×$Ñ$ t§¡Ñ6¸Ñ<¸zÑIÈCÑOÐRUÑUˆØ—9‘9—=‘=ØØØ#Ð%7Ð8Ü ð	 !ó 
ˆð ˆr%   c                ó˜   — | j                   | j                  z   dz   |z   dz   |z   }| j                  j                  |ddit        ¬«      }|S )zÁGet an entry
        Args:
            key(str): key of the entry
            cache_name(str): target cache
        Returns:
            An http Response containing the entry or errors
        rð   rñ   rò   )rõ   rö   )rÞ   rß   rå   r/   rø   )r"   rˆ   r   rù   rû   s        r#   r/   zInfinispan.get[  sX   € ð ×$Ñ$ t§¡Ñ6¸Ñ<¸zÑIÈCÑOÐRUÑUˆØ—9‘9—=‘=Ø˜nÐ.@ÐAÌ<ð !ó 
ˆð ˆr%   c                óˆ   — | j                   | j                  z   dz   |z   }| j                  j                  ||t        ¬«      }|S )zäDeploy a schema
        Args:
            name(str): name of the schema. Will be used as a key
            proto(str): protobuf schema
        Returns:
            An http Response containing the result of the operation
        rð   )rô   rö   )rÞ   rà   rå   r÷   rø   )r"   Únamer\   rù   rû   s        r#   r[   zInfinispan.schema_posti  sA   € ð ×$Ñ$ t×'7Ñ'7Ñ7¸#Ñ=ÀÑDˆØ—9‘9—>‘> '°5Ä,�>ÓOˆØˆr%   c                óŽ   — | j                   | j                  z   dz   |z   }| j                  j                  ||ddit        ¬«      }|S )zÙCreate a cache
        Args:
            name(str): name of the cache.
            config(str): configuration of the cache.
        Returns:
            An http Response containing the result of the operation
        rð   rñ   rò   ró   rÿ   )r"   r  rc   rù   rû   s        r#   rb   zInfinispan.cache_postu  sR   € ð ×$Ñ$ t§¡Ñ6¸Ñ<¸tÑCˆØ—9‘9—>‘>ØØØ#Ð%7Ð8Ü ð	 "ó 
ˆð ˆr%   c                ó†   — | j                   | j                  z   dz   |z   }| j                  j                  |t        ¬«      }|S )z¦Delete a schema
        Args:
            name(str): name of the schema.
        Returns:
            An http Response containing the result of the operation
        rð   rý   )rÞ   rà   rå   Údeleterø   ©r"   r  rù   rû   s       r#   r_   zInfinispan.schema_delete†  sB   € ð ×$Ñ$ t×'7Ñ'7Ñ7¸#Ñ=ÀÑDˆØ—9‘9×#Ñ# G´\Ð#ÓBˆØˆr%   c                ó†   — | j                   | j                  z   dz   |z   }| j                  j                  |t        ¬«      }|S )z¤Delete a cache
        Args:
            name(str): name of the cache.
        Returns:
            An http Response containing the result of the operation
        rð   rý   )rÞ   rß   rå   r  rø   r  s       r#   rf   zInfinispan.cache_delete‘  s@   € ð ×$Ñ$ t§¡Ñ6¸Ñ<¸tÑCˆØ—9‘9×#Ñ# G´\Ð#ÓBˆØˆr%   c                óŒ   — | j                   | j                  z   dz   |z   dz   }| j                  j                  |t        ¬«      }|S )z©Clear a cache
        Args:
            cache_name(str): name of the cache.
        Returns:
            An http Response containing the result of the operation
        rð   ú?action=clearrý   rÿ   )r"   r   rù   rû   s       r#   ri   zInfinispan.cache_clearœ  sG   € ð ×Ñ §¡Ñ0°3Ñ6¸ÑCÀoÑUð 	ð —9‘9—>‘> '´<�>Ó@ˆØˆr%   c                óh   — | j                   | j                  z   dz   |z   dz   }| j                  |«      S )z�Check if a cache exists
        Args:
            cache_name(str): name of the cache.
        Returns:
            True if cache exists
        rð   r  )rÞ   rß   Úresource_exists©r"   r   rù   s      r#   rl   zInfinispan.cache_exists©  s=   € ð ×Ñ §¡Ñ0°3Ñ6¸ÑCÀoÑUð 	ð ×#Ñ# GÓ,Ð,r%   c                óŠ   — | j                   j                  |t        ¬«      }|j                  | j                  j
                  k(  S )z•Check if a resource exists
        Args:
            api_url(str): url of the resource.
        Returns:
            true if resource exists
        rý   )rå   Úheadrø   r­   r®   r¯   )r"   rù   rû   s      r#   r  zInfinispan.resource_existsµ  s3   € ð —9‘9—>‘> '´<�>Ó@ˆØ×#Ñ# t§z¡z§}¡}Ñ4Ð4r%   c                óˆ   — | j                   | j                  z   dz   |z   dz   }| j                  j                  |t        ¬«      S )zµClear an index on a cache
        Args:
            cache_name(str): name of the cache.
        Returns:
            An http Response containing the result of the operation
        rð   z/search/indexes?action=clearrý   rÿ   r  s      r#   rn   zInfinispan.index_clear¿  sS   € ð ×ÑØ�o‰oñàñð ñð -ñ	-ð 	ð �y‰y�~‰~˜g¬|ˆ~Ó<Ð<r%   c                óˆ   — | j                   | j                  z   dz   |z   dz   }| j                  j                  |t        ¬«      S )z´Rebuild index on a cache
        Args:
            cache_name(str): name of the cache.
        Returns:
            An http Response containing the result of the operation
        rð   z/search/indexes?action=reindexrý   rÿ   r  s      r#   rq   zInfinispan.index_reindexÏ  sS   € ð ×ÑØ�o‰oñàñð ñð /ñ	/ð 	ð �y‰y�~‰~˜g¬|ˆ~Ó<Ð<r%   N)r°   r.   ræ   r.   rÒ   r.   rç   rÁ   rè   r.   ré   r.   rê   rO   rÓ   rO   rÖ   rO   r>   r   )F)r�   r.   r   r.   rî   rO   r¾   r   )r    r.   r   r.   rî   rO   r¾   r   )rˆ   r.   r‰   r.   r   r.   r¾   r   )rˆ   r.   r   r.   r¾   r   )r  r.   r\   r.   r¾   r   )r  r.   rc   r.   r¾   r   )r  r.   r¾   r   )r   r.   r¾   r   )r   r.   r¾   rO   )rù   r.   r¾   rO   )rÈ   rÉ   rÊ   rË   r?   r�   rì   rí   r÷   r}   r/   r[   rb   r_   rf   ri   rl   r  rn   rq   r*   r%   r#   r+   r+   ®  s1  „ ñð ØØØ-Ð.Ø*Ø,Ø#'ØØðJàðJð ðJð ð	Jð
 ðJð ðJð ðJð !ðJð ðJð ðJð óJôX9ð >CðØðØ*-ðØ6:ðà	óð, >CðØðØ*-ðØ6:ðà	óó ó$ó$ó
óó"	ó	óó
-ó5ó=ô =r%   r+   )rË   Ú
__future__r   r{   Úloggingrw   r4   Útypingr   r   r   r   r   r	   r
   r   r×   r   Úlangchain_core.documentsr   Úlangchain_core.embeddingsr   Úlangchain_core.vectorstoresr   Ú	getLoggerrÈ   Úloggerr   rø   r+   r*   r%   r#   Ú<module>r     s`   ðÙ 2å "ã Û Û Û ß J× JÓ Jå Ý -Ý 0Ý 3à	ˆ×	Ñ	˜8Ó	$€ôU�;ô Uðp €÷o=ò o=r%   