Skip to content

Commit 4613a60

Browse files
authored
feat: add support for folder scoped ephemeral index creation [ECS-1745] (#1574)
1 parent 298ca3a commit 4613a60

5 files changed

Lines changed: 91 additions & 6 deletions

File tree

packages/uipath-platform/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-platform"
3-
version = "0.1.29"
3+
version = "0.1.30"
44
description = "HTTP client library for programmatic access to UiPath Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath-platform/src/uipath/platform/context_grounding/_context_grounding_service.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,20 +598,29 @@ async def create_index_async(
598598
@resource_override(resource_type="index")
599599
@traced(name="contextgrounding_create_ephemeral_index", run_type="uipath")
600600
def create_ephemeral_index(
601-
self, usage: EphemeralIndexUsage, attachments: List[str]
601+
self,
602+
usage: EphemeralIndexUsage,
603+
attachments: List[str],
604+
folder_key: str | None = None,
605+
folder_path: str | None = None,
602606
) -> ContextGroundingIndex:
603607
"""Create a new ephemeral context grounding index.
604608
605609
Args:
606610
usage (EphemeralIndexUsage): The task type for the ephemeral index (DeepRAG or BatchRAG)
607611
attachments (list[str]): The list of attachments ids from which the ephemeral index will be created
612+
folder_key (Optional[str]): The folder key to scope the ephemeral index to.
613+
folder_path (Optional[str]): The folder path to scope the ephemeral index to (resolved to a key if folder_key is not provided).
608614
609615
Returns:
610616
ContextGroundingIndex: The created index information.
611617
"""
618+
if folder_key is not None or folder_path is not None:
619+
folder_key = self._resolve_folder_key(folder_key, folder_path)
612620
spec = self._create_ephemeral_spec(
613621
usage,
614622
attachments,
623+
folder_key=folder_key,
615624
)
616625

617626
response = self.request(
@@ -626,20 +635,29 @@ def create_ephemeral_index(
626635
@resource_override(resource_type="index")
627636
@traced(name="contextgrounding_create_ephemeral_index", run_type="uipath")
628637
async def create_ephemeral_index_async(
629-
self, usage: EphemeralIndexUsage, attachments: List[str]
638+
self,
639+
usage: EphemeralIndexUsage,
640+
attachments: List[str],
641+
folder_key: str | None = None,
642+
folder_path: str | None = None,
630643
) -> ContextGroundingIndex:
631644
"""Create a new ephemeral context grounding index.
632645
633646
Args:
634647
usage (EphemeralIndexUsage): The task type for the ephemeral index (DeepRAG or BatchRAG)
635648
attachments (list[str]): The list of attachments ids from which the ephemeral index will be created
649+
folder_key (Optional[str]): The folder key to scope the ephemeral index to.
650+
folder_path (Optional[str]): The folder path to scope the ephemeral index to (resolved to a key if folder_key is not provided).
636651
637652
Returns:
638653
ContextGroundingIndex: The created index information.
639654
"""
655+
if folder_key is not None or folder_path is not None:
656+
folder_key = self._resolve_folder_key(folder_key, folder_path)
640657
spec = self._create_ephemeral_spec(
641658
usage,
642659
attachments,
660+
folder_key=folder_key,
643661
)
644662

645663
response = await self.request_async(
@@ -1991,12 +2009,14 @@ def _create_ephemeral_spec(
19912009
self,
19922010
usage: str,
19932011
attachments: List[str],
2012+
folder_key: str | None = None,
19942013
) -> RequestSpec:
19952014
"""Create request spec for ephemeral index creation.
19962015
19972016
Args:
19982017
usage (str): The task in which the ephemeral index will be used for
19992018
attachments (list[str]): The list of attachments ids from which the ephemeral index will be created
2019+
folder_key (Optional[str]): The folder key to scope the ephemeral index to.
20002020
20012021
Returns:
20022022
RequestSpec for the create index request
@@ -2012,7 +2032,7 @@ def _create_ephemeral_spec(
20122032
method="POST",
20132033
endpoint=Endpoint("/ecs_/v2/indexes/createephemeral"),
20142034
json=payload.model_dump(by_alias=True, exclude_none=True),
2015-
headers={},
2035+
headers={**header_folder(folder_key, None)},
20162036
)
20172037

20182038
def _build_data_source(self, source: SourceConfig) -> Dict[str, Any]:

packages/uipath-platform/tests/services/test_context_grounding_service.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,71 @@ async def test_create_ephemeral_index_async(
27492749
== f"UiPath.Python.Sdk/UiPath.Python.Sdk.Activities.ContextGroundingService.create_ephemeral_index_async/{version}"
27502750
)
27512751

2752+
def test_create_ephemeral_index_with_folder_key(
2753+
self,
2754+
httpx_mock: HTTPXMock,
2755+
service: ContextGroundingService,
2756+
base_url: str,
2757+
org: str,
2758+
tenant: str,
2759+
) -> None:
2760+
import uuid
2761+
2762+
httpx_mock.add_response(
2763+
url=f"{base_url}{org}{tenant}/ecs_/v2/indexes/createephemeral",
2764+
status_code=200,
2765+
json={
2766+
"id": "ephemeral-index-id",
2767+
"name": "ephemeral-index",
2768+
"lastIngestionStatus": "Queued",
2769+
},
2770+
)
2771+
2772+
attachment_ids = [str(uuid.uuid4())]
2773+
service.create_ephemeral_index(
2774+
usage="DeepRAG",
2775+
attachments=attachment_ids,
2776+
folder_key="test-folder-key",
2777+
)
2778+
2779+
sent_requests = httpx_mock.get_requests()
2780+
assert sent_requests is not None
2781+
assert "x-uipath-folderkey" in sent_requests[0].headers
2782+
assert sent_requests[0].headers["x-uipath-folderkey"] == "test-folder-key"
2783+
2784+
@pytest.mark.anyio
2785+
async def test_create_ephemeral_index_async_with_folder_key(
2786+
self,
2787+
httpx_mock: HTTPXMock,
2788+
service: ContextGroundingService,
2789+
base_url: str,
2790+
org: str,
2791+
tenant: str,
2792+
) -> None:
2793+
import uuid
2794+
2795+
httpx_mock.add_response(
2796+
url=f"{base_url}{org}{tenant}/ecs_/v2/indexes/createephemeral",
2797+
status_code=200,
2798+
json={
2799+
"id": "ephemeral-index-id",
2800+
"name": "ephemeral-index",
2801+
"lastIngestionStatus": "Queued",
2802+
},
2803+
)
2804+
2805+
attachment_ids = [str(uuid.uuid4())]
2806+
await service.create_ephemeral_index_async(
2807+
usage="DeepRAG",
2808+
attachments=attachment_ids,
2809+
folder_key="test-folder-key",
2810+
)
2811+
2812+
sent_requests = httpx_mock.get_requests()
2813+
assert sent_requests is not None
2814+
assert "x-uipath-folderkey" in sent_requests[0].headers
2815+
assert sent_requests[0].headers["x-uipath-folderkey"] == "test-folder-key"
2816+
27522817
@pytest.mark.anyio
27532818
async def test_download_batch_transform_result_async_creates_nested_directories(
27542819
self,

packages/uipath-platform/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uipath/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)