
    iOQ                     n   d dl Z d dlmZmZmZmZ d dlmZ d dlZd dl	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  e j*                  e      Z	 erRd d	l	mZmZ d d
l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'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:  G d dee      Z;de<ddfdZ=y)    N)OptionalDictUnionTYPE_CHECKING)	cpu_count)PineconeConfigConfigBuilder   ) LegacyPineconeDBControlInterface)normalize_hostPluginAware	docslinksrequire_kwargs)(_build_langchain_attribute_error_message)ConfigOpenApiConfiguration)_Index_IndexAsyncio)IndexHostStore)ManageIndexesApi)!CreateIndexForModelEmbedTypedDictConfigureIndexEmbed)Metric
VectorTypeDeletionProtectionPodTypeCloudProvider	AwsRegion	GcpRegionAzureRegion)ServerlessSpecPodSpecByocSpec
IndexModel	IndexListCollectionList
IndexEmbedBackupModel
BackupListRestoreJobModelRestoreJobListc                       e Zd ZdZddddddi dfdee   dee   dee   deeeef      dee   dee   d	eeeef      d
ee   f fdZ	e
d        Ze
d        Ze
dZd       Ze
d[d       Ze
d\d       Ze
defd       Ze
d]d       Z	 	 	 	 	 	 d^dedeedddf   dee   deedef      dee   deedef      d eed!ef      d"eeeef      dd#fd$Z	 	 	 d_ded%ed&ef   d'ed(d)d*ef   d+ed,   d"eeeef      deedef      dee   dd#fd-Zedddd.ded/edeedef      d"eeeef      dee   dd#fd0       Zd`dedee   fd1Zdad2Zdedd#fd3Zdedefd4Z	 	 	 	 	 dbded5ee   d6eed7ef      deedef      d"eeeef      d+eed8ef      fd9Zded:eddfd;Zdcd<Zdeddfd=Zdefd>Zed?d@dAedBedCeddDfdE       Z eddFddGdAee   dHee   dIee   ddJfdK       Z!ed/eddDfdL       Z"ed/eddfdM       Z#edFddNdHee   dIee   ddOfdP       Z$edQeddRfdS       Z%e&dT        Z'e&dU        Z(dddededdVfdWZ)deddXfdYZ* xZ+S )ePineconez6
    A client for interacting with Pinecone APIs.
    Napi_keyhost	proxy_urlproxy_headersssl_ca_certs
ssl_verifyadditional_headerspool_threadsc	                 V   dD ]  }
|
|	v st        d|
 dt        d    d       t        j                  d	|||||||d|	| _        	 t        j                  | j                  fi |	| _        	 |dt               z  | _	        n|| _	        	 d| _
        	 d| _        	 t        | 5          y)
a  
        The ``Pinecone`` class is the main entry point for interacting with Pinecone via this Python SDK.
        Instances of the ``Pinecone`` class are used to manage and interact with Pinecone resources such as
        indexes, backups, and collections. When using the SDK, calls are made on your behalf to the API
        documented at `https://docs.pinecone.io <https://docs.pinecone.io/reference/api/introduction>`_.

        The class also holds inference functionality (embed, rerank) under the ``inference`` namespace.


        When you are ready to perform data operations on an index, you will need to instantiate an index client. Though the functionality of the index client is defined in a different
        class, it is instantiated through the ``Index()`` method in order for configurations to be shared between the two objects.

        :param api_key: The API key to use for authentication. If not passed via kwarg, the API key will be read from the environment variable ``PINECONE_API_KEY``.
        :type api_key: str, optional
        :param host: The control plane host. If unspecified, the host ``api.pinecone.io`` will be used.
        :type host: str, optional
        :param proxy_url: The URL of the proxy to use for the connection.
        :type proxy_url: str, optional
        :param proxy_headers: Additional headers to pass to the proxy. Use this if your proxy setup requires authentication.
        :type proxy_headers: Dict[str, str], optional
        :param ssl_ca_certs: The path to the SSL CA certificate bundle to use for the connection. This path should point to a file in PEM format. When not passed, the SDK will use the certificate bundle returned from ``certifi.where()``.
        :type ssl_ca_certs: str, optional
        :param ssl_verify: SSL verification is performed by default, but can be disabled using the boolean flag when testing with Pinecone Local or troubleshooting a proxy setup. You should never run with SSL verification disabled in production.
        :type ssl_verify: bool, optional
        :param additional_headers: Additional headers to pass to the API. This is mainly to support internal testing at Pinecone. End users should not need to use this unless following specific instructions to do so.
        :type additional_headers: Dict[str, str], optional
        :param pool_threads: The number of threads to use for the ThreadPool when using methods that support the ``async_req`` keyword argument. The default number of threads is 5 * the number of CPUs in your execution environment.
        :type pool_threads: int, optional

        **Configuration with environment variables**

        If you instantiate the Pinecone client with no arguments, it will attempt to read the API key from the environment variable ``PINECONE_API_KEY``.

        .. code-block:: python

            from pinecone import Pinecone

            pc = Pinecone()

        **Configuration with keyword arguments**

        If you prefer being more explicit in your code, you can also pass the API key as a keyword argument. This is also where you will pass additional configuration options such as proxy settings if you wish to use those.

        .. code-block:: python

            import os
            from pinecone import Pinecone

            pc = Pinecone(
                api_key=os.environ.get("PINECONE_API_KEY"),
                host="https://api-staging.pinecone.io"
            )

        **Environment variables**

        The Pinecone client supports the following environment variables:

        * ``PINECONE_API_KEY``: The API key to use for authentication. If not passed via kwarg, the API key will be read from the environment variable ``PINECONE_API_KEY``.
        * ``PINECONE_DEBUG_CURL``: Enable some additional debug logging representing the HTTP requests as curl commands. The main use of is to run calls outside of the SDK to help evaluate whether a problem you are experiencing is due to the API's behavior or the behavior of the SDK itself.
        * ``PINECONE_ADDITIONAL_HEADERS``: A json string of a dictionary of header values to attach to all requests. This is primarily used for internal testing at Pinecone.

        .. warning::

            Be very careful with the ``PINECONE_DEBUG_CURL`` environment variable, as it will print out your API key which forms part of a required authentication header.

        **Proxy configuration**

        If your network setup requires you to interact with Pinecone via a proxy, you will need
        to pass additional configuration using optional keyword parameters. These optional parameters
        are forwarded to ``urllib3``, which is the underlying library currently used by the Pinecone client to
        make HTTP requests. You may find it helpful to refer to the
        `urllib3 documentation on working with proxies <https://urllib3.readthedocs.io/en/stable/advanced-usage.html#http-and-https-proxies>`_
        while troubleshooting these settings.

        Here is a basic example:

        .. code-block:: python

            from pinecone import Pinecone

            pc = Pinecone(
                api_key='YOUR_API_KEY',
                proxy_url='https://your-proxy.com'
            )

            pc.list_indexes()

        If your proxy requires authentication, you can pass those values in a header dictionary using the ``proxy_headers`` parameter.

        .. code-block:: python

            from pinecone import Pinecone
            import urllib3 import make_headers

            pc = Pinecone(
                api_key='YOUR_API_KEY',
                proxy_url='https://your-proxy.com',
                proxy_headers=make_headers(proxy_basic_auth='username:password')
            )

            pc.list_indexes()


        **Using proxies with self-signed certificates**

        By default the Pinecone Python client will perform SSL certificate verification
        using the CA bundle maintained by Mozilla in the `certifi <https://pypi.org/project/certifi/>`_ package.
        If your proxy server is using a self-signed certificate, you will need to pass the path to the certificate
        in PEM format using the ``ssl_ca_certs`` parameter.

        .. code-block:: python

            from pinecone import Pinecone
            import urllib3 import make_headers

            pc = Pinecone(
                api_key='YOUR_API_KEY',
                proxy_url='https://your-proxy.com',
                proxy_headers=make_headers(proxy_basic_auth='username:password'),
                ssl_ca_certs='path/to/cert-bundle.pem'
            )

            pc.list_indexes()


        **Disabling SSL verification**

        If you would like to disable SSL verification, you can pass the ``ssl_verify``
        parameter with a value of ``False``. We do not recommend going to production with SSL verification disabled.

        .. code-block:: python

            from pinecone import Pinecone
            import urllib3 import make_headers

            pc = Pinecone(
                api_key='YOUR_API_KEY',
                proxy_url='https://your-proxy.com',
                proxy_headers=make_headers(proxy_basic_auth='username:password'),
                ssl_ca_certs='path/to/cert-bundle.pem',
                ssl_verify=False
            )

            pc.list_indexes()

        >   config	index_apiopenapi_configzPassing z is no longer supported. Please pass individual settings such as proxy_url, proxy_headers, ssl_ca_certs, and ssl_verify directly to the Pinecone constructor as keyword arguments. See the README at READMEz for examples.)r.   r/   r4   r0   r1   r2   r3   N    )NotImplementedErrorr   r   build_configr	   build_openapi_config_openapi_configr   _pool_threads
_inference_db_controlsuper__init__)selfr.   r/   r0   r1   r2   r3   r4   r5   kwargsdeprecated_kwarg	__class__s              c/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/pinecone.pyrF   zPinecone.__init__4   s   | !J 	6))/0  1v  w@  AI  wJ  vK  KY  Z 	 &++ 	
1'%!	
 	
 	,AA$,,YRXY!"Y[D"!-D"    c                     | j                   4ddlm}  || j                  | j                  | j
                        | _         | j                   S )z
        Inference is a namespace where an instance of the `pinecone.inference.Inference` class is lazily created and cached.
        r   )	Inferencer7   r9   r5   )rC   pinecone.inferencerN   r?   rA   rB   )rG   rN   s     rK   	inferencezPinecone.inference   sB    
 ??"4'||#33!//DO
 rL   c                     | j                   4ddlm}  || j                  | j                  | j
                        | _         | j                   S )z
        DBControl is a namespace where an instance of the `pinecone.db_control.DBControl` class is lazily created and cached.
        r   )	DBControlrO   )rD   pinecone.db_controlrS   r?   rA   rB   )rG   rS   s     rK   dbzPinecone.db  sG    
 #5(||#33!// D
 rL   returnc                 z    t        j                  dt        d       | j                  j                  j
                  S ):meta private:zThe `index_host_store` property is deprecated. This warning will become an error in a future version of the Pinecone Python SDK.   
stacklevel)warningswarnDeprecationWarningrU   index_index_host_storerG   s    rK   index_host_storezPinecone.index_host_store  s2     	 O	

 ww}}...rL   c                     | j                   S )rX   )r?   ra   s    rK   r7   zPinecone.config  s    
 ||rL   c                 R    t        j                  dt        d       | j                  S )rX   zThe `openapi_config` property has been renamed to `_openapi_config`. It is considered private and should not be used directly. This warning will become an error in a future version of the Pinecone Python SDK.rY   rZ   )r\   r]   r^   rA   ra   s    rK   r9   zPinecone.openapi_config%  s*     	 _	

 ###rL   c                 R    t        j                  dt        d       | j                  S )rX   zThe `pool_threads` property has been renamed to `_pool_threads`. It is considered private and should not be used directly. This warning will become an error in a future version of the Pinecone Python SDK.rY   rZ   )r\   r]   r^   rB   ra   s    rK   r5   zPinecone.pool_threads/  s*     	 [	

 !!!rL   c                 f    t        j                  dt        d       | j                  j                  S )rX   zyThe `index_api` property is deprecated. This warning will become an error in a future version of the Pinecone Python SDK.rY   rZ   )r\   r]   r^   rU   
_index_apira   s    rK   r8   zPinecone.index_api9  s.     	 H	

 ww!!!rL   disablednamespecr!   r"   r#   	dimensionmetricr   timeoutdeletion_protectionr   vector_typer   tagsr$   c	           
      \    | j                   j                  j                  ||||||||      S )N)ri   rj   rk   rl   rm   rn   ro   rp   )rU   r_   create)	rG   ri   rj   rk   rl   rm   rn   ro   rp   s	            rK   create_indexzPinecone.create_indexC  s<     ww}}## 3# $ 	
 		
rL   cloudr   regionr   r   r    embed)r'   r   c           	      Z    | j                   j                  j                  |||||||      S )N)ri   rt   ru   rv   rp   rn   rm   )rU   r_   create_for_model)rG   ri   rt   ru   rv   rp   rn   rm   s           rK   create_index_for_modelzPinecone.create_index_for_modelY  s9     ww}}-- 3 . 
 	
rL   )rn   rp   rm   	backup_idc                V    | j                   j                  j                  |||||      S )N)ri   rz   rn   rp   rm   )rU   r_   create_from_backup)rG   ri   rz   rn   rp   rm   s         rK   create_index_from_backupz!Pinecone.create_index_from_backupm  s3     ww}}// 3 0 
 	
rL   c                 P    | j                   j                  j                  ||      S )N)ri   rm   )rU   r_   delete)rG   ri   rm   s      rK   delete_indexzPinecone.delete_index  s     ww}}##w#??rL   c                 J    | j                   j                  j                         S N)rU   r_   listra   s    rK   list_indexeszPinecone.list_indexes  s    ww}}!!##rL   c                 N    | j                   j                  j                  |      S N)ri   )rU   r_   describerG   ri   s     rK   describe_indexzPinecone.describe_index  s    ww}}%%4%00rL   c                 N    | j                   j                  j                  |      S r   )rU   r_   hasr   s     rK   	has_indexzPinecone.has_index  s    ww}}  d ++rL   replicaspod_typer   r   c                 X    | j                   j                  j                  ||||||      S )N)ri   r   r   rn   rp   rv   )rU   r_   	configure)rG   ri   r   r   rn   rp   rv   s          rK   configure_indexzPinecone.configure_index  s6     ww}}&& 3 ' 
 	
rL   sourcec                 P    | j                   j                  j                  ||      S )N)ri   r   )rU   
collectionrr   )rG   ri   r   s      rK   create_collectionzPinecone.create_collection  s"    ww!!((d6(BBrL   c                 J    | j                   j                  j                         S r   )rU   r   r   ra   s    rK   list_collectionszPinecone.list_collections  s    ww!!&&((rL   c                 N    | j                   j                  j                  |      S r   )rU   r   r   r   s     rK   delete_collectionzPinecone.delete_collection  s     ww!!((d(33rL   c                 N    | j                   j                  j                  |      S r   )rU   r   r   r   s     rK   describe_collectionzPinecone.describe_collection  s     ww!!***55rL    )description
index_namebackup_namer   r(   c                R    | j                   j                  j                  |||      S )N)r   r   r   )rU   backuprr   )rG   r   r   r   s       rK   create_backupzPinecone.create_backup  s+     ww~~$$!{ % 
 	
rL   
   r   limitpagination_tokenr   r   r)   c                R    | j                   j                  j                  |||      S )Nr   )rU   r   r   )rG   r   r   r   s       rK   list_backupszPinecone.list_backups  s,     ww~~""!AQ # 
 	
rL   c                N    | j                   j                  j                  |      S N)rz   )rU   r   r   rG   rz   s     rK   describe_backupzPinecone.describe_backup  s    ww~~&&&;;rL   c                N    | j                   j                  j                  |      S r   )rU   r   r   r   s     rK   delete_backupzPinecone.delete_backup  s    ww~~$$y$99rL   r   r   r+   c                P    | j                   j                  j                  ||      S )Nr   )rU   restore_jobr   )rG   r   r   s      rK   list_restore_jobszPinecone.list_restore_jobs  s%     ww""''eFV'WWrL   job_idr*   c                N    | j                   j                  j                  |      S )N)r   )rU   r   r   )rG   r   s     rK   describe_restore_jobzPinecone.describe_restore_job  s     ww""++6+::rL   c                  *    t        t        d            )rX   
from_textsAttributeErrorr   argsrH   s     rK   r   zPinecone.from_texts  s     ElSTTrL   c                  *    t        t        d            )rX   from_documentsr   r   s     rK   r   zPinecone.from_documents  s     EFVWXXrL   Indexc           	         ddl m} |dk(  r|dk(  rt        d      |j                  dd       xs | j                  }| j
                  j                  }| j                  }|dk7  rt        |       t        |      }n%| j                  j                  j                  |      } |d||||| j                  j                  d|S )Nr   )r   r   z%Either name or host must be specifiedr5   )r/   r.   r5   r9   
source_tagr<   )pinecone.db_datar   
ValueErrorpoprB   r?   r.   rA   check_realistic_hostr   rU   r_   	_get_hostr7   r   )	rG   ri   r/   rH   r   ptr.   r9   
index_hosts	            rK   r   zPinecone.Index  s    +2:$"*DEEZZ-C1C1C,,&&--2: & (-J 006J 
){{--
 
 	
rL   IndexAsyncioc                     ddl m} | j                  j                  }| j                  }||dk(  rt        d      t        |       t        |      } |d|||| j                  j                  d|S )Nr   )r   r   zA host must be specified)r/   r.   r9   r   r<   )
r   r   r?   r.   rA   r   r   r   r7   r   )rG   r/   rH   r   r.   r9   r   s          rK   r   zPinecone.IndexAsyncio  sz    2,,&&--<42:788T"#D)
 
){{--	

 
 	
rL   )rV   r   )rV   r   )rV   r   )rV   r   )NcosineNrh   denseN)Nrh   Nr   )rV   r%   )NNNNN)rV   r&   )r   r   ),__name__
__module____qualname____doc__r   strr   boolintrF   propertyrQ   rU   rb   r7   r9   r5   r8   r   rs   ry   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   __classcell__)rJ   s   @rK   r-   r-   /   s    "&"#'26&*%)79&*@#@ sm@ C=	@
  S#X/@ sm@ TN@ %T#s(^4@ sm@D       / /   $ $ "c " " " " $(19!%JT:A)-

 D*IzAB
 C=	

 x}-.
 #
 &e,@#,E&FG
 eL#$567
 tCH~&
 

8 *.JT!%

 _c)*
 k;sBC	

 FG
 tCH~&
 &e,@#,E&FG
 #
 

(  KU)-!%
 
 	

 &e,@#,E&FG
 tCH~&
 #
 

 
"@ @x} @$13 1< 1,c ,d , #'48JN)->B

 3-
 5C01	

 &e,@#,E&FG
 tCH~&
 3T9:;
$Cc C3 C4 C)4c 4d 46 6 GI
 
/2
AD
	
 
  %)!*.	
 SM	
 }		

 #3-	
 
	
 	
 <C <M < < :# :$ : : (*dX X>FsmX	X X
 ;c ;6G ; ; U U Y Y
# 
# 
 
8
 
> 
rL   r-   r/   rV   c                 4    d| vrd| vrt        d|  d      yy)aV  :meta private:

    Checks whether a user-provided host string seems plausible.
    Someone could erroneously pass an index name as the host by
    mistake, and if they have done that we'd like to give them a
    simple error message as feedback rather than attempting to
    call the url and getting a more cryptic DNS resolution error.
    .	localhostzYou passed 'zk' as the host but this does not appear to be valid. Call describe_index() to confirm the host of the index.N)r   )r/   s    rK   r   r   
  s9     $;d24&  !L  M
 	
 3rL   )>loggingtypingr   r   r   r   multiprocessingr   r\   pinecone.configr   r	   legacy_pinecone_interfacer   pinecone.utilsr   r   r   r   langchain_import_warningsr   	getLoggerr   loggerr   r   r   r   r   r   r   $pinecone.db_control.index_host_storer   7pinecone.core.openapi.db_control.api.manage_indexes_apir   pinecone.db_control.typesr   r   pinecone.db_control.enumsr   r   r   r   r   r   r   r    pinecone.db_control.modelsr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r-   r   r   r<   rL   rK   <module>r      s     7 7 %  9 G Q Q O			8	$ <OCX`	 	 	   X
{< X
v
s 
t 
rL   