Skip to content

Commit ffb2a90

Browse files
authored
Merge pull request #391 from aurelio-labs/tolga/function-schemas
feat: optimize local/remote routes flow and store them on Pinecone
2 parents b17ea3d + 6b650b1 commit ffb2a90

File tree

9 files changed

+325
-98
lines changed

9 files changed

+325
-98
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ node_modules
2727
package-lock.json
2828
package.json
2929
test.ipynb
30+
test_sync.ipynb
3031
```
3132

3233
# docs

semantic_router/index/base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def add(
2626
embeddings: List[List[float]],
2727
routes: List[str],
2828
utterances: List[Any],
29+
function_schemas: Optional[List[Dict[str, Any]]] = None,
30+
metadata_list: List[Dict[str, Any]] = [],
2931
):
3032
"""
3133
Add embeddings to the index.
@@ -109,17 +111,22 @@ def delete_index(self):
109111
raise NotImplementedError("This method should be implemented by subclasses.")
110112

111113
def _sync_index(
112-
self, local_route_names: List[str], local_utterances: List[str], dimensions: int
114+
self,
115+
local_route_names: List[str],
116+
local_utterances: List[str],
117+
local_function_schemas: List[Dict[str, Any]],
118+
local_metadata: List[Dict[str, Any]],
119+
dimensions: int,
113120
):
114121
"""
115122
Synchronize the local index with the remote index based on the specified mode.
116123
Modes:
117124
- "error": Raise an error if local and remote are not synchronized.
118125
- "remote": Take remote as the source of truth and update local to align.
119126
- "local": Take local as the source of truth and update remote to align.
120-
- "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.
121-
- "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.
122-
- "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.
127+
- "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.
128+
- "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.
129+
- "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.
123130
124131
This method should be implemented by subclasses.
125132
"""

semantic_router/index/local.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from semantic_router.index.base import BaseIndex
66
from semantic_router.linear import similarity_matrix, top_scores
77
from semantic_router.utils.logger import logger
8+
from typing import Any
89

910

1011
class LocalIndex(BaseIndex):
@@ -26,6 +27,8 @@ def add(
2627
embeddings: List[List[float]],
2728
routes: List[str],
2829
utterances: List[str],
30+
function_schemas: Optional[List[Dict[str, Any]]] = None,
31+
metadata_list: List[Dict[str, Any]] = [],
2932
):
3033
embeds = np.array(embeddings) # type: ignore
3134
routes_arr = np.array(routes)
@@ -47,7 +50,12 @@ def _remove_and_sync(self, routes_to_delete: dict):
4750
logger.warning("Sync remove is not implemented for LocalIndex.")
4851

4952
def _sync_index(
50-
self, local_route_names: List[str], local_utterances: List[str], dimensions: int
53+
self,
54+
local_route_names: List[str],
55+
local_utterances: List[str],
56+
local_function_schemas: List[Dict[str, Any]],
57+
local_metadata: List[Dict[str, Any]],
58+
dimensions: int,
5159
):
5260
if self.sync is not None:
5361
logger.error("Sync remove is not implemented for LocalIndex.")

0 commit comments

Comments
 (0)