Skip to content

Commit

Permalink
Merge pull request #391 from aurelio-labs/tolga/function-schemas
Browse files Browse the repository at this point in the history
feat: optimize local/remote routes flow and store them on Pinecone
  • Loading branch information
jamescalam committed Sep 2, 2024
2 parents b17ea3d + 6b650b1 commit ffb2a90
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ node_modules
package-lock.json
package.json
test.ipynb
test_sync.ipynb
```

# docs
Expand Down
15 changes: 11 additions & 4 deletions semantic_router/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def add(
embeddings: List[List[float]],
routes: List[str],
utterances: List[Any],
function_schemas: Optional[List[Dict[str, Any]]] = None,
metadata_list: List[Dict[str, Any]] = [],
):
"""
Add embeddings to the index.
Expand Down Expand Up @@ -109,17 +111,22 @@ def delete_index(self):
raise NotImplementedError("This method should be implemented by subclasses.")

def _sync_index(
self, local_route_names: List[str], local_utterances: List[str], dimensions: int
self,
local_route_names: List[str],
local_utterances: List[str],
local_function_schemas: List[Dict[str, Any]],
local_metadata: List[Dict[str, Any]],
dimensions: int,
):
"""
Synchronize the local index with the remote index based on the specified mode.
Modes:
- "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.
"""
Expand Down
10 changes: 9 additions & 1 deletion semantic_router/index/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from semantic_router.index.base import BaseIndex
from semantic_router.linear import similarity_matrix, top_scores
from semantic_router.utils.logger import logger
from typing import Any


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

def _sync_index(
self, local_route_names: List[str], local_utterances: List[str], dimensions: int
self,
local_route_names: List[str],
local_utterances: List[str],
local_function_schemas: List[Dict[str, Any]],
local_metadata: List[Dict[str, Any]],
dimensions: int,
):
if self.sync is not None:
logger.error("Sync remove is not implemented for LocalIndex.")
Expand Down
Loading

0 comments on commit ffb2a90

Please sign in to comment.