From 2b7854ad9352ec962484cf4deae994178adda56c Mon Sep 17 00:00:00 2001 From: tolgadevAI <164843802+tolgadevAI@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:56:13 +0300 Subject: [PATCH] develop the case "merge-force-local" --- .gitignore | 1 + semantic_router/index/base.py | 6 +++--- semantic_router/index/pinecone.py | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index f571c929..094c61f4 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ node_modules package-lock.json package.json test.ipynb +test_sync.ipynb ``` # docs diff --git a/semantic_router/index/base.py b/semantic_router/index/base.py index 73467887..9d824661 100644 --- a/semantic_router/index/base.py +++ b/semantic_router/index/base.py @@ -122,9 +122,9 @@ class BaseIndex(BaseModel): - "error": Raise an error if local and remote are not synchronized. - "remote": Take remote as the source of truth and update local to align. - "local": Take local as the source of truth and update remote to align. - - "merge-force-remote": Merge both local and remote taking only remote routes utterances when a route with same route name is present both locally and remotely. - - "merge-force-local": Merge both local and remote taking only local routes utterances when a route with same route name is present both locally and remotely. - - "merge": Merge both local and remote, merging also local and remote utterances when a route with same route name is present both locally and remotely. + - "merge-force-remote": Merge both local and remote taking only remote routes features when a route with same route name is present both locally and remotely. + - "merge-force-local": Merge both local and remote taking only local routes features when a route with same route name is present both locally and remotely. + - "merge": Merge both local and remote, merging also local and remote features when a route with same route name is present both locally and remotely. This method should be implemented by subclasses. """ diff --git a/semantic_router/index/pinecone.py b/semantic_router/index/pinecone.py index 1016a7b5..cb2f58ca 100644 --- a/semantic_router/index/pinecone.py +++ b/semantic_router/index/pinecone.py @@ -292,7 +292,6 @@ class PineconeIndex(BaseIndex): layer_routes[route][ "function_schemas" ] = remote_function_schemas_dict - elif self.sync == "local": utterances_to_include = local_utterances_set - remote_utterances_set routes_to_delete.extend( @@ -304,7 +303,7 @@ class PineconeIndex(BaseIndex): ) layer_routes[route] = {} if local_utterances_set: - layer_routes[route]["utterances"] = list(local_utterances_set) + layer_routes[route] = {"utterances": list(local_utterances_set)} if local_function_schemas_dict: layer_routes[route][ "function_schemas" @@ -340,12 +339,19 @@ class PineconeIndex(BaseIndex): ) if local_utterances_set: layer_routes[route] = {"utterances": list(local_utterances_set)} + if local_function_schemas_dict: + layer_routes[route][ + "function_schemas" + ] = local_function_schemas_dict else: if remote_utterances_set: layer_routes[route] = { "utterances": list(remote_utterances_set) } - + if remote_function_schemas_dict: + layer_routes[route][ + "function_schemas" + ] = remote_function_schemas_dict elif self.sync == "merge": utterances_to_include = local_utterances_set - remote_utterances_set if local_utterances_set or remote_utterances_set: -- GitLab