@@ -95,10 +95,12 @@ def __init__(
9595 api_key : str ,
9696 host : str ,
9797 pool_threads : Optional [int ] = None ,
98- additional_headers : Optional [Dict [str , str ]] = {} ,
98+ additional_headers : Optional [Dict [str , str ]] = None ,
9999 openapi_config = None ,
100100 ** kwargs ,
101101 ):
102+ if additional_headers is None :
103+ additional_headers = {}
102104 self ._config = ConfigBuilder .build (
103105 api_key = api_key , host = host , additional_headers = additional_headers , ** kwargs
104106 )
@@ -133,8 +135,8 @@ def __init__(
133135 self ._namespace_resource = None
134136 """ :meta private: """
135137
136- # Pass the same api_client to the ImportFeatureMixin
137- super ().__init__ (api_client = self . _api_client )
138+ # Initialize PluginAware parent class
139+ super ().__init__ ()
138140
139141 @property
140142 def config (self ) -> "Config" :
@@ -281,7 +283,47 @@ def upsert_from_dataframe(
281283
282284 return UpsertResponse (upserted_count = upserted_count )
283285
284- def upsert_records (self , namespace : str , records : List [Dict ]):
286+ @validate_and_convert_errors
287+ def upsert_records (self , namespace : str , records : List [Dict [str , Any ]]):
288+ """Upsert records to a namespace.
289+
290+ Upsert records to a namespace. A record is a dictionary that contains either an ``id`` or ``_id``
291+ field along with other fields that will be stored as metadata. The ``id`` or ``_id`` field is used
292+ as the unique identifier for the record. At least one field in the record should correspond to
293+ a field mapping in the index's embed configuration.
294+
295+ When records are upserted, Pinecone converts mapped fields into embeddings and upserts them into
296+ the specified namespace of the index.
297+
298+ Args:
299+ namespace (str): The namespace of the index to upsert records to.
300+ records (List[Dict[str, Any]]): The records to upsert into the index.
301+ Each record should contain either an ``id`` or ``_id`` field.
302+
303+ Examples:
304+
305+ .. code-block:: python
306+
307+ >>> from pinecone import Pinecone, CloudProvider, AwsRegion, EmbedModel, IndexEmbed
308+ >>> pc = Pinecone(api_key="<<PINECONE_API_KEY>>")
309+ >>> index_model = pc.create_index_for_model(
310+ ... name="my-model-index",
311+ ... cloud=CloudProvider.AWS,
312+ ... region=AwsRegion.US_WEST_2,
313+ ... embed=IndexEmbed(
314+ ... model=EmbedModel.Multilingual_E5_Large,
315+ ... field_map={"text": "my_text_field"}
316+ ... )
317+ ... )
318+ >>> idx = pc.Index(host=index_model.host)
319+ >>> idx.upsert_records(
320+ ... namespace="my-namespace",
321+ ... records=[
322+ ... {"_id": "test1", "my_text_field": "Apple is a popular fruit."},
323+ ... {"_id": "test2", "my_text_field": "The tech company Apple is innovative."},
324+ ... ],
325+ ... )
326+ """
285327 args = IndexRequestFactory .upsert_records_args (namespace = namespace , records = records )
286328 self ._vector_api .upsert_records_namespace (** args )
287329
@@ -293,9 +335,6 @@ def search(
293335 rerank : Optional [Union [SearchRerankTypedDict , SearchRerank ]] = None ,
294336 fields : Optional [List [str ]] = ["*" ], # Default to returning all fields
295337 ) -> SearchRecordsResponse :
296- if namespace is None :
297- raise Exception ("Namespace is required when searching records" )
298-
299338 request = IndexRequestFactory .search_request (query = query , rerank = rerank , fields = fields )
300339
301340 return self ._vector_api .search_records_namespace (namespace , request )
0 commit comments