§
    ¦ìNg’%  ã                   ó€   — d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
mZ  G d„ de
e¦  «        Z G d„ de¦  «        Zd	S )
é    )ÚAnyÚDictÚListÚOptional)Ú
Embeddings)Úget_from_dict_or_env)Ú	BaseModelÚmodel_validatorc                   ó’  — 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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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_sizeFÚ	normalizeÚcontextual_control_thresholdTÚcontrol_log_additiveÚaleph_alpha_api_keyzhttps://api.aleph-alpha.comÚhostÚhostingi1  Úrequest_timeout_secondsé   Útotal_retriesÚniceÚbefore)ÚmodeÚ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)Úclsr   r   r    s       úf/var/www/html/ai-engine/env/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”^ð ñ  ô  ˆF8ÑÐøõ ð 	ð 	ð 	Ýð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$   Ú	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_documentsm   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.   r1   r3   )r#   r+   r,   r-   r$   r4   ÚQueryr   r   r   r   r   r6   r   r8   )r9   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
   Úclassmethodr   r'   r   Úfloatr?   rG   r3   ó    r&   r   r      sÈ  € € € € € € ðð ð. €K€KKð !€Eˆ3Ð Ð Ñ ØØ&*Ðh˜s”mÐ*Ð*Ñ*ð.à€IˆtÐÐÑØ2Ø26Ð  (¨3¤-Ð6Ð6Ñ6ð+à!%Ð˜$Ð%Ð%Ñ%ðð *.Ð˜ #œÐ-Ð-Ñ-Ø&Ø-€Dˆ#Ð-Ð-Ñ-ð9à!€GˆXcŒ]Ð!Ð!Ñ!ð4ð $'Ð˜SÐ&Ð&Ñ&ðWð €M3ÐÐÑðð €Dˆ$ÐÐÑð>ð €_˜(Ð#Ñ#Ô#Øð¨$ð °3ð ð ð ñ „[ñ $Ô#ðð0'# T¨#¤Yð '#°4¸¸U¼Ô3Dð '#ð '#ð '#ð '#ðR!, ð !,¨¨U¬ð !,ð !,ð !,ð !,ð !,ð !,rR   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 )	Ú$AlephAlphaSymmetricSemanticEmbeddingaW  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.   r1   r3   )r#   r+   r,   r-   r$   r4   Ú	Symmetricr   r   r   r   r   r6   r   r8   )r9   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.
        )r7   rZ   )r9   r(   r:   r;   s       r&   r?   z4AlephAlphaSymmetricSemanticEmbedding.embed_documentsé   sB   € ð !Ðàð 	:ð 	:ˆDØ×&Ò& t§{¢{°4Ñ'8Ô'8Ñ9Ô9Ð9Ð9Ø"Ð"rR   c                 ó,   — |                       |¦  «        S )rB   )rZ   )r9   r;   s     r&   rG   z0AlephAlphaSymmetricSemanticEmbedding.embed_queryø   s   € ð {Š{˜4Ñ Ô Ð rR   N)
rH   rI   rJ   rK   rM   r   rQ   rZ   r?   rG   r3   rR   r&   rT   rT   º   s™   € € € € € ðð ð$(˜3ð ( 4¨¤;ð (ð (ð (ð (ð8# T¨#¤Yð #°4¸¸U¼Ô3Dð #ð #ð #ð #ð! ð !¨¨U¬ð !ð !ð !ð !ð !ð !rR   rT   N)Útypingr   r   r   r   Úlangchain_core.embeddingsr   Úlangchain_core.utilsr   Úpydanticr	   r
   r   rT   r3   rR   r&   ú<module>ra      sÙ   ðØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /ðo,ð o,ð o,ð o,ð o,¨I°zñ o,ô o,ð o,ðdF!ð F!ð F!ð F!ð F!Ð+Pñ F!ô F!ð F!ð F!ð F!rR   