a
    bg~                     @   s~   d dl Z d dlZ d dlmZmZmZmZmZmZm	Z	 d dl
Zd dlmZ d dlmZ d dlmZmZ dZG dd deeZdS )	    N)AnyDictListLiteralOptionalSequencecast)
Embeddings)pre_init)	BaseModel
ConfigDictz0.2.0c                   @   s   e Zd ZU dZ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d
 ed< dZeed< dZe
e ed< dZe
ee  ed< dZeed< edddZeeedddZee eee  dddZeee dddZdS )FastEmbedEmbeddingsa  Qdrant FastEmbedding models.

    FastEmbed is a lightweight, fast, Python library built for embedding generation.
    See more documentation at:
    * https://github.com/qdrant/fastembed/
    * https://qdrant.github.io/fastembed/

    To use this class, you must install the `fastembed` Python package.

    `pip install fastembed`
    Example:
        from langchain_community.embeddings import FastEmbedEmbeddings
        fastembed = FastEmbedEmbeddings()
    zBAAI/bge-small-en-v1.5
model_namei   
max_lengthN	cache_dirthreadsdefault)r   passagedoc_embed_type   
batch_sizeparallel	providersmodelZallow )extraZprotected_namespaces)valuesreturnc           	      C   s   | d}| d}| d}| d}| d}|rBd|v rBdnd}ztd}W n" tyv   td	| d
Y n0 tj|tk rtd| dt d|j|||||d|d< |S )z+Validate that FastEmbed has been installed.r   r   r   r   r   ZCUDAExecutionProviderzfastembed-gpu	fastembedzQCould not import 'fastembed' Python package. Please install it with `pip install z`.z.FastEmbedEmbeddings requires `pip install -U "z>=z"`.)r   r   r   r   r   r   )	get	importlibimport_moduleModuleNotFoundErrorImportErrormetadataversionMIN_VERSIONZTextEmbedding)	clsr   r   r   r   r   r   Zpkg_to_installr   r   r   v/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/embeddings/fastembed.pyvalidate_environmentP   sF    






z(FastEmbedEmbeddings.validate_environment)textsr   c                 C   sF   | j dkr"| jj|| j| jd}n| jj|| j| jd}dd |D S )zGenerate embeddings for documents using FastEmbed.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        r   r   r   c                 S   s   g | ]}t tt | qS r   )r   r   floattolist).0er   r   r(   
<listcomp>       z7FastEmbedEmbeddings.embed_documents.<locals>.<listcomp>)r   r   Zpassage_embedr   r   Zembed)selfr*   Z
embeddingsr   r   r(   embed_documentsv   s    



z#FastEmbedEmbeddings.embed_documents)textr   c                 C   s,   t | jj|| j| jd}ttt | S )zGenerate query embeddings using FastEmbed.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r+   )	nextr   Zquery_embedr   r   r   r   r,   r-   )r2   r4   Zquery_embeddingsr   r   r(   embed_query   s    	
zFastEmbedEmbeddings.embed_query)__name__
__module____qualname____doc__r   str__annotations__r   intr   r   r   r   r   r   r   r   r   r   r   r   Zmodel_configr
   r   r)   r   r,   r3   r6   r   r   r   r(   r      s   
%r   )r    importlib.metadatatypingr   r   r   r   r   r   r   numpynpZlangchain_core.embeddingsr	   Zlangchain_core.utilsr
   Zpydanticr   r   r&   r   r   r   r   r(   <module>   s   $