diff --git a/semantic_router/layer.py b/semantic_router/layer.py index 4512207f..778af03d 100644 --- a/semantic_router/layer.py +++ b/semantic_router/layer.py @@ -177,7 +177,7 @@ class RouteLayer: index: BaseIndex def __init__( - self + self, encoder: Optional[BaseEncoder] = None, llm: Optional[BaseLLM] = None, routes: Optional[List[Route]] = None, @@ -435,8 +435,29 @@ def add(self, route: Route): def list_route_names(self) -> List[str]: return [route.name for route in self.routes] - def update(self, route_name: str, utterances: List[str]): - raise NotImplementedError("This method has not yet been implemented.") + def update(self, name: str, threshold: Optional[float] = None, utterances: Optional[List[str]] = None): + """Updates the route specified in name. Allows the update of + threshold and/or utterances. If no values are provided via the + 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 + KeyError will be raised. + """ + + if threshold is None and utterances is None: + raise ValueError("At least one of 'threshold' or 'utterances' must be provided.") + if utterances: + raise NotImplementedError("The update method cannot be used for updating utterances yet.") + + route = self.get(name) + if route: + if threshold: + old_threshold = route.score_threshold + route.score_threshold = threshold + logger.info(f"Updated threshold for route '{route.name}' from {old_threshold} to {threshold}") + else: + raise ValueError(f"Route '{name}' not found. Nothing updated.") def delete(self, route_name: str): """Deletes a route given a specific route name.