Ë
    kQêj-  ã                   ó€   — d dl Z d dlmZmZ d dlZddlmZ ddlm	Z	 ddl
mZ ddlmZ  ed	«       G d
„ de	«      «       Zy)é    N)ÚListÚUnioné   )Úattempt_import_or_raiseé   )ÚTextEmbeddingFunction)Úregister)Úweak_lruzgte-textc                   óÞ   ‡ — e Zd ZU dZdZeed<   dZeed<   dZe	ed<   dZ
e	ed	<   ˆ fd
„Zed„ «       Zd„ Zdeee   ej$                  f   deej&                     fd„Z ed¬«      d„ «       Zˆ xZS )ÚGteEmbeddingsa±  
    Deprecated: GTE embeddings should be used through sentence-transformers.

    An embedding function that uses GTE-LARGE MLX format(for Apple silicon devices only)
    as well as the standard cpu/gpu version from: https://huggingface.co/thenlper/gte-large.

    For Apple users, you will need the mlx package installed, which can be done with:
        pip install mlx

    Parameters
    ----------
    name : str, default "thenlper/gte-large"
        The name of the model to use.
    device : str, default "cpu"
        Sets the device type for the model.
    normalize : str, default "True"
        Controls normalize param in encode function for the transformer.
    mlx : bool, default False
        Controls which model to use. False for gte-large,True for the mlx version.

    Examples
    --------
    import lancedb
    import lancedb.embeddings.gte
    from lancedb.embeddings import get_registry
    from lancedb.pydantic import LanceModel, Vector
    import pandas as pd

    model = get_registry().get("gte-text").create() # mlx=True for Apple silicon
    class TextModel(LanceModel):
        text: str = model.SourceField()
        vector: Vector(model.ndims()) = model.VectorField()

    df = pd.DataFrame({"text": ["hi hello sayonara", "goodbye world"]})
    db = lancedb.connect("~/.lancedb")
    tbl = db.create_table("test", schema=TextModel, mode="overwrite")

    tbl.add(df)
    rs = tbl.search("hello").limit(1).to_pandas()

    zthenlper/gte-largeÚnameÚcpuÚdeviceTÚ	normalizeFÚmlxc                 óÊ   •— t        ‰| �  di |¤Ž t        j                  dt        d¬«       d | _        |r.|j                  dd«      | _        | j                  du rd| _        y y y )	NzŽGTE embeddings as a standalone embedding function are deprecated. Use the 'sentence-transformers' embedding function with a GTE model instead.é   )Ú
stacklevelr   FTzgte-mlx© )	ÚsuperÚ__init__ÚwarningsÚwarnÚDeprecationWarningÚ_ndimsÚgetr   r   )ÚselfÚkwargsÚ	__class__s     €ú[/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/embeddings/gte.pyr   zGteEmbeddings.__init__A   sg   ø€ Ü‰ÑÑ"˜6Ò"Ü�‰ðô Øõ	
ð ˆŒÙØ—z‘z %¨Ó/ˆDŒHØ�x‰x˜4ÑØ%�•	ð  ð ó    c                 ó"   — | j                  «       S )ú£
        Get the embedding model specified by the flag,
        name and device. This is cached so that the model is only loaded
        once per process.
        )Úget_embedding_model©r   s    r    Úembedding_modelzGteEmbeddings.embedding_modelP   s   € ð ×'Ñ'Ó)Ð)r!   c                 óÈ   — | j                   du r| j                  j                  | _        | j                  €"t	        | j                  d«      d   «      | _        | j                  S )NTÚfoor   )r   r&   Údimsr   ÚlenÚgenerate_embeddingsr%   s    r    ÚndimszGteEmbeddings.ndimsY   sQ   € Ø�8‰8�tÑØ×.Ñ.×3Ñ3ˆDŒKØ�;‰;ÐÜ˜d×6Ñ6°uÓ=¸aÑ@ÓAˆDŒKØ�{‰{Ðr!   ÚtextsÚreturnc                 ó   — | j                   du r2| j                  j                  t        |«      «      j	                  «       S | j                  j                  t        |«      d| j                  ¬«      j	                  «       S )z¯
        Get the embeddings for the given texts.

        Parameters
        ----------
        texts: list[str] or np.ndarray (of str)
            The texts to embed
        T)Úconvert_to_numpyÚnormalize_embeddings)r   r&   ÚrunÚlistÚtolistÚencoder   )r   r-   s     r    r+   z!GteEmbeddings.generate_embeddings`   sl   € ð �8‰8�tÑØ×'Ñ'×+Ñ+¬D°«KÓ8×?Ñ?ÓAÐAà×#Ñ#×*Ñ*Ü�‹KØ!Ø!%§¡ð +ó 
÷ ‰&‹(ð		r!   r   )Úmaxsizec                 óž   — | j                   du rddlm}  |«       S t        dd«      }|j	                  | j
                  | j                  ¬«      S )r#   Tr   )ÚModelÚsentence_transformerszsentence-transformers)r   )r   Úgte_mlx_modelr8   r   ÚSentenceTransformerr   r   )r   r8   r9   s      r    r$   z!GteEmbeddings.get_embedding_modelt   sR   € ð �8‰8�tÑÝ,á“7ˆNä$;Ø'Ð)@ó%Ð!ð )×<Ñ<Ø—	‘	 $§+¡+ð =ó ð r!   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚ__annotations__r   r   Úboolr   r   Úpropertyr&   r,   r   r   ÚnpÚndarrayÚarrayr+   r
   r$   Ú__classcell__)r   s   @r    r   r      s™   ø… ñ(ðT %€Dˆ#Ó$Ø€FˆCÓØ€IˆtÓØ€CˆÓô&ð ñ*ó ð*òðØ˜4 ™9 b§j¡jÐ0Ñ1ðà	ˆb�h‰h‰óñ( �aÔñó ôr!   r   )r   Útypingr   r   ÚnumpyrD   Úutilr   Úbaser   Úregistryr	   Úutilsr
   r   r   r!   r    ú<module>rN      s@   ðó
 ß ã å *Ý 'Ý Ý ñ 
ˆ*ÓôtÐ)ó tó ñtr!   