33
44import httpx
55from pydantic import Field , TypeAdapter
6- from typing_extensions import deprecated
76
87from ..._utils import Endpoint , RequestSpec , header_folder , resource_override
98from ..._utils ._ssl_context import get_httpx_client_kwargs
3029 ContextGroundingQueryResponse ,
3130 DeepRagCreationResponse ,
3231 DeepRagResponse ,
32+ EphemeralIndexUsage ,
3333)
3434from .context_grounding_index import ContextGroundingIndex
3535from .context_grounding_payloads import (
36+ AttachmentsDataSource ,
3637 BucketDataSource ,
3738 BucketSourceConfig ,
3839 ConfluenceDataSource ,
3940 ConfluenceSourceConfig ,
41+ CreateEphemeralIndexPayload ,
4042 CreateIndexPayload ,
4143 DropboxDataSource ,
4244 DropboxSourceConfig ,
@@ -276,7 +278,6 @@ async def retrieve_async(
276278 raise Exception ("ContextGroundingIndex not found" ) from e
277279
278280 @traced (name = "contextgrounding_retrieve_by_id" , run_type = "uipath" )
279- @deprecated ("Use retrieve instead" )
280281 def retrieve_by_id (
281282 self ,
282283 id : str ,
@@ -296,11 +297,7 @@ def retrieve_by_id(
296297 Returns:
297298 Any: The index information, including its configuration and metadata.
298299 """
299- spec = self ._retrieve_by_id_spec (
300- id ,
301- folder_key = folder_key ,
302- folder_path = folder_path ,
303- )
300+ spec = self ._retrieve_by_id_spec (id )
304301
305302 return self .request (
306303 spec .method ,
@@ -309,7 +306,6 @@ def retrieve_by_id(
309306 ).json ()
310307
311308 @traced (name = "contextgrounding_retrieve_by_id" , run_type = "uipath" )
312- @deprecated ("Use retrieve_async instead" )
313309 async def retrieve_by_id_async (
314310 self ,
315311 id : str ,
@@ -329,11 +325,7 @@ async def retrieve_by_id_async(
329325 Returns:
330326 Any: The index information, including its configuration and metadata.
331327 """
332- spec = self ._retrieve_by_id_spec (
333- id ,
334- folder_key = folder_key ,
335- folder_path = folder_path ,
336- )
328+ spec = self ._retrieve_by_id_spec (id )
337329
338330 response = await self .request_async (
339331 spec .method ,
@@ -453,6 +445,66 @@ async def create_index_async(
453445
454446 return ContextGroundingIndex .model_validate (response .json ())
455447
448+ @resource_override (resource_type = "index" )
449+ @traced (name = "contextgrounding_create_ephemeral_index" , run_type = "uipath" )
450+ def create_ephemeral_index (
451+ self ,
452+ usage : EphemeralIndexUsage ,
453+ attachments : list [str ],
454+ ) -> ContextGroundingIndex :
455+ """Create a new ephemeral context grounding index.
456+
457+ Args:
458+ usage (EphemeralIndexUsage): The task type for the ephemeral index (DeepRAG or BatchRAG)
459+ attachments (list[str]): The list of attachments ids from which the ephemeral index will be created
460+
461+ Returns:
462+ ContextGroundingIndex: The created index information.
463+ """
464+ spec = self ._create_ephemeral_spec (
465+ usage ,
466+ attachments ,
467+ )
468+
469+ response = self .request (
470+ spec .method ,
471+ spec .endpoint ,
472+ json = spec .json ,
473+ headers = spec .headers ,
474+ )
475+
476+ return ContextGroundingIndex .model_validate (response .json ())
477+
478+ @resource_override (resource_type = "index" )
479+ @traced (name = "contextgrounding_create_ephemeral_index" , run_type = "uipath" )
480+ async def create_ephemeral_index_async (
481+ self ,
482+ usage : EphemeralIndexUsage ,
483+ attachments : list [str ],
484+ ) -> ContextGroundingIndex :
485+ """Create a new ephemeral context grounding index.
486+
487+ Args:
488+ usage (EphemeralIndexUsage): The task type for the ephemeral index (DeepRAG or BatchRAG)
489+ attachments (list[str]): The list of attachments ids from which the ephemeral index will be created
490+
491+ Returns:
492+ ContextGroundingIndex: The created index information.
493+ """
494+ spec = self ._create_ephemeral_spec (
495+ usage ,
496+ attachments ,
497+ )
498+
499+ response = await self .request_async (
500+ spec .method ,
501+ spec .endpoint ,
502+ json = spec .json ,
503+ headers = spec .headers ,
504+ )
505+
506+ return ContextGroundingIndex .model_validate (response .json ())
507+
456508 @resource_override (resource_type = "index" , resource_identifier = "index_name" )
457509 @traced (name = "contextgrounding_retrieve_deep_rag" , run_type = "uipath" )
458510 def retrieve_deep_rag (
@@ -1197,6 +1249,34 @@ def _create_spec(
11971249 },
11981250 )
11991251
1252+ def _create_ephemeral_spec (
1253+ self ,
1254+ usage : str ,
1255+ attachments : list [str ],
1256+ ) -> RequestSpec :
1257+ """Create request spec for ephemeral index creation.
1258+
1259+ Args:
1260+ usage (str): The task in which the ephemeral index will be used for
1261+ attachments (list[str]): The list of attachments ids from which the ephemeral index will be created
1262+
1263+ Returns:
1264+ RequestSpec for the create index request
1265+ """
1266+ data_source_dict = self ._build_ephemeral_data_source (attachments )
1267+
1268+ payload = CreateEphemeralIndexPayload (
1269+ usage = usage ,
1270+ data_source = data_source_dict ,
1271+ )
1272+
1273+ return RequestSpec (
1274+ method = "POST" ,
1275+ endpoint = Endpoint ("/ecs_/v2/indexes/createephemeral" ),
1276+ json = payload .model_dump (by_alias = True , exclude_none = True ),
1277+ headers = {},
1278+ )
1279+
12001280 def _build_data_source (self , source : SourceConfig ) -> Dict [str , Any ]:
12011281 """Build data source configuration from typed source config.
12021282
@@ -1265,14 +1345,29 @@ def _build_data_source(self, source: SourceConfig) -> Dict[str, Any]:
12651345
12661346 return data_source .model_dump (by_alias = True , exclude_none = True )
12671347
1348+ def _build_ephemeral_data_source (self , attachments : list [str ]) -> Dict [str , Any ]:
1349+ """Build data source configuration from typed source config.
1350+
1351+ Args:
1352+ attachments (list[str]): The list of attachments ids from which the ephemeral index will be created
1353+
1354+ Returns:
1355+ Dictionary with data source configuration for API
1356+ """
1357+ data_source = AttachmentsDataSource (attachments = attachments )
1358+ return data_source .model_dump (
1359+ by_alias = True ,
1360+ exclude_none = True ,
1361+ mode = "json" ,
1362+ )
1363+
12681364 def _retrieve_by_id_spec (
12691365 self ,
12701366 id : str ,
12711367 folder_key : Optional [str ] = None ,
12721368 folder_path : Optional [str ] = None ,
12731369 ) -> RequestSpec :
12741370 folder_key = self ._resolve_folder_key (folder_key , folder_path )
1275-
12761371 return RequestSpec (
12771372 method = "GET" ,
12781373 endpoint = Endpoint (f"/ecs_/v2/indexes/{ id } " ),
@@ -1422,9 +1517,6 @@ def _resolve_folder_key(self, folder_key, folder_path):
14221517 else None
14231518 )
14241519
1425- if folder_key is None :
1426- raise ValueError ("ContextGrounding: Failed to resolve folder key" )
1427-
14281520 return folder_key
14291521
14301522 def _extract_bucket_info (self , index : ContextGroundingIndex ) -> Tuple [str , str ]:
0 commit comments