
    i6$                         d dl mZmZmZmZmZmZ d dlmZ ddl	m
Z
mZmZmZ d dlmZmZ ddlmZmZmZ erddlmZ  G d d	      Zy
)    )OptionalDictListUnionAnyTYPE_CHECKING)AsyncioInferenceApi   )EmbeddingsListRerankResultModelInfoList	ModelInfo)require_kwargsparse_non_empty_args)InferenceRequestBuilder
EmbedModelRerankModelModelAsyncioc                   2   e Zd ZdZeZeZddZ	 dde	de
e	ee   ee	   f   deee	ef      defdZedd	       Zd
gdddfde	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eddddee	   dee	   defd       Zede	defd       Zy)AsyncioInferencea  
    The `AsyncioInference` class configures and uses the Pinecone Inference API to generate embeddings and
    rank documents.

    This class 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 PineconeAsyncio

    pc = PineconeAsyncio()
    embeddings = await 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                 D    || _         	 d | _        	 t        |      | _        y N)
api_client_modelr	    _AsyncioInference__inference_api)selfr   kwargss      v/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/inference/inference_asyncio.py__init__zAsyncioInference.__init__+   s&    $8<2:>    modelinputs
parametersc                    K   t        j                  |||      }| j                  j                  |       d{   }t	        |      S 7 w)a0  
        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 = await 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_requestN)r   r'   r   embedr   )r   r#   r$   r%   request_bodyresps         r    r(   zAsyncioInference.embed5   sO     F /<<:
 ))//l/KKd## Ls   8AA
Ac                 n    | j                   ddlm}  || j                        | _         | j                   S )a  
        Model is a resource that describes models available in the Pinecone Inference API.

        Curently you can get or list models.

        ```python
        async with PineconeAsyncio() as pc:
            # List all models
            models = await pc.inference.model.list()

            # List models, with model type filtering
            models = await pc.inference.model.list(type="embed")
            models = await pc.inference.model.list(type="rerank")

            # List models, with vector type filtering
            models = await pc.inference.model.list(vector_type="dense")
            models = await pc.inference.model.list(vector_type="sparse")

            # List models, with both type and vector type filtering
            models = await pc.inference.model.list(type="rerank", vector_type="dense")

            # Get details on a specific model
            model = await pc.inference.model.get("text-embedding-3-small")
        ```
        r
   r   )inference_api)r   resources.asyncio.modelr   r   )r   ModelAsyncioResources     r    r#   zAsyncioInference.model^   s-    6 ;;U.T=Q=QRDK{{r"   textTquery	documentsrank_fieldsreturn_documentstop_nc           	         K   t        j                  |||||||      }| j                  j                  |       d{   }	t        |	      S 7 w)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 = await 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#   r0   r1   r2   r3   r4   r%   )rerank_requestN)r   rerankr   r   )
r   r#   r0   r1   r2   r3   r4   r%   r6   r*   s
             r    r7   zAsyncioInference.rerank   s]     F 177#-!
 ))000OOD!! Ps   <AAA)typevector_typer8   r9   c                   K   t        d|fd|fg      } | j                  j                  di | d{   }t        |      S 7 w)a=  
        List all available models.

        :param type: The type of model to list. Either "embed" or "rerank".
        :type type: str, optional

        :param vector_type: The type of vector to list. Either "dense" or "sparse".
        :type vector_type: str, optional

        :return: A list of models.
        r8   r9   N )r   r   list_modelsr   )r   r8   r9   argsr*   s        r    r<   zAsyncioInference.list_models   sN      $fd^m[5Q$RS5T))55===T"" >s   1AAA
model_namec                 l   K   | j                   j                  |       d{   }t        |      S 7 w)af  
        Get details on a specific model.

        ```python
        async with PineconeAsyncio() as pc:
            model = await pc.inference.get_model(model_name="text-embedding-3-small")
        ```

        :param model_name: The name of the model to get details on.
        :type model_name: str, required

        :return: A ModelInfo object.
        )r>   N)r   	get_modelr   )r   r>   r*   s      r    r@   zAsyncioInference.get_model   s4      ))33z3JJ Ks    424)r   Nr   )r   r.   )__name__
__module____qualname____doc__EmbedModelEnumr   RerankModelEnumr   r!   strr   r   r   r   r   r   r(   propertyr#   boolintr   r7   r   r   r<   r   r@   r;   r"   r    r   r      sw   ,  J!K 04	'$'$ c4:tCy01'$ T#s(^,	'$
 
'$R  J #)!%#/3M"M" M" cDc3h$889	M"
 #YM" M" }M" T#s(^,M" 
M"^ '+$#}#:B3-#	# #$ # )  r"   r   N)typingr   r   r   r   r   r   1pinecone.core.openapi.inference.api.inference_apir	   modelsr   r   r   r   pinecone.utilsr   r   inference_request_builderr   r   rE   r   rF   r-   r   r.   r   r;   r"   r    <module>rP      s5    B B Q J J ?  M` `r"   