
    g3fi%                        U d Z ddlZddlZddlmZ ddlmZ ddlmZ de	e   dedefd	Z
d
de
fddd fdde
fdde
fdde
fddd fdde
fdde
fd
de
fd	Zeeeeeedef   f   f   ed<   	  ej                    ee             d!ededef   fd"       Zdefd#Zd$edeeef   fd%Zdd&d'ed!edz  deeef   fd(Zdd&d'ed!edz  dedefd)Zd*d+gZy),z!Factory functions for embeddings.    N)Callable)Any)
Embeddingsclskwargsreturnc                      | di |S )N r
   )r   r   s     W/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain/embeddings/base.py_callr      s    ==    langchain_openaiAzureOpenAIEmbeddingslangchain_awsBedrockEmbeddingsc                      | dd|i|S )Nmodel_idr
   r
   r   modelr   s      r   <lambda>r      s    S%B%%B6%B r   langchain_cohereCohereEmbeddingslangchain_google_genaiGoogleGenerativeAIEmbeddingslangchain_google_vertexaiVertexAIEmbeddingslangchain_huggingfaceHuggingFaceEmbeddingsc                      | dd|i|S )N
model_namer
   r
   r   s      r   r   r      s    S%DE%DV%D r   langchain_mistralaiMistralAIEmbeddingslangchain_ollamaOllamaEmbeddingsOpenAIEmbeddings)	azure_openaibedrockcoheregoogle_genaigoogle_vertexaihuggingface	mistralaiollamaopenai._SUPPORTED_PROVIDERS)maxsizeproviderc                 D   | t         vrd|  dt                }t        |      t         |    \  }}}	 t        j                  |      }t        ||      }t        j                  ||	      S # t
        $ r,}|j                  dd      }d| d| d}t        |      |d}~ww xY w)
aP  Return a factory function that creates an embeddings model for the given provider.

    This function is cached to avoid repeated module imports.

    Args:
        provider: The name of the model provider (e.g., `'openai'`, `'cohere'`).

            Must be a key in `_SUPPORTED_PROVIDERS`.

    Returns:
        A callable that accepts model kwargs and returns an `Embeddings` instance for
            the specified provider.

    Raises:
        ValueError: If the provider is not in `_SUPPORTED_PROVIDERS`.
        ImportError: If the provider's integration package is not installed.
    
Provider 'E' is not supported.
Supported providers and their required packages:
_-zCould not import z5 python package. Please install it with `pip install `N)r   )
r/   _get_provider_list
ValueError	importlibimport_moduleImportErrorreplacegetattr	functoolspartial)	r1   msgmodule_name
class_namecreator_funcmoduleepkgr   s	            r   _get_embeddings_class_creatorrH   ,   s    & ++
 #A!#$& 	
 o,@,J)K\&((5 &*
%C\s33  &!!#s+!#&[\_[``ab#A%&s   A* *	B3'BBc                  V    dj                  d t        j                         D              S )z3Get formatted list of providers and their packages.
c              3   X   K   | ]"  \  }}d | d|d   j                  dd        $ yw)z  - z: r   r5   r6   N)r=   ).0prG   s      r   	<genexpr>z%_get_provider_list.<locals>.<genexpr>U   s6      391c$qcCFNN3,-.s   (*)joinr/   itemsr
   r   r   r8   r8   S   s)    99 =Q=W=W=Y  r   r    c                 F   d| vr%d|  dt         j                          }t        |      | j                  dd      \  }}|j	                         j                         }|j                         }|t         vrd| dt                }t        |      |sd}t        |      ||fS )a  Parse a model string into provider and model name components.

    The model string should be in the format 'provider:model-name', where provider
    is one of the supported providers.

    Args:
        model_name: A model string in the format 'provider:model-name'

    Returns:
        A tuple of (provider, model_name)

    ```python
    _parse_model_string("openai:text-embedding-3-small")
    # Returns: ("openai", "text-embedding-3-small")

    _parse_model_string("bedrock:amazon.titan-embed-text-v1")
    # Returns: ("bedrock", "amazon.titan-embed-text-v1")
    ```

    Raises:
        ValueError: If the model string is not in the correct format or
            the provider is unsupported

    :zInvalid model format 'z'.
Model name must be in format 'provider:model-name'
Example valid model strings:
  - openai:text-embedding-3-small
  - bedrock:amazon.titan-embed-text-v1
  - cohere:embed-english-v3.0
Supported providers:    r3   r4   Model name cannot be empty)r/   keysr9   splitlowerstripr8   )r    rA   r1   r   s       r   _parse_model_stringrY   Z   s    2 *$ZL 1$ %9$=$=$?#@B 	 o &&sA.OHe~~%%'HKKME++
 #A!#$& 	
 o*oU?r   r1   r   c                    | j                         sd}t        |      |d| v rt        |       \  }}n| }|s"dt        j	                          }t        |      |t        vrd| dt                }t        |      ||fS )NrT   rR   zMust specify either:
1. A model string in format 'provider:model-name'
   Example: 'openai:text-embedding-3-small'
2. Or explicitly set provider from: r3   r4   )rX   r9   rY   r/   rU   r8   )r   r1   rA   r    s       r   _infer_model_and_providerr\      s    
 ;;=*oC5L259*
3 $((*+	- 	 o++
 #A!#$& 	
 oZr   c                    | s3t         j                         }ddj                  |       }t        |      t	        | |      \  }} t        |      dd|i|S )ap  Initialize an embedding model from a model name and optional provider.

    !!! note
        Requires the integration package for the chosen model provider to be installed.

        See the `model_provider` parameter below for specific package names
        (e.g., `pip install langchain-openai`).

        Refer to the [provider integration's API reference](https://docs.langchain.com/oss/python/integrations/providers)
        for supported model parameters to use as `**kwargs`.

    Args:
        model: The name of the model, e.g. `'openai:text-embedding-3-small'`.

            You can also specify model and model provider in a single argument using
            `'{model_provider}:{model}'` format, e.g. `'openai:text-embedding-3-small'`.
        provider: The model provider if not specified as part of the model arg
            (see above).

            Supported `provider` values and the corresponding integration package
            are:

            - `openai`                  -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
            - `azure_openai`            -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
            - `bedrock`                 -> [`langchain-aws`](https://docs.langchain.com/oss/python/integrations/providers/aws)
            - `cohere`                  -> [`langchain-cohere`](https://docs.langchain.com/oss/python/integrations/providers/cohere)
            - `google_vertexai`         -> [`langchain-google-vertexai`](https://docs.langchain.com/oss/python/integrations/providers/google)
            - `huggingface`             -> [`langchain-huggingface`](https://docs.langchain.com/oss/python/integrations/providers/huggingface)
            - `mistralai`               -> [`langchain-mistralai`](https://docs.langchain.com/oss/python/integrations/providers/mistralai)
            - `ollama`                  -> [`langchain-ollama`](https://docs.langchain.com/oss/python/integrations/providers/ollama)

        **kwargs: Additional model-specific parameters passed to the embedding model.

            These vary by provider. Refer to the specific model provider's
            [integration reference](https://reference.langchain.com/python/integrations/)
            for all available parameters.

    Returns:
        An `Embeddings` instance that can generate embeddings for text.

    Raises:
        ValueError: If the model provider is not supported or cannot be determined
        ImportError: If the required provider package is not installed

    ???+ example

        ```python
        # pip install langchain langchain-openai

        # Using a model string
        model = init_embeddings("openai:text-embedding-3-small")
        model.embed_query("Hello, world!")

        # Using explicit provider
        model = init_embeddings(model="text-embedding-3-small", provider="openai")
        model.embed_documents(["Hello, world!", "Goodbye, world!"])

        # With additional parameters
        model = init_embeddings("openai:text-embedding-3-small", api_key="sk-...")
        ```

    !!! version-added "Added in `langchain` 0.3.9"

    z2Must specify model name. Supported providers are: z, rZ   r   r
   )r/   rU   rO   r9   r\   rH   )r   r1   r   	providersrA   r    s         r   init_embeddingsr_      sb    L (--/	B499YCWBXYo4UXNHj2(2NNvNNr   r   r_   )__doc__r?   r:   collections.abcr   typingr   langchain_core.embeddingsr   typer   r/   dictstrtuple__annotations__	lru_cachelenrH   r8   rY   r\   r_   __all__r
   r   r   <module>rl      s   '   $  0tJ 3 : 
 ()@%HB
 "#5u=-/MuU35I5QD
 ()>F!#5u=!#5u=#O d3c3j0I&I JJK & S!567#4C #4HS*_4M #4 8#4LC 3C 3E#s(O 3r     Dj  38_	 H  LOLO DjLO 	LO
 LO` r   