diff --git a/semantic_router/index/base.py b/semantic_router/index/base.py index 44bbecf9c949115b31ee8fcc1c93726accbc4ed9..08c6ad6c77fec6bb0b2a119c8654ff720036abbc 100644 --- a/semantic_router/index/base.py +++ b/semantic_router/index/base.py @@ -113,8 +113,8 @@ class BaseIndex(BaseModel): self, local_route_names: List[str], local_utterances: List[str], - local_function_schemas: List[Dict[str, Any]], dimensions: int, + local_function_schemas: List[Dict[str, Any]], ): """ Synchronize the local index with the remote index based on the specified mode. diff --git a/semantic_router/index/local.py b/semantic_router/index/local.py index e979c40b3699d157a0d0dd32f635b25c2cd6a95e..68a859b5ed7049f6043558e8cb129338c641ec56 100644 --- a/semantic_router/index/local.py +++ b/semantic_router/index/local.py @@ -52,8 +52,8 @@ class LocalIndex(BaseIndex): self, local_route_names: List[str], local_utterances: List[str], - local_function_schemas: List[Dict[str, Any]], dimensions: int, + local_function_schemas: List[Dict[str, Any]], ): if self.sync is not None: logger.error("Sync remove is not implemented for LocalIndex.") diff --git a/semantic_router/index/pinecone.py b/semantic_router/index/pinecone.py index 875a488cd2dc062597d654b35fbc4792d4df03e8..3893acff82eee2871ab1e50a8be4a17c3b0c03d2 100644 --- a/semantic_router/index/pinecone.py +++ b/semantic_router/index/pinecone.py @@ -216,8 +216,8 @@ class PineconeIndex(BaseIndex): self, local_route_names: List[str], local_utterances: List[str], - local_function_schemas: List[Dict[str, Any]], dimensions: int, + local_function_schemas: List[Dict[str, Any]], ) -> Tuple: if self.index is None: @@ -313,9 +313,9 @@ class PineconeIndex(BaseIndex): } elif self.sync == "merge-force-remote": if route in local_dict and route not in remote_dict: - utterances_to_include = set(local_utterances) - if local_utterances: - layer_routes[route] = {"utterances": list(local_utterances)} + utterances_to_include = local_utterances_set + if local_utterances_set: + layer_routes[route] = {"utterances": list(local_utterances_set)} if isinstance(local_function_schemas_dict, dict): layer_routes[route]["function_schemas"] = { **local_function_schemas_dict diff --git a/semantic_router/index/qdrant.py b/semantic_router/index/qdrant.py index ec809577c0410bfb69041c97deca2e180aeb103e..180bb3b38ae1b9acc40fb9b0a7aa61e8df7d46a7 100644 --- a/semantic_router/index/qdrant.py +++ b/semantic_router/index/qdrant.py @@ -168,8 +168,8 @@ class QdrantIndex(BaseIndex): self, local_route_names: List[str], local_utterances: List[str], - local_function_schemas: List[Dict[str, Any]], dimensions: int, + local_function_schemas: List[Dict[str, Any]], ): if self.sync is not None: logger.error("Sync remove is not implemented for QdrantIndex.") diff --git a/semantic_router/layer.py b/semantic_router/layer.py index 4f478ea0fddaaa2b3d1c20ab54650dcaa2deb013..f5c270cafece0824a6c31158f7ae69c0b5dcc41d 100644 --- a/semantic_router/layer.py +++ b/semantic_router/layer.py @@ -180,7 +180,7 @@ class RouteLayer: self, encoder: Optional[BaseEncoder] = None, llm: Optional[BaseLLM] = None, - routes: List[Route] = [], + routes: Optional[List[Route]] = None, index: Optional[BaseIndex] = None, # type: ignore top_k: int = 5, aggregation: str = "sum", @@ -195,7 +195,7 @@ class RouteLayer: else: self.encoder = encoder self.llm = llm - self.routes = routes + self.routes = routes if routes else [] if self.encoder.score_threshold is None: raise ValueError( "No score threshold provided for encoder. Please set the score threshold " @@ -216,12 +216,10 @@ class RouteLayer: for route in self.routes: if route.score_threshold is None: route.score_threshold = self.score_threshold - # if routes list has been passed, we initialize index now if self.index.sync: self._add_and_sync_routes(routes=self.routes) - - if self.routes: + elif self.routes: self._add_routes(routes=self.routes) def check_for_matching_routes(self, top_class: str) -> Optional[Route]: @@ -529,8 +527,8 @@ class RouteLayer: routes_to_add, routes_to_delete, layer_routes_dict = self.index._sync_index( local_route_names=local_route_names, local_utterances=local_utterances, - local_function_schemas=local_function_schemas, dimensions=len(self.encoder(["dummy"])[0]), + local_function_schemas=local_function_schemas, ) layer_routes: List[Route] = []