
    Y%h                         d dl Z d dlmZmZmZmZmZ d dlmZ d dl	m
Z
 ddlmZmZ d dlmZ d dlmZmZ dd	lmZmZmZ  e j2                  e      Z	  G d
 de      Zy)    N)OptionalDictListUnionAny)	ApiClient)InferenceApi   )EmbeddingsListRerankResult)API_VERSION)setup_openapi_clientPluginAware)InferenceRequestBuilder
EmbedModelRerankModelc                       e Zd ZdZeZeZddZ	 dde	ee
f   de	e
ee   ee
   f   deee
ef      defdZd	gd
ddfde	ee
f   de
de	ee
   eee
ef      f   dee
   dedee   deee
ef      defdZy)	Inferencea  
    The `Inference` class configures and uses the Pinecone Inference API to generate embeddings and
    rank documents.

    It is generally not instantiated directly, but rather accessed through a parent `Pinecone` client
    object that is responsible for managing shared configurations.

    ```python
    from pinecone import Pinecone

    pc = Pinecone()
    embeddings = pc.inference.embed(
        model="text-embedding-3-small",
        inputs=["Hello, world!"],
        parameters={"input_type": "passage", "truncate": "END"}
    )
    ```

    :param config: A `pinecone.config.Config` object, configured and built in the Pinecone class.
    :type config: `pinecone.config.Config`, required
    returnNc           
         || _         	 || _        	 |j                  dd      | _        	 t	        t
        t        |||j                  dd      t              | _        | j                  | j                   | j                  | j                         y )Npool_threadsr
   )api_client_klass	api_klassconfigopenapi_configr   api_version)r   r   r   )
r   r   getr   r   r   r	   r   _Inference__inference_apiload_plugins)selfr   r   kwargss       /var/www/pru.catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/data/features/inference/inference.py__init__zInference.__init__/   s    ,"JJ~q93&")NA6# 
 	;;t/B/BQUQbQb 	 	
    modelinputs
parametersc                     t        j                  |||      }| j                  j                  |      }t	        |      S )a*  
        Generates embeddings for the provided inputs using the specified model and (optional) parameters.

        :param model: The model to use for generating embeddings.
        :type model: str, required

        :param inputs: A list of items to generate embeddings for.
        :type inputs: list, required

        :param parameters: A dictionary of parameters to use when generating embeddings.
        :type parameters: dict, optional

        :return: EmbeddingsList object with keys `data`, `model`, and `usage`. The `data` key contains a list of
        `n` embeddings, where `n` = len(inputs) and type(n) = Embedding. Precision of returned embeddings is either
        float16 or float32, with float32 being the default. `model` key is the model used to generate the embeddings.
        `usage` key contains the total number of tokens used at request-time.

        Example:
        >>> inputs = ["Who created the first computer?"]
        >>> outputs = pc.inference.embed(model="multilingual-e5-large", inputs=inputs, parameters={"input_type": "passage", "truncate": "END"})
        >>> print(outputs)
        EmbeddingsList(
            model='multilingual-e5-large',
            data=[
                {'values': [0.1, ...., 0.2]},
              ],
            usage={'total_tokens': 6}
        )
        )r%   r&   r'   )embed_request)r   r)   r   embedr   )r    r%   r&   r'   request_bodyresps         r"   r*   zInference.embedF   sB    F /<<:
 ##)))Ed##r$   textTquery	documentsrank_fieldsreturn_documentstop_nc           	          t        j                  |||||||      }| j                  j                  |      }	t        |	      S )a	  
        Rerank documents with associated relevance scores that represent the relevance of each document
        to the provided query using the specified model.

        :param model: The model to use for reranking.
        :type model: str, required

        :param query: The query to compare with documents.
        :type query: str, required

        :param documents: A list of documents or strings to rank.
        :type documents: list, required

        :param rank_fields: A list of document fields to use for ranking. Defaults to ["text"].
        :type rank_fields: list, optional

        :param return_documents: Whether to include the documents in the response. Defaults to True.
        :type return_documents: bool, optional

        :param top_n: How many documents to return. Defaults to len(documents).
        :type top_n: int, optional

        :param parameters: A dictionary of parameters to use when ranking documents.
        :type parameters: dict, optional

        :return: RerankResult object with keys `data` and `usage`. The `data` key contains a list of
        `n` documents, where `n` = `top_n` and type(n) = Document. The documents are sorted in order of
        relevance, with the first being the most relevant. The `index` field can be used to locate the document
        relative to the list of documents specified in the request. Each document contains a `score` key
        representing how close the document relates to the query.

        Example:
        >>> result = pc.inference.rerank(
                model="bge-reranker-v2-m3",
                query="Tell me about tech companies",
                documents=[
                    "Apple is a popular fruit known for its sweetness and crisp texture.",
                    "Software is still eating the world.",
                    "Many people enjoy eating apples as a healthy snack.",
                    "Acme Inc. has revolutionized the tech industry with its sleek designs and user-friendly interfaces.",
                    "An apple a day keeps the doctor away, as the saying goes.",
                ],
                top_n=2,
                return_documents=True,
            )
        >>> print(result)
        RerankResult(
          model='bge-reranker-v2-m3',
          data=[
            { index=3, score=0.020980744,
              document={text="Acme Inc. has rev..."} },
            { index=1, score=0.00034015716,
              document={text="Software is still..."} }
          ],
          usage={'rerank_units': 1}
        )
        )r%   r.   r/   r0   r1   r2   r'   )rerank_request)r   rerankr   r   )
r    r%   r.   r/   r0   r1   r2   r'   r4   r,   s
             r"   r5   zInference.reranko   sP    F 177#-!
 ##**.*ID!!r$   )r   N)N)__name__
__module____qualname____doc__EmbedModelEnumr   RerankModelEnumr   r#   r   strr   r   r   r   r   r*   boolintr   r5    r$   r"   r   r      s   ,  J!K
6 04	'$^S()'$ c4:tCy01'$ T#s(^,	'$
 
'$\ #)!%#/3M"_c)*M" M" cDc3h$889	M"
 #YM" M" }M" T#s(^,M" 
M"r$   r   )loggingtypingr   r   r   r   r   pinecone.openapi_supportr   $pinecone.core.openapi.inference.apisr	   modelsr   r   pinecone.core.openapi.inferencer   pinecone.utilsr   r   inference_request_builderr   r   r:   r   r;   	getLoggerr6   loggerr   r?   r$   r"   <module>rJ      sL     3 3 . = 0 7 <  
		8	$ g" g"r$   