@@ -184,7 +184,7 @@ async def add(
184184 """
185185 return await self .client .add (self .dataset , document , metadata )
186186
187- async def batch_add (self , documents : List [Dict [ str , Any ] ]) -> List [Document ]:
187+ async def batch_add (self , documents : List [AddDocument ]) -> List [Document ]:
188188 """
189189 Add multiple documents to the specified dataset in a single batch asynchronously.
190190
@@ -281,6 +281,26 @@ async def create_max_context(
281281 """
282282 return await self .client .create_max_context (self .dataset , query , max_tokens )
283283
284+ async def update (self , document : Document ) -> Document :
285+ """
286+ Update the documents in the specified dataset asynchronously.
287+
288+ Args:
289+ dataset: The name of the dataset to update.
290+ documents: A list of documents to update.
291+
292+ Returns:
293+ A list of updated documents.
294+
295+ Example usage:
296+ documents = [
297+ {"id": "document_id1", "data": "Updated document 1"},
298+ {"id": "document_id2", "data": "Updated document 2"},
299+ ]
300+ results = await dataset.update(documents)
301+ """
302+ return await self .client .update (self .dataset , document )
303+
284304
285305class EmbedbaseAsyncClient (BaseClient ):
286306 def dataset (self , dataset : str ) -> AsyncDataset :
@@ -648,3 +668,40 @@ async def create_context_for_dataset(d, max_tokens):
648668 contexts .append (context )
649669
650670 return "\n \n " .join (contexts )
671+
672+ async def update (self , dataset : str , documents : List [Document ]) -> List [Document ]:
673+ """
674+ Update the documents in the specified dataset asynchronously.
675+
676+ Args:
677+ dataset: The name of the dataset to update.
678+ documents: A list of documents to update.
679+
680+ Returns:
681+ A list of updated documents.
682+
683+ Example usage:
684+ documents = [
685+ {"id": "document_id1", "data": "Updated document 1"},
686+ {"id": "document_id2", "data": "Updated document 2"},
687+ ]
688+ results = await embedbase.update("my_dataset", documents)
689+ """
690+ update_url = f"{ self .embedbase_url } /{ dataset } "
691+ async with httpx .AsyncClient () as client :
692+ res = await client .put (
693+ update_url ,
694+ headers = self .headers ,
695+ json = {"documents" : [dict (doc ) for doc in documents ]},
696+ timeout = self .timeout ,
697+ )
698+ try :
699+ data = res .json ()
700+ except json .JSONDecodeError :
701+ # pylint: disable=raise-missing-from
702+ raise EmbedbaseAPIException (res .text )
703+
704+ if res .status_code != 200 :
705+ raise EmbedbaseAPIException (data .get ("error" , res .text ))
706+
707+ return [Document (** result ) for result in data ["results" ]]
0 commit comments