
    3i                     p    S SK JrJrJrJr  S SKJr  S SKJrJ	r	J
r
  S SKrS SKJr  Sr " S S\\   5      rg)	    )
Embeddings	DocumentsEmbeddingFunctionSpacevalidate_config_schema)ListDictAnyN)urlparsezchroma/all-minilm-l6-v2-f32c            	          \ rS rSrSrS\S4S\S\S\SS	4S
 jjrS\	S\
4S jr\S\4S j5       rS\4S jrS\\   4S jr\S\\\4   SS4S j5       rS\\\4   4S jrS\\\4   S\\\4   SS	4S jr\S\\\4   SS	4S j5       rSrg	)OllamaEmbeddingFunction
   z
This class is used to generate embeddings for a list of texts using the Ollama Embedding API
(https://github.com/ollama/ollama/blob/main/docs/api.md#generate-embeddings).
zhttp://localhost:11434<   url
model_nametimeoutreturnNc                 6    SSK Jn  Xl        X l        X0l        Xl        U R                  R                  S5      (       a+  [        U5      nUR                   SUR                   3U l        U" U R                  US9U l        g! [         a    [        S5      ef = f)a  
Initialize the Ollama Embedding Function.

Args:
    url (str): The Base URL of the Ollama Server (default: "http://localhost:11434").
    model_name (str): The name of the model to use for text embeddings.
        Defaults to "chroma/all-minilm-l6-v2-f32", for available models see https://ollama.com/library.
    timeout (int): The timeout for the API call in seconds. Defaults to 60.
r   )ClientzWThe ollama python package is not installed. Please install it with `pip install ollama`z/api/embeddingsz://)hostr   N)ollamar   ImportError
ValueErrorr   r   r   	_base_urlendswithr   schemenetloc_client)selfr   r   r   r   
parsed_urls         v/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/utils/embedding_functions/ollama_embedding_function.py__init__ OllamaEmbeddingFunction.__init__   s    	% $ >>""#455!#J * 1 12#j6G6G5HIDN4>>7C  	i 	s   B Binputc                     U R                   R                  U R                  US9nUS    Vs/ s H&  n[        R                  " U[        R
                  S9PM(     sn$ s  snf )a6  
Get the embeddings for a list of texts.

Args:
    input (Documents): A list of texts to get embeddings for.

Returns:
    Embeddings: The embeddings for the texts.

Example:
    >>> ollama_ef = OllamaEmbeddingFunction()
    >>> texts = ["Hello, world!", "How are you?"]
    >>> embeddings = ollama_ef(texts)
)modelr%   
embeddings)dtype)r   embedr   nparrayfloat32)r    r%   response	embeddings       r"   __call__ OllamaEmbeddingFunction.__call__2   s\      <<%%DOO5%I
 &l3
3	 HHYbjj13
 	
 
s   -Ac                      g)Nr    r3       r"   nameOllamaEmbeddingFunction.nameJ   s    r4   c                     g)Ncosiner3   r    s    r"   default_space%OllamaEmbeddingFunction.default_spaceN   s    r4   c                 
    / SQ$ )N)r8   l2ipr3   r9   s    r"   supported_spaces(OllamaEmbeddingFunction.supported_spacesQ   s    %%r4   configzEmbeddingFunction[Documents]c                     U R                  S5      nU R                  S5      nU R                  S5      nUb  Ub  Uc   S5       e[        XUS9$ )Nr   r   r   zThis code should not be reachedr   r   r   )getr   )rA   r   r   r   s       r"   build_from_config)OllamaEmbeddingFunction.build_from_configT   sR    jjZZ-
**Y';*,;;;5&3wWWr4   c                 J    U R                   U R                  U R                  S.$ )NrC   rC   r9   s    r"   
get_config"OllamaEmbeddingFunction.get_config_   s    xxt4<<XXr4   
old_config
new_configc                 &    SU;   a  [        S5      eg )Nr   zSThe model name cannot be changed after the embedding function has been initialized.)r   )r    rJ   rK   s      r"   validate_config_update.OllamaEmbeddingFunction.validate_config_updateb   s!     :%e  &r4   c                     [        U S5        g)z
Validate the configuration using the JSON schema.

Args:
    config: Configuration to validate

Raises:
    ValidationError: If the configuration does not match the schema
r   Nr   )rA   s    r"   validate_config'OllamaEmbeddingFunction.validate_configj   s     	vx0r4   )r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__DEFAULT_MODEL_NAMEstrintr#   r   r   r0   staticmethodr5   r   r:   r	   r?   r
   r   rE   rH   rM   rP   __static_attributes__r3   r4   r"   r   r   
   s)    ,,	 D D  D 	 D
 
 DD
i 
J 
0 #  u &$u+ & X$sCx. X5S X XYDcN YsCx.6:38n	 
1S#X 
14 
1 
1r4   r   )chromadb.api.typesr   r   r   r   *chromadb.utils.embedding_functions.schemasr   typingr	   r
   r   numpyr+   urllib.parser   rW   r   r3   r4   r"   <module>ra      s4    N N M " "  !2 k1/	: k1r4   