diff --git a/packages/uipath-platform/pyproject.toml b/packages/uipath-platform/pyproject.toml index b80e51351..413a6c63c 100644 --- a/packages/uipath-platform/pyproject.toml +++ b/packages/uipath-platform/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath-platform" -version = "0.3.6" +version = "0.3.7" description = "HTTP client library for programmatic access to UiPath Platform" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" diff --git a/packages/uipath-platform/src/uipath/platform/memory/memory.py b/packages/uipath-platform/src/uipath/platform/memory/memory.py index e0ec5d34c..b1973d33e 100644 --- a/packages/uipath-platform/src/uipath/platform/memory/memory.py +++ b/packages/uipath-platform/src/uipath/platform/memory/memory.py @@ -72,7 +72,11 @@ class SearchSettings(BaseModel): class MemoryMatchField(BaseModel): - """A field within a search result, with scoring details.""" + """A field within a search result, with scoring details. + + ``semantic_score`` is the field's vector similarity, as distinct from + ``score``. + """ model_config = ConfigDict(populate_by_name=True) @@ -80,6 +84,7 @@ class MemoryMatchField(BaseModel): value: str = Field(..., alias="value") weight: float = Field(..., alias="weight") score: float = Field(..., alias="score") + semantic_score: Optional[float] = Field(None, alias="semanticScore") weighted_score: float = Field(..., alias="weightedScore") diff --git a/packages/uipath-platform/tests/services/test_memory_service.py b/packages/uipath-platform/tests/services/test_memory_service.py index 084fe2587..9a5245ab6 100644 --- a/packages/uipath-platform/tests/services/test_memory_service.py +++ b/packages/uipath-platform/tests/services/test_memory_service.py @@ -76,6 +76,7 @@ def service( "value": "What is the capital of France?", "weight": 1.0, "score": 0.95, + "semanticScore": 0.91, "weightedScore": 0.95, } ], @@ -284,6 +285,7 @@ def test_search_memory( assert result.results[0].memory_item_id == "item-001" assert result.results[0].score == 0.95 assert isinstance(result.results[0].fields[0], MemoryMatchField) + assert result.results[0].fields[0].semantic_score == 0.91 assert ( result.system_prompt_injection == "Based on past interactions: Paris is the capital." @@ -298,6 +300,31 @@ def test_search_memory( assert body["settings"]["fieldMatching"] == "Or" assert body["definitionSystemPrompt"] == "You are a helpful assistant." + def test_search_response_keeps_field_semantic_score_in_dump(self) -> None: + response = MemorySearchResponse.model_validate(SAMPLE_SEARCH_RESPONSE) + + dumped = response.model_dump(by_alias=True, exclude_none=True) + + field = dumped["results"][0]["fields"][0] + assert field["semanticScore"] == 0.91 + assert field["score"] == 0.95 + + def test_search_response_field_semantic_score_is_optional(self) -> None: + field = MemoryMatchField.model_validate( + { + "keyPath": ["agent-input", "topic"], + "value": "python", + "weight": 1.0, + "score": 0.5, + "weightedScore": 0.5, + } + ) + + assert field.semantic_score is None + assert "semanticScore" not in field.model_dump( + by_alias=True, exclude_none=True + ) + @pytest.mark.parametrize( ("raw", "expected"), [ diff --git a/packages/uipath-platform/uv.lock b/packages/uipath-platform/uv.lock index 2d859d395..4530e2ed5 100644 --- a/packages/uipath-platform/uv.lock +++ b/packages/uipath-platform/uv.lock @@ -1095,7 +1095,7 @@ dev = [ [[package]] name = "uipath-platform" -version = "0.3.6" +version = "0.3.7" source = { editable = "." } dependencies = [ { name = "anyio" }, diff --git a/packages/uipath/uv.lock b/packages/uipath/uv.lock index 73de2e882..6b4d34ce2 100644 --- a/packages/uipath/uv.lock +++ b/packages/uipath/uv.lock @@ -2762,7 +2762,7 @@ wheels = [ [[package]] name = "uipath-platform" -version = "0.3.6" +version = "0.3.7" source = { editable = "../uipath-platform" } dependencies = [ { name = "anyio" },