Skip to content

Commit

Permalink
chore: rename route layer to semantic router
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescalam committed Nov 24, 2024
1 parent cec4b20 commit 7752b08
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 95 deletions.
4 changes: 2 additions & 2 deletions semantic_router/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from semantic_router.routers import RouterConfig, RouteLayer, HybridRouter
from semantic_router.routers import RouterConfig, SemanticRouter, HybridRouter
from semantic_router.route import Route

__all__ = ["RouteLayer", "HybridRouter", "Route", "RouterConfig"]
__all__ = ["SemanticRouter", "HybridRouter", "Route", "RouterConfig"]

__version__ = "0.1.0.dev2"
2 changes: 2 additions & 0 deletions semantic_router/index/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from semantic_router.index.base import BaseIndex
from semantic_router.index.hybrid_local import HybridLocalIndex
from semantic_router.index.hybrid_local_opt import HybridLocalOptIndex
from semantic_router.index.local import LocalIndex
from semantic_router.index.pinecone import PineconeIndex
from semantic_router.index.qdrant import QdrantIndex

__all__ = [
"BaseIndex",
"HybridLocalIndex",
"HybridLocalOptIndex",
"LocalIndex",
"QdrantIndex",
"PineconeIndex",
Expand Down
4 changes: 2 additions & 2 deletions semantic_router/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from semantic_router.routers.base import BaseRouter, RouterConfig
from semantic_router.routers.semantic import RouteLayer
from semantic_router.routers.semantic import SemanticRouter
from semantic_router.routers.hybrid import HybridRouter

__all__ = [
"BaseRouter",
"RouterConfig",
"RouteLayer",
"SemanticRouter",
"HybridRouter",
]
14 changes: 7 additions & 7 deletions semantic_router/routers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ def _execute_sync_strategy(self, strategy: Dict[str, Dict[str, List[Utterance]]]
self._write_hash()

def _local_upsert(self, utterances: List[Utterance]):
"""Adds new routes to the RouteLayer.
"""Adds new routes to the SemanticRouter.
:param utterances: The utterances to add to the local RouteLayer.
:param utterances: The utterances to add to the local SemanticRouter.
:type utterances: List[Utterance]
"""
new_routes = {route.name: route for route in self.routes}
Expand All @@ -590,9 +590,9 @@ def _local_upsert(self, utterances: List[Utterance]):
self.routes = list(new_routes.values())

def _local_delete(self, utterances: List[Utterance]):
"""Deletes routes from the local RouteLayer.
"""Deletes routes from the local SemanticRouter.
:param utterances: The utterances to delete from the local RouteLayer.
:param utterances: The utterances to delete from the local SemanticRouter.
:type utterances: List[Utterance]
"""
# create dictionary of route names to utterances
Expand Down Expand Up @@ -704,7 +704,7 @@ def from_config(cls, config: RouterConfig, index: Optional[BaseIndex] = None):
return cls(encoder=encoder, routes=config.routes, index=index)

def add(self, route: Route):
"""Add a route to the local RouteLayer and index.
"""Add a route to the local SemanticRouter and index.
:param route: The route to add.
:type route: Route
Expand Down Expand Up @@ -734,7 +734,7 @@ def add(self, route: Route):
else:
logger.warning(
"Local and remote route layers were not aligned. Remote hash "
"not updated. Use `RouteLayer.get_utterance_diff()` to see "
"not updated. Use `SemanticRouter.get_utterance_diff()` to see "
"details."
)

Expand All @@ -752,7 +752,7 @@ def update(
threshold or utterances parameters, those fields are not updated.
If neither field is provided raises a ValueError.
The name must exist within the local RouteLayer, if not a
The name must exist within the local SemanticRouter, if not a
KeyError will be raised.
"""
current_local_hash = self._get_hash()
Expand Down
28 changes: 14 additions & 14 deletions semantic_router/routers/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def is_valid(layer_config: str) -> bool:
return False


class RouteLayer(BaseRouter):
class SemanticRouter(BaseRouter):
index: BaseIndex = Field(default_factory=LocalIndex)

@validator("index", pre=True, always=True)
Expand Down Expand Up @@ -312,9 +312,9 @@ def _execute_sync_strategy(self, strategy: Dict[str, Dict[str, List[Utterance]]]
self._write_hash()

def _local_upsert(self, utterances: List[Utterance]):
"""Adds new routes to the RouteLayer.
"""Adds new routes to the SemanticRouter.
:param utterances: The utterances to add to the local RouteLayer.
:param utterances: The utterances to add to the local SemanticRouter.
:type utterances: List[Utterance]
"""
new_routes = {route.name: route for route in self.routes}
Expand All @@ -336,9 +336,9 @@ def _local_upsert(self, utterances: List[Utterance]):
self.routes = list(new_routes.values())

def _local_delete(self, utterances: List[Utterance]):
"""Deletes routes from the local RouteLayer.
"""Deletes routes from the local SemanticRouter.
:param utterances: The utterances to delete from the local RouteLayer.
:param utterances: The utterances to delete from the local SemanticRouter.
:type utterances: List[Utterance]
"""
# create dictionary of route names to utterances
Expand Down Expand Up @@ -427,7 +427,7 @@ def _check_threshold(self, scores: List[float], route: Optional[Route]) -> bool:

def __str__(self):
return (
f"RouteLayer(encoder={self.encoder}, "
f"SemanticRouter(encoder={self.encoder}, "
f"score_threshold={self.score_threshold}, "
f"routes={self.routes})"
)
Expand All @@ -450,7 +450,7 @@ def from_config(cls, config: RouterConfig, index: Optional[BaseIndex] = None):
return cls(encoder=encoder, routes=config.routes, index=index)

def add(self, route: Route):
"""Add a route to the local RouteLayer and index.
"""Add a route to the local SemanticRouter and index.
:param route: The route to add.
:type route: Route
Expand Down Expand Up @@ -480,7 +480,7 @@ def add(self, route: Route):
else:
logger.warning(
"Local and remote route layers were not aligned. Remote hash "
"not updated. Use `RouteLayer.get_utterance_diff()` to see "
"not updated. Use `SemanticRouter.get_utterance_diff()` to see "
"details."
)

Expand All @@ -498,7 +498,7 @@ def update(
threshold or utterances parameters, those fields are not updated.
If neither field is provided raises a ValueError.
The name must exist within the local RouteLayer, if not a
The name must exist within the local SemanticRouter, if not a
KeyError will be raised.
"""
current_local_hash = self._get_hash()
Expand Down Expand Up @@ -532,7 +532,7 @@ def update(
else:
logger.warning(
"Local and remote route layers were not aligned. Remote hash "
"not updated. Use `RouteLayer.get_utterance_diff()` to see "
"not updated. Use `SemanticRouter.get_utterance_diff()` to see "
"details."
)

Expand All @@ -549,7 +549,7 @@ def delete(self, route_name: str):
current_remote_hash = current_local_hash

if route_name not in [route.name for route in self.routes]:
err_msg = f"Route `{route_name}` not found in RouteLayer"
err_msg = f"Route `{route_name}` not found in SemanticRouter"
logger.warning(err_msg)
try:
self.index.delete(route_name=route_name)
Expand All @@ -564,7 +564,7 @@ def delete(self, route_name: str):
else:
logger.warning(
"Local and remote route layers were not aligned. Remote hash "
"not updated. Use `RouteLayer.get_utterance_diff()` to see "
"not updated. Use `SemanticRouter.get_utterance_diff()` to see "
"details."
)

Expand Down Expand Up @@ -618,7 +618,7 @@ def _add_routes(self, routes: List[Route]):
else:
logger.warning(
"Local and remote route layers were not aligned. Remote hash "
"not updated. Use `RouteLayer.get_utterance_diff()` to see "
"not updated. Use `SemanticRouter.get_utterance_diff()` to see "
"details."
)

Expand Down Expand Up @@ -959,7 +959,7 @@ def _get_route_names(self) -> List[str]:


def threshold_random_search(
route_layer: RouteLayer,
route_layer: SemanticRouter,
search_range: Union[int, float],
) -> Dict[str, float]:
"""Performs a random search iteration given a route layer and a search range."""
Expand Down
Loading

0 comments on commit 7752b08

Please sign in to comment.