
    i                        d dl Z d dlmZmZmZmZ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 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mZ dd	lmZ dd
l m!Z! d dl"m#Z#m$Z$m%Z&m'Z'm(Z( d dl)m*Z+m,Z, d dl-m.Z/m0Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z=m>Z>m?Z?m@Z@ d dlAm.Z.m<Z< d dlBmCZCmDZD d dlEmFZF ddlGmHZH ddlImJZJ ddlKmLZLmMZMmNZNmOZOmPZP g dZQ e j                  eS      ZT	  G d deH      ZUy)    N)	OptionalDictUnionListTupleAnyIterablecastLiteral)json_format)tqdm)require_kwargs)as_completedFuture   )	dict_to_proto_structparse_fetch_responseparse_query_responseparse_stats_responseparse_upsert_responseparse_update_responseparse_delete_responseparse_namespace_descriptionparse_list_namespaces_response)VectorFactoryGRPC)SparseValuesFactory)FetchResponseQueryResponseIndexDescriptionNamespaceDescriptionListNamespacesResponse)ListResponse
Pagination)VectorQueryVectorUpsertRequestUpsertResponseDeleteRequestQueryRequestFetchRequestUpdateRequestListRequestDescribeIndexStatsRequestDeleteResponseUpdateResponseSparseValuesDescribeNamespaceRequestDeleteNamespaceRequestListNamespacesRequest)r$   r0   )QueryNamespacesResultsQueryResultsAggregatorVectorServiceStub)GRPCIndexBase)PineconeGrpcFuture   )SparseVectorTypedDictVectorTypedDictVectorTupleFilterTypedDictVectorMetadataTypedDict)	GRPCIndex
GRPCVectorGRPCQueryVectorGRPCSparseValuesr    r!   c                      e Zd ZdZed        Z	 	 	 	 d0deee   ee	   ee
   ee   f   dedee   dee   ded	eeef   fd
Zdee	   dee   dee   d	efdZ	 	 	 	 d1dedededed	ef
dZed        Z	 	 	 	 	 d2deee      dee   dee   dee   ded	eeef   fdZ	 	 d3deee      dee   dee   d	eeef   fdZ	 	 	 	 	 	 	 	 	 d4deee      dee   dee   dee   dee   dee   dee   deeeeef      dee   d	ee ef   fdZ!	 	 	 	 	 d5dee   dee   de"d   dee   dee   dee   dee   deeeef      d	e#fdZ$	 	 	 	 	 d6deded eee      d!ee%   dee   d"eeeef      d	ee&ef   fd#Z'	 	 	 	 d7d$ee   d%ee   d&ee   dee   d	e(f
d'Z)d( Z*	 d8dee   d	e+fd)Z,e-ded	e.fd*       Z/e-ded	e0ee1f   fd+       Z2e-	 	 d9d%ee   d&ee   d	e3fd,       Z4e-d8d%ee   fd-       Z5ed.ee6ee1f      d	e0ee1f   fd/       Z7y):r@   z<A client for interacting with a Pinecone index via GRPC API.c                     t         S )z:meta private:r6   )selfs    j/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/grpc/index_grpc.py
stub_classzGRPCIndex.stub_classJ   s
     !     Nvectors	async_req	namespace
batch_sizeshow_progressreturnc                    |r|t        d      |j                  dd      }t        t        t        j
                  |            }|rq| j                  d|fg      }t        dd|i||}	| j                  j                  | j                  j                  j                  |	|      }
t        |
|t              S | | j                  ||fd|i|S t!        |t"              r|dk  rt        d	      t%        t'        |      | d
      }d}t)        dt'        |      |      D ]H  } | j                  ||||z    |fd|i|}|j+                  |j,                         ||j,                  z  }J t/        |      S )a<  
        The upsert operation writes vectors into a namespace.
        If a new value is upserted for an existing vector id, it will overwrite the previous value.

        Examples:

        .. code-block:: python

            >>> index.upsert([('id1', [1.0, 2.0, 3.0], {'key': 'value'}),
                              ('id2', [1.0, 2.0, 3.0])
                              ],
                              namespace='ns1', async_req=True)
            >>> index.upsert([{'id': 'id1', 'values': [1.0, 2.0, 3.0], 'metadata': {'key': 'value'}},
                              {'id': 'id2',
                                        'values': [1.0, 2.0, 3.0],
                                        'sparse_values': {'indices': [1, 8], 'values': [0.2, 0.4]},
                              ])
            >>> index.upsert([GRPCVector(id='id1', values=[1.0, 2.0, 3.0], metadata={'key': 'value'}),
                              GRPCVector(id='id2', values=[1.0, 2.0, 3.0]),
                              GRPCVector(id='id3',
                                         values=[1.0, 2.0, 3.0],
                                         sparse_values=GRPCSparseValues(indices=[1, 2], values=[0.2, 0.4]))])

        Args:
            vectors (Union[List[Vector], List[Tuple]]): A list of vectors to upsert.

                     A vector can be represented by a 1) GRPCVector object, a 2) tuple or 3) a dictionary
                     1) if a tuple is used, it must be of the form (id, values, metadata) or (id, values).
                        where id is a string, vector is a list of floats, and metadata is a dict.
                        Examples: ('id1', [1.0, 2.0, 3.0], {'key': 'value'}), ('id2', [1.0, 2.0, 3.0])

                    2) if a GRPCVector object is used, a GRPCVector object must be of the form
                        GRPCVector(id, values, metadata), where metadata is an optional argument of type
                        Dict[str, Union[str, float, int, bool, List[int], List[float], List[str]]]
                       Examples: GRPCVector(id='id1', values=[1.0, 2.0, 3.0], metadata={'key': 'value'}),
                                 GRPCVector(id='id2', values=[1.0, 2.0, 3.0]),
                                 GRPCVector(id='id3',
                                            values=[1.0, 2.0, 3.0],
                                            sparse_values=GRPCSparseValues(indices=[1, 2], values=[0.2, 0.4]))

                    3) if a dictionary is used, it must be in the form
                       {'id': str, 'values': List[float], 'sparse_values': {'indices': List[int], 'values': List[float]},
                        'metadata': dict}

                    Note: the dimension of each vector must match the dimension of the index.
            async_req (bool): If True, the upsert operation will be performed asynchronously.
                              Cannot be used with batch_size.
                              Defaults to False. See: https://docs.pinecone.io/docs/performance-tuning [optional]
            namespace (str): The namespace to write to. If not specified, the default namespace is used. [optional]
            batch_size (int): The number of vectors to upsert in each batch.
                                Cannot be used with async_req=True.
                               If not specified, all vectors will be upserted in a single batch. [optional]
            show_progress (bool): Whether to show a progress bar using tqdm.
                                  Applied only if batch_size is provided. Default is True.

        Returns: UpsertResponse, contains the number of vectors upserted
        Nzasync_req is not supported when batch_size is provided.To upsert in parallel, please follow: https://docs.pinecone.io/docs/performance-tuningtimeoutrL   rJ   rQ   rQ   result_transformerr   z%batch_size must be a positive integerzUpserted vectorstotaldisabledescupserted_count )
ValueErrorpoplistmapr   build_parse_non_empty_argsr&   runnerrunstubUpsertfuturer9   r   _upsert_batch
isinstanceintr   lenrangeupdaterZ   r'   )rF   rJ   rK   rL   rM   rN   kwargsrQ   	args_dictrequestrf   pbartotal_upsertedibatch_results                  rG   upsertzGRPCIndex.upsertO   s   D /C  **Y-s,22G<=22[)4L3MNI#KGKyKFKG[[__TYY%5%5%<%<gw_WF%<Q  %4%%gyT'TVTT*c*jAoDEE#g,M0AHZ[q#g,
3 	:A-4--A
N+Y@GKQL KK334l999N	: ^<<rI   rQ   c                     | j                  d|fg      }t        dd|i|} | j                  j                  | j                  j
                  |fd|i|S )NrL   rJ   rQ   r[   )ra   r&   rb   rc   rd   re   )rF   rJ   rL   rQ   rm   rn   ro   s          rG   rg   zGRPCIndex._upsert_batch   sY     ..i0H/IJ	==9=t{{tyy//T'TVTTrI   use_async_requestsc                    	 ddl }t        ||j                        st        dt        |             t        t        |      | d      }g }| j                  ||      D ]A  }	| j                  |	||      }
|j                  t        |	             |j                  |
       C |rAt        t        t           |      }t        || d	
      D cg c]  }|j!                          }}d}|D ]9  }
t#        |
d      st        |
j$                  t&              s+||
j$                  z  }; t)        |      S # t        $ r t        d      w xY wc c}w )a  Upserts a dataframe into the index.

        Args:
            df: A pandas dataframe with the following columns: id, values, sparse_values, and metadata.
            namespace: The namespace to upsert into.
            batch_size: The number of rows to upsert in a single batch.
            use_async_requests: Whether to upsert multiple requests at the same time using asynchronous request mechanism.
                                Set to ``False``
            show_progress: Whether to show a progress bar.
        r   Nz]The `pandas` package is not installed. Please install pandas to use `upsert_from_dataframe()`z-Only pandas dataframes are supported. Found: zsending upsert requestsrU   )rM   )rJ   rL   rK   zcollecting async responses)iterablerW   rX   rZ   rY   )pandasImportErrorRuntimeErrorrh   	DataFramer\   typer   rj   _iter_dataframert   rl   appendr
   r   r9   resulthasattrrZ   ri   r'   )rF   dfrL   rM   rv   rN   pdrp   resultschunkrescast_resultsasync_resultrZ   s                 rG   upsert_from_dataframezGRPCIndex.upsert_from_dataframe   s`   $	 "bll+LTRTXJWXX#b'}+<C\]))")D 	 E++eyL^+_CKKE
#NN3	 
 %7 8'BL %)) --5%  ##%G   	5Cs,-*S=O=OQT2U#"4"44	5 ^<<?  	o 	"s   D3 E3Ec              #      K   t        dt        |       |      D ](  }| j                  |||z    j                  d      }| * y w)Nr   records)orient)rk   rj   ilocto_dict)r   rM   rr   batchs       rG   r~   zGRPCIndex._iter_dataframe   sI     q#b':. 	AGGAJ/77y7IEK	s   AAids
delete_allfilterc                    |t        |      }nd}| j                  d|fd|fd|fd|fg      }|j                  dd      }	t        d	i ||}
|rN| j                  j                  | j                  j                  j                  |
|	      }t        ||	t              S | j                  j                  | j                  j                  |
|	      S )
a  
        The Delete operation deletes vectors from the index, from a single namespace.
        No error raised if the vector id does not exist.

        Args:
            ids (List[str]): Vector ids to delete [optional]
            delete_all (bool): This indicates that all vectors in the index namespace should be deleted.. [optional]
                               Default is False.
            namespace (str): The namespace to delete vectors from [optional]
                             If not specified, the default namespace is used.
            filter (FilterTypedDict):
                    If specified, the metadata filter here will be used to select the vectors to delete.
                    This is mutually exclusive with specifying ids to delete in the ids param or using delete_all=True.
                     See `metadata filtering <https://www.pinecone.io/docs/metadata-filtering/>_` [optional]
            async_req (bool): If True, the delete operation will be performed asynchronously.
                              Defaults to False. [optional]

        Returns: DeleteResponse (contains no data) or a PineconeGrpcFuture object if async_req is True.

        .. admonition:: Note

            For any delete call, if namespace is not specified, the default namespace is used.

        Delete can occur in the following mutual exclusive ways:

        1. Delete by ids from a single namespace
        2. Delete all vectors from a single namespace by setting delete_all to True
        3. Delete all vectors from a single namespace by specifying a metadata filter
           (note that for this option delete all must be set to False)

        Examples:

        .. code-block:: python

            >>> index.delete(ids=['id1', 'id2'], namespace='my_namespace')
            >>> index.delete(delete_all=True, namespace='my_namespace')
            >>> index.delete(filter={'key': 'value'}, namespace='my_namespace', async_req=True)
        Nr   r   rL   r   rQ   rR   rS   r[   )r   ra   r]   r(   rb   rc   rd   Deleterf   r9   r   )rF   r   r   rL   r   rK   rm   filter_structrn   rQ   ro   rf   s               rG   deletezGRPCIndex.delete   s    ` 08M M..z*i(=)	
	 **Y-6)6v6[[__TYY%5%5%<%<gw_WF%<Q  ;;??499#3#3Wg?NNrI   c                    |j                  dd      }| j                  d|fg      }t        dd|i||}|rN| j                  j	                  | j
                  j                  j                  ||      }t        |t        |      S | j                  j	                  | j
                  j                  ||      }	t        |	      S )a  
        The fetch operation looks up and returns vectors, by ID, from a single namespace.
        The returned vectors include the vector data and/or metadata.

        Examples:

        .. code-block:: python

            >>> index.fetch(ids=['id1', 'id2'], namespace='my_namespace')
            >>> index.fetch(ids=['id1', 'id2'])

        Args:
            ids (List[str]): The vector IDs to fetch.
            namespace (str): The namespace to fetch vectors from.
                             If not specified, the default namespace is used. [optional]

        Returns: FetchResponse object which contains the list of Vector objects, and namespace name.
        rQ   NrL   r   rR   rT   rQ   r[   )
r]   ra   r*   rb   rc   rd   Fetchrf   r9   r   )
rF   r   rL   rK   rm   rQ   rn   ro   rf   responses
             rG   fetchzGRPCIndex.fetch?  s    2 **Y-..i0H/IJ	>3>)>v>[[__TYY__%;%;Wg_VF%+?  {{tyyQH'11rI   vectoridtop_kinclude_valuesinclude_metadatasparse_vectorc
                 >   ||t        d      |t        |      }nd}t        j                  |      }| j	                  d|fd|fd|fd|fd|fd|fd	|fd
|fg      }t        di |}|
j                  dd      }|	rN| j                  j                  | j                  j                  j                  ||      }t        |t        |      S | j                  j                  | j                  j                  ||      }t        j                  |      }t        |d      S )an  
        The Query operation searches a namespace, using a query vector.
        It retrieves the ids of the most similar items in a namespace, along with their similarity scores.

        Examples:

        .. code-block:: python

            >>> index.query(vector=[1, 2, 3], top_k=10, namespace='my_namespace')
            >>> index.query(id='id1', top_k=10, namespace='my_namespace')
            >>> index.query(vector=[1, 2, 3], top_k=10, namespace='my_namespace', filter={'key': 'value'})
            >>> index.query(id='id1', top_k=10, namespace='my_namespace', include_metadata=True, include_values=True)
            >>> index.query(vector=[1, 2, 3], sparse_vector={'indices': [1, 2], 'values': [0.2, 0.4]},
            >>>             top_k=10, namespace='my_namespace')
            >>> index.query(vector=[1, 2, 3], sparse_vector=GRPCSparseValues([1, 2], [0.2, 0.4]),
            >>>             top_k=10, namespace='my_namespace')

        Args:
            vector (List[float]): The query vector. This should be the same length as the dimension of the index
                                  being queried. Each ``query()`` request can contain only one of the parameters
                                  ``id`` or ``vector``.. [optional]
            id (str): The unique ID of the vector to be used as a query vector.
                      Each ``query()`` request can contain only one of the parameters
                      ``vector`` or ``id``.. [optional]
            top_k (int): The number of results to return for each query. Must be an integer greater than 1.
            namespace (str): The namespace to fetch vectors from.
                             If not specified, the default namespace is used. [optional]
            filter (Dict[str, Union[str, float, int, bool, List, dict]]):
                    The filter to apply. You can use vector metadata to limit your search.
                    See `metadata filtering <https://www.pinecone.io/docs/metadata-filtering/>_` [optional]
            include_values (bool): Indicates whether vector values are included in the response.
                                   If omitted the server will use the default value of False [optional]
            include_metadata (bool): Indicates whether metadata is included in the response as well as the ids.
                                     If omitted the server will use the default value of False  [optional]
            sparse_vector: (Union[SparseValues, Dict[str, Union[List[float], List[int]]]]): sparse values of the query vector.
                            Expected to be either a SparseValues object or a dict of the form:
                             {'indices': List[int], 'values': List[float]}, where the lists each have the same length.

        Returns: QueryResponse object which contains the list of the closest vectors as ScoredVector objects,
                 and namespace name.
        Nz%Cannot specify both `id` and `vector`r   r   rL   r   r   r   r   r   rQ   rR   r   F)_check_typer[   )r\   r   r   r`   ra   r)   r]   rb   rc   rd   Queryrf   r9   r   r   MessageToDict)rF   r   r   rL   r   r   r   r   r   rK   rm   r   rn   ro   rQ   rf   r   json_responses                     rG   queryzGRPCIndex.queryg  s1   r ".DEE08M M+11-@..6"r
i(% =)!>2#%56 -0	
	 ++**Y-[[__TYY__%;%;Wg_VF%+?  {{tyyQH'55h?M'5IIrI   
namespacesmetric)cosine	euclidean
dotproductc	                    |t        |      dk(  rt        d      t        |      dk(  rt        d      ||nd}
t        |
|      }t        |      }|D cg c]2  } | j                  j
                  | j                  f|||
||||dd|	4 }}t        t        t           |      }t        |      D ]!  }|j                  |j                                # |j                         }|S c c}w )Nr   z(At least one namespace must be specifiedzQuery vector must not be empty
   )r   r   F)r   rL   r   r   r   r   r   rK   )rj   r\   r5   setthreadpool_executorsubmitr   r
   r	   r   r   add_resultsr   get_results)rF   r   r   r   r   r   r   r   r   rm   overall_topk
aggregatortarget_namespacesnsfuturesonly_futuresr   final_resultss                     rG   query_namespaceszGRPCIndex.query_namespaces  s    ZA!5GHHv;!=>> % 1ur+,vN

O (
  ,D$$++

"-!1+ 
 
  HV,g6$\2 	6H""8??#45	6 #..0+
s   7C(valuesset_metadatasparse_valuesc                    |t        |      }nd}|j                  dd      }	t        j                  |      }| j	                  d|fd|fd|fd|fg      }
t        d
d|i|
}|rN| j                  j                  | j                  j                  j                  ||	      }t        ||	t        	      S | j                  j                  | j                  j                  ||	      S )a  
        The Update operation updates vector in a namespace.
        If a value is included, it will overwrite the previous value.
        If a set_metadata is included,
        the values of the fields specified in it will be added or overwrite the previous value.

        Examples:

        .. code-block:: python

            >>> index.update(id='id1', values=[1, 2, 3], namespace='my_namespace')
            >>> index.update(id='id1', set_metadata={'key': 'value'}, namespace='my_namespace', async_req=True)
            >>> index.update(id='id1', values=[1, 2, 3], sparse_values={'indices': [1, 2], 'values': [0.2, 0.4]},
            >>>              namespace='my_namespace')
            >>> index.update(id='id1', values=[1, 2, 3], sparse_values=GRPCSparseValues(indices=[1, 2], values=[0.2, 0.4]),
            >>>              namespace='my_namespace')

        Args:
            id (str): Vector's unique id.
            async_req (bool): If True, the update operation will be performed asynchronously.
                              Defaults to False. [optional]
            values (List[float]): vector values to set. [optional]
            set_metadata (Dict[str, Union[str, float, int, bool, List[int], List[float], List[str]]]]):
                metadata to set for vector. [optional]
            namespace (str): Namespace name where to update the vector.. [optional]
            sparse_values: (Dict[str, Union[List[float], List[int]]]): sparse values to update for the vector.
                           Expected to be either a GRPCSparseValues object or a dict of the form:
                           {'indices': List[int], 'values': List[float]} where the lists each have the same length.


        Returns: UpdateResponse (contains no data) or a PineconeGrpcFuture object if async_req is True.
        NrQ   r   r   rL   r   r   rR   rS   r[   )r   r]   r   r`   ra   r+   rb   rc   rd   Updaterf   r9   r   )rF   r   rK   r   r   rL   r   rm   set_metadata_structrQ   rn   ro   rf   s                rG   rl   zGRPCIndex.update  s    T #"6|"D"&**Y-+11-@..6"!45i( -0	
	  3233[[__TYY%5%5%<%<gw_WF%<Q  ;;??499#3#3Wg?NNrI   prefixlimitpagination_tokenc                    | j                  d|fd|fd|fd|fg      }t        di ||}|j                  dd      }| j                  j	                  | j
                  j                  ||      }	|	j                  r:|	j                  j                  dk7  r!t        |	j                  j                  	      }
nd}
t        |	j                  |	j                  |

      S )a  
        The list_paginated operation finds vectors based on an id prefix within a single namespace.
        It returns matching ids in a paginated form, with a pagination token to fetch the next page of results.
        This id list can then be passed to fetch or delete operations, depending on your use case.

        Consider using the ``list`` method to avoid having to handle pagination tokens manually.

        Examples:

        .. code-block:: python

            >>> results = index.list_paginated(prefix='99', limit=5, namespace='my_namespace')
            >>> [v.id for v in results.vectors]
            ['99', '990', '991', '992', '993']
            >>> results.pagination.next
            eyJza2lwX3Bhc3QiOiI5OTMiLCJwcmVmaXgiOiI5OSJ9
            >>> next_results = index.list_paginated(prefix='99', limit=5, namespace='my_namespace', pagination_token=results.pagination.next)

        Args:
            prefix (Optional[str]): The id prefix to match. If unspecified, an empty string prefix will
                                    be used with the effect of listing all ids in a namespace [optional]
            limit (Optional[int]): The maximum number of ids to return. If unspecified, the server will use a default value. [optional]
            pagination_token (Optional[str]): A token needed to fetch the next page of results. This token is returned
                in the response if additional results are available. [optional]
            namespace (Optional[str]): The namespace to fetch vectors from. If not specified, the default namespace is used. [optional]

        Returns: SimpleListResponse object which contains the list of ids, the namespace name, pagination information, and usage showing the number of read_units consumed.
        r   r   rL   r   rQ   NrR    )next)rL   rJ   
paginationr[   )ra   r,   r]   rb   rc   rd   r   r   r   r#   SimpleListResponserL   rJ   )rF   r   r   r   rL   rm   rn   ro   rQ   r   r   s              rG   list_paginatedzGRPCIndex.list_paginated3  s    H ..6"% i(#%56	
	 4	4V4**Y-;;??499>>7G?L8#6#6#;#;r#A#)<)<)A)ABJJ!(((2B2Bz
 	
rI   c              +     K   d}|s	  | j                   di |}t        |j                        dkD  r&|j                  D cg c]  }|j                   c} |j
                  r>|j
                  j                  r(|j                  d|j
                  j                  i       nd}|syy# t        $ r}|d}~ww xY wc c}w w)a  
        The list operation accepts all of the same arguments as list_paginated, and returns a generator that yields
        a list of the matching vector ids in each page of results. It automatically handles pagination tokens on your
        behalf.

        Examples:

        .. code-block:: python

            >>> for ids in index.list(prefix='99', limit=5, namespace='my_namespace'):
            >>>     print(ids)
            ['99', '990', '991', '992', '993']
            ['994', '995', '996', '997', '998']
            ['999']

        Args:
            prefix (Optional[str]): The id prefix to match. If unspecified, an empty string prefix will
                                    be used with the effect of listing all ids in a namespace [optional]
            limit (Optional[int]): The maximum number of ids to return. If unspecified, the server will use a default value. [optional]
            pagination_token (Optional[str]): A token needed to fetch the next page of results. This token is returned
                in the response if additional results are available. [optional]
            namespace (Optional[str]): The namespace to fetch vectors from. If not specified, the default namespace is used. [optional]
        FNr   r   Tr[   )r   	Exceptionrj   rJ   r   r   r   rl   )rF   rm   doner   evs         rG   r^   zGRPCIndex.listl  s     0 -$--77 7??#a'%,__5qtt55!!g&8&8&=&=173E3E3J3JKL    6s:   CB) &C B<AC'C)	B92B44B99Cc                 (   |t        |      }nd}| j                  d|fg      }|j                  dd      }t        di |}| j                  j                  | j                  j                  ||      }t        j                  |      }t        |      S )a  
        The DescribeIndexStats operation returns statistics about the index's contents.
        For example: The vector count per namespace and the number of dimensions.

        Examples:

        .. code-block:: python

            >>> index.describe_index_stats()
            >>> index.describe_index_stats(filter={'key': 'value'})

        Args:
            filter (Dict[str, Union[str, float, int, bool, List, dict]]):
            If this parameter is present, the operation only returns statistics for vectors that satisfy the filter.
            See `metadata filtering <https://www.pinecone.io/docs/metadata-filtering/>_` [optional]

        Returns: DescribeIndexStatsResponse object which contains stats about the index.
        Nr   rQ   rR   r[   )r   ra   r]   r-   rb   rc   rd   DescribeIndexStatsr   r   r   )	rF   r   rm   r   rn   rQ   ro   r   r   s	            rG   describe_index_statszGRPCIndex.describe_index_stats  s    * 08M M..=0I/JK	**Y-+8i8;;??499#?#?RY?Z#11(;#M22rI   c                     |j                  dd      }t        |      }| j                  j                  | j                  j
                  ||      }t        |      S )a  
        The describe_namespace operation returns information about a specific namespace,
        including the total number of vectors in the namespace.

        Examples:

        .. code-block:: python

            >>> index.describe_namespace(namespace='my_namespace')

        Args:
            namespace (str): The namespace to describe.

        Returns: NamespaceDescription object which contains information about the namespace.
        rQ   NrL   rR   )r]   r1   rb   rc   rd   DescribeNamespacer   rF   rL   rm   rQ   ro   r   s         rG   describe_namespacezGRPCIndex.describe_namespace  sL    & **Y-*Y?;;??499#>#>QX?Y*844rI   c                     |j                  dd      }t        |      }| j                  j                  | j                  j
                  ||      }t        |      S )a  
        The delete_namespace operation deletes a namespace from an index.
        This operation is irreversible and will permanently delete all data in the namespace.

        Examples:

        .. code-block:: python

            >>> index.delete_namespace(namespace='my_namespace')

        Args:
            namespace (str): The namespace to delete.

        Returns: Empty dictionary indicating successful deletion.
        rQ   Nr   rR   )r]   r2   rb   rc   rd   DeleteNamespacer   r   s         rG   delete_namespacezGRPCIndex.delete_namespace  sK    & **Y-(9=;;??499#<#<gw?W$X..rI   c                     | j                  d|fd|fg      }|j                  dd      }t        di ||}| j                  j	                  | j
                  j                  ||      }t        |      S )ap  
        The list_namespaces_paginated operation returns a list of all namespaces in a serverless index.
        It returns namespaces in a paginated form, with a pagination token to fetch the next page of results.

        Examples:

        .. code-block:: python

            >>> results = index.list_namespaces_paginated(limit=10)
            >>> [ns.name for ns in results.namespaces]
            ['namespace1', 'namespace2', 'namespace3']
            >>> results.pagination.next
            eyJza2lwX3Bhc3QiOiI5OTMiLCJwcmVmaXgiOiI5OSJ9
            >>> next_results = index.list_namespaces_paginated(limit=10, pagination_token=results.pagination.next)

        Args:
            limit (Optional[int]): The maximum number of namespaces to return. If unspecified, the server will use a default value. [optional]
            pagination_token (Optional[str]): A token needed to fetch the next page of results. This token is returned
                in the response if additional results are available. [optional]

        Returns: ListNamespacesResponse object which contains the list of namespaces and pagination information.
        r   r   rQ   NrR   r[   )ra   r]   r3   rb   rc   rd   ListNamespacesr   )rF   r   r   rm   rn   rQ   ro   r   s           rG   list_namespaces_paginatedz#GRPCIndex.list_namespaces_paginated  s{    : ..% #%56
	 **Y-'>)>v>;;??499#;#;Wg?V-h77rI   c              +   v  K   d}|s	  | j                   dd|i|}|j                  r-t        |j                        dkD  r|j                  D ]  }|  |j                  r>|j                  j
                  r(|j                  d|j                  j
                  i       nd}|syy# t        $ r}|d}~ww xY ww)a&  
        The list_namespaces operation accepts all of the same arguments as list_namespaces_paginated, and returns a generator that yields
        each namespace. It automatically handles pagination tokens on your behalf.

        Args:
            limit (Optional[int]): The maximum number of namespaces to fetch in each network call. If unspecified, the server will use a default value. [optional]

        Returns:
            Returns a generator that yields each namespace. It automatically handles pagination tokens on your behalf so you can
            easily iterate over all results. The ``list_namespaces`` method accepts all of the same arguments as list_namespaces_paginated

        Examples:

        .. code-block:: python

            >>> for namespace in index.list_namespaces():
            >>>     print(namespace.name)
            namespace1
            namespace2
            namespace3

        You can convert the generator into a list by wrapping the generator in a call to the built-in ``list`` function:

        .. code-block:: python

            namespaces = list(index.list_namespaces())

        You should be cautious with this approach because it will fetch all namespaces at once, which could be a large number
        of network calls and a lot of memory to hold the results.
        Fr   Nr   r   Tr[   )r   r   r   rj   r   r   rl   )rF   r   rm   r   r   r   rL   s          rG   list_namespaceszGRPCIndex.list_namespaces  s     @ 8$88OuOO !!c'*<*<&=&A!(!3!3 $I#O$ !!g&8&8&=&=173E3E3J3JKL   s.   B9B& BB9$B9&	B6/B11B66B9argsc                 @    | D ci c]  \  }}|	|| c}}S c c}}w Nr[   )r   arg_namevals      rG   ra   zGRPCIndex._parse_non_empty_args<  s"    37K-(C3?#KKKs   
)FNNT)r   i  TT)NNNNF)NF)	NNNNNNNNF)NNNNN)FNNNN)NNNNr   )NN)8__name__
__module____qualname____doc__propertyrH   r   r   r$   rA   r=   r<   boolr   strri   r'   r9   rt   rg   r   staticmethodr~   r>   r.   r   r   r   floatr0   rC   r;   r   r   r   r4   r   r?   r/   rl   r   r   r^   DescribeIndexStatsResponser   r   r    r   r   r   r   r!   r   r   r   ra   r[   rI   rG   r@   r@   G   s   F! !  #'$("d=tF|T*%5tK7H$J__`d= d= C=	d=
 SMd= d= 
~11	2d=LUJ'U4<SMULTUXMU	U #'"3= 3= 	3=
 !3= 3= 
3=j   $(%)#',0FOd3i FO TNFO C=	FO
 )FO FO 
~11	2FOV $($)	&2d3i &2 C=&2 D>	&2 
}00	1&2T )- #'#,0)-+/ $)[Je%[J SM[J C=	[J
 }[J )[J ![J #4.[J  , 02GGH
[J D>[J 
}00	1[JD  $,0)-+/RV*U* I* ;<	*
 }* )* !* #4.*  &68M&M NO* 
 *^  (,:>#'RVAOAO AO e%	AO
 67AO C=AO  &68M&M NOAO 
~11	2AOJ !%#*.#'7
7
 }7
 #3-	7

 C=7
 
7
r%P 373/3	#3B 55	5 5. //	c3h/ /.   $*.%8}%8 #3-%8
 
 %8 %8N -Xc] - -^ LDsCx$9 Ld38n L LrI   r@   )Vloggingtypingr   r   r   r   r   r   r	   r
   r   google.protobufr   pinecone.utils.tqdmr   pinecone.utilsr   concurrent.futuresr   r   utilsr   r   r   r   r   r   r   r   r   vector_factory_grpcr   sparse_values_factoryr   $pinecone.core.openapi.db_data.modelsr   r   r   r   r    r!   (pinecone.db_control.models.list_responser"   r   r#   -pinecone.core.grpc.protos.db_data_2025_04_pb2r$   rA   r%   rB   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   rC   r1   r2   r3   pinecone)pinecone.db_data.query_results_aggregatorr4   r5   2pinecone.core.grpc.protos.db_data_2025_04_pb2_grpcr7   baser8   rf   r9   db_data.typesr;   r<   r=   r>   r?   __all__	getLoggerr   _loggerr@   r[   rI   rG   <module>r     s     S S S ' $ ) 3
 
 
 3 6  d    $ * d P  &  
'

H
% wL wLrI   