§
    æ˜ºhŽ%  ã                   ó€   — d dl mZmZmZmZ d dlmZ d dlmZm	Z	 d dl
mZ  G d„ dee¦  «        Z G d„ de¦  «        Zd	S )
é    )ÚAnyÚDictÚListÚOptional)Ú
Embeddings)Ú	BaseModelÚroot_validator)Úget_from_dict_or_envc                   óŠ  — e Zd ZU dZeed<   dZeed<   	 dZe	e
         ed<   	 dZe	e         ed<   	 dZe	e
         ed<   	 d	Zeed
<   	 dZe	e         ed<   	 dZeed<   	 dZe	e         ed<   	 dZe
ed<   	 dZe
ed<   	 dZeed<   	  e¦   «         dedefd„¦   «         Zdee         deee                  fd„Zdedee         fd„ZdS )Ú%AlephAlphaAsymmetricSemanticEmbeddinga6  Aleph Alpha's asymmetric semantic embedding.

    AA provides you with an endpoint to embed a document and a query.
    The models were optimized to make the embeddings of documents and
    the query for a document as similar as possible.
    To learn more, check out: https://docs.aleph-alpha.com/docs/tasks/semantic_embed/

    Example:
        .. code-block:: python
            from aleph_alpha import AlephAlphaAsymmetricSemanticEmbedding

            embeddings = AlephAlphaAsymmetricSemanticEmbedding(
                normalize=True, compress_to_size=128
            )

            document = "This is a content of the document"
            query = "What is the content of the document?"

            doc_result = embeddings.embed_documents([document])
            query_result = embeddings.embed_query(query)

    Úclientzluminous-baseÚmodelNÚcompress_to_sizeÚ	normalizeÚcontextual_control_thresholdTÚcontrol_log_additiveÚaleph_alpha_api_keyzhttps://api.aleph-alpha.comÚhostÚhostingi1  Úrequest_timeout_secondsé   Útotal_retriesFÚniceÚvaluesÚreturnc           	      óÖ   — t          |dd¦  «        }	 ddlm}  |||d         |d         |d         |d         |d	         ¬
¦  «        |d<   n# t          $ r t	          d¦  «        ‚w xY w|S )z?Validate that api key and python package exists in environment.r   ÚALEPH_ALPHA_API_KEYr   )ÚClientr   r   r   r   r   )Útokenr   r   r   r   r   r   úlCould not import aleph_alpha_client python package. Please install it with `pip install aleph_alpha_client`.)r
   Úaleph_alpha_clientr   ÚImportErrorÚ
ValueError)Úclsr   r   r   s       úr/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain_community/embeddings/aleph_alpha.pyÚvalidate_environmentz:AlephAlphaAsymmetricSemanticEmbedding.validate_environmentS   s¸   € õ 3ØÐ)Ð+@ñ
ô 
Ðð	Ø1Ð1Ð1Ð1Ð1Ð1à%˜vØ)Ø˜F”^Ø˜yÔ)Ø(.Ð/HÔ(IØ$ _Ô5Ø˜F”^ð ñ  ô  ˆF�8ÑÐøõ ð 	ð 	ð 	ÝðKñô ð ð	øøøð ˆs   “8A ÁA&Útextsc                 óV  — 	 ddl m}m}m} n# t          $ r t          d¦  «        ‚w xY wg }|D ]z}|                     |¦  «        |j        | j        | j	        | j
        | j        dœ} |di |¤Ž}| j                             || j        ¬¦  «        }	|                     |	j        ¦  «         Œ{|S )zÃCall out to Aleph Alpha's asymmetric Document endpoint.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        r   ©ÚPromptÚSemanticEmbeddingRequestÚSemanticRepresentationr    ©ÚpromptÚrepresentationr   r   r   r   ©Úrequestr   © )r!   r*   r+   r,   r"   r#   Ú	from_textÚDocumentr   r   r   r   r   Úsemantic_embedr   ÚappendÚ	embedding)
Úselfr'   r*   r+   r,   Údocument_embeddingsÚtextÚdocument_paramsÚdocument_requestÚdocument_responses
             r%   Úembed_documentsz5AlephAlphaAsymmetricSemanticEmbedding.embed_documentsl   s&  € ð
	ðð ð ð ð ð ð ð ð ð ð øõ
 ð 	ð 	ð 	ÝðKñô ð ð	øøøð
 !Ðàð 	Dð 	DˆDà ×*Ò*¨4Ñ0Ô0Ø"8Ô"AØ$(Ô$9Ø!œ^Ø04Ô0QØ(,Ô(Aðð ˆOð  8Ð7ÐJÐJ¸/ÐJÐJÐØ $¤× :Ò :Ø(°´
ð !;ñ !ô !Ðð  ×&Ò&Ð'8Ô'BÑCÔCÐCÐCà"Ð"ó   ‚
 �'r:   c                 ó  — 	 ddl m}m}m} n# t          $ r t          d¦  «        ‚w xY w|                     |¦  «        |j        | j        | j	        | j
        | j        dœ} |di |¤Ž}| j                             || j        ¬¦  «        }|j        S )ú±Call out to Aleph Alpha's asymmetric, query embedding endpoint
        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   r)   r    r-   r0   r2   )r!   r*   r+   r,   r"   r#   r3   ÚQueryr   r   r   r   r   r5   r   r7   )r8   r:   r*   r+   r,   Úsymmetric_paramsÚsymmetric_requestÚsymmetric_responses           r%   Úembed_queryz1AlephAlphaAsymmetricSemanticEmbedding.embed_query•   sù   € ð
	ðð ð ð ð ð ð ð ð ð ð øõ
 ð 	ð 	ð 	ÝðKñô ð ð	øøøð ×&Ò& tÑ,Ô,Ø4Ô:Ø $Ô 5ØœØ,0Ô,MØ$(Ô$=ð
ð 
Ðð 5Ð4ÐHÐHÐ7GÐHÐHÐØ!œ[×7Ò7Ø%¨T¬Zð 8ñ 
ô 
Ðð "Ô+Ð+r?   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Ústrr   r   Úintr   Úboolr   r   r   r   r   r   r   r   r	   r   r&   r   Úfloatr>   rF   r2   ó    r%   r   r      s½  € € € € € € ðð ð. €K€K�Kð !€Eˆ3Ð Ð Ñ ØØ&*Ð�h˜s”mÐ*Ð*Ñ*ð.à $€Iˆx˜Œ~Ð$Ð$Ñ$Ø2Ø26Ð  (¨3¤-Ð6Ð6Ñ6ð+à!%Ð˜$Ð%Ð%Ñ%ðð *.Ð˜ #œÐ-Ð-Ñ-Ø&Ø-€Dˆ#Ð-Ð-Ñ-ð9à!€GˆX�cŒ]Ð!Ð!Ñ!ð4ð $'Ð˜SÐ&Ð&Ñ&ðWð €M�3ÐÐÑðð €Dˆ$ÐÐÑð>ð €^ÑÔð¨$ð °4ð ð ð ñ Ôðð0'# T¨#¤Yð '#°4¸¸U¼Ô3Dð '#ð '#ð '#ð '#ðR!, ð !,¨¨U¬ð !,ð !,ð !,ð !,ð !,ð !,rP   r   c                   ó~   — e Zd ZdZdedee         fd„Zdee         deee                  fd„Zdedee         fd„Z	dS )	Ú$AlephAlphaSymmetricSemanticEmbeddinga[  The symmetric version of the Aleph Alpha's semantic embeddings.

    The main difference is that here, both the documents and
    queries are embedded with a SemanticRepresentation.Symmetric
    Example:
        .. code-block:: python

            from aleph_alpha import AlephAlphaSymmetricSemanticEmbedding

            embeddings = AlephAlphaAsymmetricSemanticEmbedding(
                normalize=True, compress_to_size=128
            )
            text = "This is a test text"

            doc_result = embeddings.embed_documents([text])
            query_result = embeddings.embed_query(text)
    r:   r   c                 ó  — 	 ddl m}m}m} n# t          $ r t          d¦  «        ‚w xY w|                     |¦  «        |j        | j        | j	        | j
        | j        dœ} |di |¤Ž}| j                             || j        ¬¦  «        }|j        S )Nr   r)   r    r-   r0   r2   )r!   r*   r+   r,   r"   r#   r3   Ú	Symmetricr   r   r   r   r   r5   r   r7   )r8   r:   r*   r+   r,   Úquery_paramsÚquery_requestÚquery_responses           r%   Ú_embedz+AlephAlphaSymmetricSemanticEmbedding._embedÌ   sõ   € ð
	ðð ð ð ð ð ð ð ð ð ð øõ
 ð 	ð 	ð 	ÝðKñô ð ð	øøøð ×&Ò& tÑ,Ô,Ø4Ô>Ø $Ô 5ØœØ,0Ô,MØ$(Ô$=ð
ð 
ˆð 1Ð0Ð@Ð@°<Ð@Ð@ˆØœ×3Ò3Ø!¨¬ð 4ñ 
ô 
ˆð Ô'Ð'r?   r'   c                 ód   — g }|D ]*}|                      |                      |¦  «        ¦  «         Œ+|S )z¸Call out to Aleph Alpha's Document endpoint.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        )r6   rX   )r8   r'   r9   r:   s       r%   r>   z4AlephAlphaSymmetricSemanticEmbedding.embed_documentsè   sB   € ð !Ðàð 	:ð 	:ˆDØ×&Ò& t§{¢{°4Ñ'8Ô'8Ñ9Ô9Ð9Ð9Ø"Ð"rP   c                 ó,   — |                       |¦  «        S )rA   )rX   )r8   r:   s     r%   rF   z0AlephAlphaSymmetricSemanticEmbedding.embed_query÷   s   € ð �{Š{˜4Ñ Ô Ð rP   N)
rG   rH   rI   rJ   rL   r   rO   rX   r>   rF   r2   rP   r%   rR   rR   ¹   s™   € € € € € ðð ð$(˜3ð ( 4¨¤;ð (ð (ð (ð (ð8# T¨#¤Yð #°4¸¸U¼Ô3Dð #ð #ð #ð #ð! ð !¨¨U¬ð !ð !ð !ð !ð !ð !rP   rR   N)Útypingr   r   r   r   Úlangchain_core.embeddingsr   Úlangchain_core.pydantic_v1r   r	   Úlangchain_core.utilsr
   r   rR   r2   rP   r%   ú<module>r_      sÙ   ðØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5ðn,ð n,ð n,ð n,ð n,¨I°zñ n,ô n,ð n,ðbF!ð F!ð F!ð F!ð F!Ð+Pñ F!ô F!ð F!ð F!ð F!rP   