
    Ig                     `    d dl mZmZmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ  G d dee      Zy)    )AnyListOptional)
Embeddings)	BaseModel
ConfigDictFieldmodel_validator)Selfc                   2   e Zd ZU dZdZeed<   eed<    edd      Z	e
ed<   	  edd	      Ze
ed	<   	  edd
      Ze
ed
<   	  edd      Zeed<   	  edd      Zeed<   	  edd      Zeed<   	  edd      Zeed<   	  edd      Zee
   ed<   	  edd      Zee
   ed<   	  edd      Zee
   ed<   	  edd      Zeed<   	  edd      Zee   ed<   	  edd      Z ed      defd       Zdee   deee      fdZdedee   fd Z y)!LlamaCppEmbeddingsa  llama.cpp embedding models.

    To use, you should have the llama-cpp-python library installed, and provide the
    path to the Llama model as a named parameter to the constructor.
    Check out: https://github.com/abetlen/llama-cpp-python

    Example:
        .. code-block:: python

            from langchain_community.embeddings import LlamaCppEmbeddings
            llama = LlamaCppEmbeddings(model_path="/path/to/model.bin")
    Nclient
model_pathi   n_ctx)aliasn_partsseedFf16_kv
logits_all
vocab_only	use_mlock	n_threadsn_batchn_gpu_layersTverbosedeviceforbid )extraprotected_namespacesafter)modereturnc                 2   | j                   }g d}|D ci c]  }|t        | |       }}| j                  | j                  |d<   	 ddlm}  ||fddi|| _        | S c c}w # t        $ r t        d      t        $ r}t        d	| d
|       d}~ww xY w)z4Validate that llama-cpp-python library is installed.)r   r   r   r   r   r   r   r   r   r   r   Nr   r   )Llama	embeddingTzCould not import llama-cpp-python library. Please install the llama-cpp-python library to use this embedding model: pip install llama-cpp-pythonz&Could not load Llama model from path: z. Received error )	r   getattrr   	llama_cppr&   r   ImportError	Exception
ValueError)selfr   model_param_nameskmodel_paramsr&   es          d/var/www/html/answerous/venv/lib/python3.12/site-packages/langchain_community/embeddings/llamacpp.pyvalidate_environmentz'LlamaCppEmbeddings.validate_environmentE   s     __

 6GG74++GG(+/+<+<L(	'
KdKlKDK + H  	I 
  	8 E""#& 	s   AA$ $B BBtextsc           
          | j                   j                  |      }|d   D cg c]  }t        t        t        |d                 c}S c c}w )zEmbed a list of documents using the Llama model.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        datar'   )r   create_embeddinglistmapfloat)r-   r4   
embeddingsr1   s       r2   embed_documentsz"LlamaCppEmbeddings.embed_documentsm   sA     [[11%8
:DV:LMQS+/0MMMs   #A	textc                 j    | j                   j                  |      }t        t        t        |            S )zEmbed a query using the Llama model.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        )r   embedr8   r9   r:   )r-   r=   r'   s      r2   embed_queryzLlamaCppEmbeddings.embed_queryy   s*     KK%%d+	Cy)**    )!__name__
__module____qualname____doc__r   r   __annotations__strr	   r   intr   r   r   boolr   r   r   r   r   r   r   r   r   r   model_configr
   r   r3   r   r:   r<   r@   r   rA   r2   r   r      s    FCOs'*E3*9-GS-? b'D#'-h/FD/1U,7J7@U,7J7/E5It5,$T=Ix}=/ #3i8GXc]8/ #(N"CL(3-CF$i0GT0)!$h7FHSM72L
 '"%d % #%N
NT#Y 
N4U3D 
N
+ 
+U 
+rA   r   N)typingr   r   r   langchain_core.embeddingsr   pydanticr   r   r	   r
   typing_extensionsr   r   r   rA   r2   <module>rO      s'    & & 0 B B "{+J {+rA   