
    ug                     x    d dl Z d dlmZmZ d dlZd dlmZmZmZ  e j                  e
      Z G d dee         Zy)    N)Unioncast)	DocumentsEmbeddingFunction
Embeddingsc                   >    e Zd ZdZdededdfdZdeeef   defdZ	y)	OllamaEmbeddingFunctionz
    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).
    url
model_namereturnNc                 T    | | _         || _        t        j                         | _        y)a  
        Initialize the Ollama Embedding Function.

        Args:
            url (str): The URL of the Ollama Server.
            model_name (str): The name of the model to use for text embeddings. E.g. "nomic-embed-text" (see https://ollama.com/library for available models).
        N)_api_url_model_namehttpxClient_session)selfr
   r   s      q/var/www/openai/venv/lib/python3.12/site-packages/chromadb/utils/embedding_functions/ollama_embedding_function.py__init__z OllamaEmbeddingFunction.__init__   s"     %%    inputc           	      (   t        |t              r|n|g}|D cg c]D  }| j                  j                  | j                  | j
                  |d      j                         F }}t        t        |D cg c]  }d|v r|d    c}      S c c}w c c}w )a  
        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(url="http://localhost:11434/api/embeddings", model_name="nomic-embed-text")
            >>> texts = ["Hello, world!", "How are you?"]
            >>> embeddings = ollama_ef(texts)
        )modelprompt)json	embedding)	
isinstancelistr   postr   r   r   r   r   )r   r   textstext
embeddingsr   s         r   __call__z OllamaEmbeddingFunction.__call__   s      $E40ug
 	
  MMd.>.>$$O  df 	 	 
  ",!+I)+ +&!+
 	

s   A	B
3B
)
__name__
__module____qualname____doc__strr   r   r   r   r#    r   r   r	   r	      s=    
'C 
'S 
'T 
'
eIsN3 

 
r   r	   )loggingtypingr   r   r   chromadb.api.typesr   r   r   	getLoggerr$   loggerr	   r)   r   r   <module>r/      s8       G G			8	$/
/	: /
r   