1
1
from tqdm .autonotebook import tqdm
2
2
3
3
from collections .abc import Iterable
4
- from typing import Union , List , Tuple , Optional , Dict , Any
4
+ from typing import Mapping , Union , List , Tuple , Optional , Dict , Any
5
5
6
6
from pinecone .config import ConfigBuilder
7
7
@@ -74,12 +74,12 @@ def __init__(
74
74
api_key : str ,
75
75
host : str ,
76
76
pool_threads : Optional [int ] = 1 ,
77
- additional_headers : Optional [Dict [str , str ]] = {},
77
+ additional_headers : Optional [Mapping [str , str ]] = {},
78
78
** kwargs
79
79
):
80
80
self ._config = ConfigBuilder .build (api_key = api_key , host = host , ** kwargs )
81
-
82
- api_client = ApiClient (configuration = self ._config .openapi_config ,
81
+
82
+ api_client = ApiClient (configuration = self ._config .openapi_config ,
83
83
pool_threads = pool_threads )
84
84
85
85
# Configure request headers
@@ -90,7 +90,7 @@ def __init__(
90
90
91
91
self ._api_client = api_client
92
92
self ._vector_api = VectorOperationsApi (api_client = api_client )
93
-
93
+
94
94
def __enter__ (self ):
95
95
return self
96
96
@@ -245,7 +245,7 @@ def delete(
245
245
ids : Optional [List [str ]] = None ,
246
246
delete_all : Optional [bool ] = None ,
247
247
namespace : Optional [str ] = None ,
248
- filter : Optional [Dict [str , Union [str , float , int , bool , List , dict ]]] = None ,
248
+ filter : Optional [Mapping [str , Union [str , float , int , bool , List , dict ]]] = None ,
249
249
** kwargs ,
250
250
) -> Dict [str , Any ]:
251
251
"""
@@ -272,7 +272,7 @@ def delete(
272
272
Default is False.
273
273
namespace (str): The namespace to delete vectors from [optional]
274
274
If not specified, the default namespace is used.
275
- filter (Dict [str, Union[str, float, int, bool, List, dict]]):
275
+ filter (Mapping [str, Union[str, float, int, bool, List, dict]]):
276
276
If specified, the metadata filter here will be used to select the vectors to delete.
277
277
This is mutually exclusive with specifying ids to delete in the ids param or using delete_all=True.
278
278
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
@@ -330,10 +330,10 @@ def query(
330
330
vector : Optional [List [float ]] = None ,
331
331
id : Optional [str ] = None ,
332
332
namespace : Optional [str ] = None ,
333
- filter : Optional [Dict [str , Union [str , float , int , bool , List , dict ]]] = None ,
333
+ filter : Optional [Mapping [str , Union [str , float , int , bool , List , dict ]]] = None ,
334
334
include_values : Optional [bool ] = None ,
335
335
include_metadata : Optional [bool ] = None ,
336
- sparse_vector : Optional [Union [SparseValues , Dict [str , Union [List [float ], List [int ]]]]] = None ,
336
+ sparse_vector : Optional [Union [SparseValues , Mapping [str , Union [List [float ], List [int ]]]]] = None ,
337
337
** kwargs ,
338
338
) -> QueryResponse :
339
339
"""
@@ -362,17 +362,17 @@ def query(
362
362
top_k (int): The number of results to return for each query. Must be an integer greater than 1.
363
363
namespace (str): The namespace to fetch vectors from.
364
364
If not specified, the default namespace is used. [optional]
365
- filter (Dict [str, Union[str, float, int, bool, List, dict]):
365
+ filter (Mapping [str, Union[str, float, int, bool, List, dict]):
366
366
The filter to apply. You can use vector metadata to limit your search.
367
367
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
368
368
include_values (bool): Indicates whether vector values are included in the response.
369
369
If omitted the server will use the default value of False [optional]
370
370
include_metadata (bool): Indicates whether metadata is included in the response as well as the ids.
371
371
If omitted the server will use the default value of False [optional]
372
- sparse_vector: (Union[SparseValues, Dict [str, Union[List[float], List[int]]]]): sparse values of the query vector.
372
+ sparse_vector: (Union[SparseValues, Mapping [str, Union[List[float], List[int]]]]): sparse values of the query vector.
373
373
Expected to be either a SparseValues object or a dict of the form:
374
374
{'indices': List[int], 'values': List[float]}, where the lists each have the same length.
375
-
375
+
376
376
Returns: QueryResponse object which contains the list of the closest vectors as ScoredVector objects,
377
377
and namespace name.
378
378
"""
@@ -414,9 +414,9 @@ def update(
414
414
self ,
415
415
id : str ,
416
416
values : Optional [List [float ]] = None ,
417
- set_metadata : Optional [Dict [str , Union [str , float , int , bool , List [int ], List [float ], List [str ]]]] = None ,
417
+ set_metadata : Optional [Mapping [str , Union [str , float , int , bool , List [int ], List [float ], List [str ]]]] = None ,
418
418
namespace : Optional [str ] = None ,
419
- sparse_values : Optional [Union [SparseValues , Dict [str , Union [List [float ], List [int ]]]]] = None ,
419
+ sparse_values : Optional [Union [SparseValues , Mapping [str , Union [List [float ], List [int ]]]]] = None ,
420
420
** kwargs ,
421
421
) -> Dict [str , Any ]:
422
422
"""
@@ -438,10 +438,10 @@ def update(
438
438
Args:
439
439
id (str): Vector's unique id.
440
440
values (List[float]): vector values to set. [optional]
441
- set_metadata (Dict [str, Union[str, float, int, bool, List[int], List[float], List[str]]]]):
441
+ set_metadata (Mapping [str, Union[str, float, int, bool, List[int], List[float], List[str]]]]):
442
442
metadata to set for vector. [optional]
443
443
namespace (str): Namespace name where to update the vector.. [optional]
444
- sparse_values: (Dict [str, Union[List[float], List[int]]]): sparse values to update for the vector.
444
+ sparse_values: (Mapping [str, Union[List[float], List[int]]]): sparse values to update for the vector.
445
445
Expected to be either a SparseValues object or a dict of the form:
446
446
{'indices': List[int], 'values': List[float]} where the lists each have the same length.
447
447
@@ -472,7 +472,7 @@ def update(
472
472
473
473
@validate_and_convert_errors
474
474
def describe_index_stats (
475
- self , filter : Optional [Dict [str , Union [str , float , int , bool , List , dict ]]] = None , ** kwargs
475
+ self , filter : Optional [Mapping [str , Union [str , float , int , bool , List , dict ]]] = None , ** kwargs
476
476
) -> DescribeIndexStatsResponse :
477
477
"""
478
478
The DescribeIndexStats operation returns statistics about the index's contents.
@@ -485,7 +485,7 @@ def describe_index_stats(
485
485
>>> index.describe_index_stats(filter={'key': 'value'})
486
486
487
487
Args:
488
- filter (Dict [str, Union[str, float, int, bool, List, dict]]):
488
+ filter (Mapping [str, Union[str, float, int, bool, List, dict]]):
489
489
If this parameter is present, the operation only returns statistics for vectors that satisfy the filter.
490
490
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
491
491
@@ -509,15 +509,15 @@ def _parse_non_empty_args(args: List[Tuple[str, Any]]) -> Dict[str, Any]:
509
509
510
510
@staticmethod
511
511
def _parse_sparse_values_arg (
512
- sparse_values : Optional [Union [SparseValues , Dict [str , Union [List [float ], List [int ]]]]]
512
+ sparse_values : Optional [Union [SparseValues , Mapping [str , Union [List [float ], List [int ]]]]]
513
513
) -> Optional [SparseValues ]:
514
514
if sparse_values is None :
515
515
return None
516
516
517
517
if isinstance (sparse_values , SparseValues ):
518
518
return sparse_values
519
519
520
- if not isinstance (sparse_values , dict ) or "indices" not in sparse_values or "values" not in sparse_values :
520
+ if not isinstance (sparse_values , Mapping ) or "indices" not in sparse_values or "values" not in sparse_values :
521
521
raise ValueError (
522
522
"Invalid sparse values argument. Expected a dict of: {'indices': List[int], 'values': List[float]}."
523
523
f"Received: { sparse_values } "
0 commit comments