
    dh                         S SK r S SKJrJrJrJrJr  S SKrS SKJ	r	  S SK
Jr  S SKJrJr  \ R                  " \5      r\	" SSSS	9 " S
 S\\5      5       rg)    N)AnyDictListMappingOptional)
deprecated)
Embeddings)	BaseModel
ConfigDictz0.3.1z1.0.0z!langchain_ollama.OllamaEmbeddings)sinceremovalalternative_importc                      \ rS rSr% SrSr\\S'    Sr\\S'    Sr	\\S'    S	r
\\S
'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\\      \S'    Sr\\   \S'    Sr\\   \S'    Sr\\   \S'    Sr\\S'    Sr\\   \S'    \ S\!\\"4   4S j5       r#Sr$\\   \S'    \ S\%\\"4   4S j5       r&\'" S S!S"9r(S#\S\\   4S$ jr)S#\\   S\\\      4S% jr*S&\\   S\\\      4S' jr+S(\S\\   4S) jr,S!r-g)*OllamaEmbeddings   aS  Ollama locally runs large language models.

To use, follow the instructions at https://ollama.ai/.

Example:
    .. code-block:: python

        from langchain_community.embeddings import OllamaEmbeddings
        ollama_emb = OllamaEmbeddings(
            model="llama:7b",
        )
        r1 = ollama_emb.embed_documents(
            [
                "Alpha is the first letter of Greek alphabet",
                "Beta is the second letter of Greek alphabet",
            ]
        )
        r2 = ollama_emb.embed_query(
            "What is the second letter of Greek alphabet"
        )

zhttp://localhost:11434base_urlllama2modelz	passage: embed_instructionzquery: query_instructionNmirostatmirostat_etamirostat_taunum_ctxnum_gpu
num_threadrepeat_last_nrepeat_penaltytemperaturestoptfs_ztop_ktop_pFshow_progressheadersreturnc                 @   U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S.S.$ )z.Get the default parameters for calling Ollama.)r   r   r   r   r   r   r   r   r   r    r!   r"   r#   )r   options)r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   selfs    ]/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/embeddings/ollama.py_default_params OllamaEmbeddings._default_paramsx   s     ZZ MM $ 1 1 $ 1 1<<<<"oo!%!3!3"&"5"5#//		
 	
    model_kwargsc                 :    0 SU R                   0EU R                  E$ )zGet the identifying parameters.r   )r   r,   r)   s    r+   _identifying_params$OllamaEmbeddings._identifying_params   s$     A7DJJ'@4+?+?@@r.   forbid )extraprotected_namespacesinputc                 2   SS0U R                   =(       d    0 En [        R                  " U R                   S3UU R                  US.U R
                  ES9nUR                  S:w  a'  [        S	UR                  < S
UR                  < 35      e UR                  5       nUS   $ ! [        R                  R                   a  n[        SU 35      eSnAff = f! [        R                  R                   a   n[        SU SUR                   35      eSnAff = f)z}Process a response from the API.

Args:
    response: The response from the API.

Returns:
    The response as a dictionary.
zContent-Typezapplication/jsonz/api/embeddings)r   prompt)r%   jsonz$Error raised by inference endpoint: N   z)Error raised by inference API HTTP code: z, 	embeddingzError raised by inference API: z.
Response: )r%   requestspostr   r   r,   
exceptionsRequestException
ValueErrorstatus_codetextr:   JSONDecodeError)r*   r7   r%   resets         r+   _process_emb_response&OllamaEmbeddings._process_emb_response   s    .
||!r

	I--==/1#zzUSd>R>RSC ??c!??CHH. 	
A[>! ""33 	ICA3GHH	I ""22 	1!M#((L 	s/   <B$ C $CCCD6DDc                     U R                   (       a   SSKJn  U" USS9nOUnU Vs/ sH  o@R                  U5      PM     sn$ ! [         a    [        R	                  S5        Un NCf = fs  snf )Nr   )tqdmr   )desczgUnable to show progress bar because tqdm could not be imported. Please install with `pip install tqdm`.)r$   rK   ImportErrorloggerwarningrH   )r*   r7   rK   iter_r9   s        r+   _embedOllamaEmbeddings._embed   ss    	%U);< EAFGv**62GG  >  Hs   A A*!A'&A'textsc                 n    U Vs/ sH  o R                    U 3PM     nnU R                  U5      nU$ s  snf )zEmbed documents using an Ollama deployed embedding model.

Args:
    texts: The list of texts to embed.

Returns:
    List of embeddings, one for each text.
)r   rQ   )r*   rS   rC   instruction_pairs
embeddingss        r+   embed_documents OllamaEmbeddings.embed_documents   sD     LQQ54 6 67v>5Q[[!23
 Rs   2rC   c                 P    U R                    U 3nU R                  U/5      S   nU$ )zEmbed a query using a Ollama deployed embedding model.

Args:
    text: The text to embed.

Returns:
    Embeddings for the text.
r   )r   rQ   )r*   rC   instruction_pairr<   s       r+   embed_queryOllamaEmbeddings.embed_query   s7     #445dV<KK!1 23A6	r.   ).__name__
__module____qualname____firstlineno____doc__r   str__annotations__r   r   r   r   r   intr   floatr   r   r   r   r   r   r   r    r   r!   r"   r#   r$   boolr%   dictpropertyr   r   r,   r/   r   r1   r   model_configrH   rQ   rW   r[   __static_attributes__r4   r.   r+   r   r      sP   . -Hc,-E3(s(.&s&."Hhsm"B %)L(5/(5
 %)L(5/(% "GXc]!$ "GXc]!+ !%J$N
 $(M8C='= '+NHUO*, $(K%'= !%D(49
$&!E8E?!M  E8C=0 "E8E?!C  M4J"GXd^"
 
c3h 
 
* $(L(4.'"AWS#X%6 A A H2FL"3 "4; "HHDI H$tE{*; H T#Y 4U3D  U r.   r   )loggingtypingr   r   r   r   r   r=   langchain_core._api.deprecationr   langchain_core.embeddingsr	   pydanticr
   r   	getLoggerr]   rN   r   r4   r.   r+   <module>rq      sX     5 5  6 0 *			8	$ 
:
Sy* S
Sr.   