Ë
    7 |h’%  ã                   ór   — 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y	)
é    )ÚAnyÚDictÚListÚOptional)Ú
Embeddings)Úget_from_dict_or_env)Ú	BaseModelÚmodel_validatorc                   óN  — 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y)Ú%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<   |S # t        $ r t        d«      ‚w xY w)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       úi/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/embeddings/aleph_alpha.pyÚvalidate_environmentz:AlephAlphaAsymmetricSemanticEmbedding.validate_environmentS   s„   € ô 3ØÐ)Ð+@ó
Ðð	Ý1á%Ø)Ø˜F‘^Ø˜yÑ)Ø(.Ð/HÑ(IØ$ _Ñ5Ø˜F‘^ô ˆF8Ñð ˆøô ò 	ÜðKóð ð	ús	   &7 ·AÚtextsc                 ó†  — 	 ddl m}m}m} g }|D ]–  }|j                  |«      |j                  | j                  | j                  | j                  | j                  dœ} |di |¤Ž}| j                  j                  || j                  ¬«      }	|j                  |	j                  «       Œ˜ |S # t        $ r t	        d«      ‚w xY w)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à   € ð
	÷ñ ð !Ðàò 	DˆDà ×*Ñ*¨4Ó0Ø"8×"AÑ"AØ$(×$9Ñ$9Ø!Ÿ^™^Ø04×0QÑ0QØ(,×(AÑ(AñˆOñ  8ÑJ¸/ÑJÐØ $§¡× :Ñ :Ø(°·
±
ð !;ó !Ðð  ×&Ñ&Ð'8×'BÑ'BÕCð	Dð" #Ð"øô1 ò 	ÜðKóð ð	ús   ‚
B+ Â+C r;   c                 óR  — 	 ddl m}m}m} |j                  |«      |j                  | j                  | j                  | j                  | j                  dœ} |di |¤Ž}| j                  j                  || j                  ¬«      }|j                  S # t        $ r t	        d«      ‚w xY w)ú±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º   € ð
	÷ñ ð ×&Ñ& tÓ,Ø4×:Ñ:Ø $× 5Ñ 5ØŸ™Ø,0×,MÑ,MØ$(×$=Ñ$=ñ
Ðñ 5ÑHÐ7GÑHÐØ!Ÿ[™[×7Ñ7Ø%¨T¯Z©Zð 8ó 
Ðð "×+Ñ+Ð+øô' ò 	ÜðKóð ð	úó   ‚
B ÂB&)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Ústrr   r   Úintr   Úboolr   r   r   r   r   r   r   r   r
   Úclassmethodr   r'   r   Úfloatr?   rF   r3   ó    r&   r   r      s4  … ñð. ƒKð !€Eˆ3Ó ØØ&*Ðh˜s‘mÓ*ð.à€IˆtÓØ2Ø26Ð  (¨3¡-Ó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	y)	Ú$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                 óR  — 	 ddl m}m}m} |j                  |«      |j                  | j                  | j                  | j                  | j                  dœ} |di |¤Ž}| j                  j                  || j                  ¬«      }|j                  S # t        $ r t	        d«      ‚w xY w)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¶   € ð
	÷ñ ð ×&Ñ& tÓ,Ø4×>Ñ>Ø $× 5Ñ 5ØŸ™Ø,0×,MÑ,MØ$(×$=Ñ$=ñ
ˆñ 1Ñ@°<Ñ@ˆØŸ™×3Ñ3Ø!¨¯©ð 4ó 
ˆð ×'Ñ'Ð'øô' ò 	ÜðKóð ð	úrG   r(   c                 óX   — g }|D ]"  }|j                  | j                  |«      «       Œ$ |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é   s6   € ð !Ðàò 	:ˆDØ×&Ñ& t§{¡{°4Ó'8Õ9ð	:à"Ð"rR   c                 ó$   — | j                  |«      S )rA   )rZ   )r9   r;   s     r&   rF   z0AlephAlphaSymmetricSemanticEmbedding.embed_queryø   s   € ð {‰{˜4Ó Ð rR   N)
rH   rI   rJ   rK   rM   r   rQ   rZ   r?   rF   r3   rR   r&   rT   rT   º   sU   „ ñð$(˜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      s4   ðß ,Ó ,å 0Ý 5ß /ôo,¨I°zô o,ôdF!Ð+Põ F!rR   