Skip to content

Commit 23805cf

Browse files
vishal-balaclaude
andcommitted
fix(router): remove persisted route_config key on delete
SemanticRouter.delete() dropped the search index but left the standalone {name}:route_config JSON key in Redis, since that key is not tracked by the index. Delete it explicitly so deletion fully removes router state. Closes #634 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9e1e20f commit 23805cf

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

redisvl/extensions/router/semantic.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,11 @@ def remove_route(self, route_name: str) -> None:
577577
self._update_router_state()
578578

579579
def delete(self) -> None:
580-
"""Delete the semantic router index."""
580+
"""Delete the semantic router index and its persisted route config."""
581581
self._index.delete(drop=True)
582+
# The route config is stored as a standalone JSON key that is not
583+
# tracked by the search index, so it must be removed explicitly.
584+
self._index.client.delete(f"{self.name}:route_config") # type: ignore
582585

583586
def clear(self) -> None:
584587
"""Flush all routes from the semantic router index."""

tests/integration/test_semantic_router.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,34 @@ def test_from_existing(client, redis_url, routes, redis_test_name):
685685
router.delete()
686686

687687

688+
def test_delete_removes_route_config_key(
689+
client, routes, hf_vectorizer, redis_test_name
690+
):
691+
"""delete() must remove the persisted {name}:route_config key (issue #634)."""
692+
skip_if_no_redis_search(client)
693+
694+
router = SemanticRouter(
695+
name=redis_test_name("test_router_delete"),
696+
routes=routes,
697+
routing_config=RoutingConfig(max_k=2),
698+
redis_client=client,
699+
overwrite=True,
700+
vectorizer=hf_vectorizer,
701+
)
702+
config_key = f"{router.name}:route_config"
703+
704+
# The config key is written when the router is constructed.
705+
assert client.exists(config_key)
706+
707+
router.delete()
708+
709+
# delete() must drop the index AND remove the standalone config key, so a
710+
# subsequent from_existing() finds no stale config to load.
711+
assert not client.exists(config_key)
712+
with pytest.raises(ValueError):
713+
SemanticRouter.from_existing(name=router.name, redis_client=client)
714+
715+
688716
def test_get_route_references(semantic_router):
689717
# Get references for a specific route
690718
refs = semantic_router.get_route_references(route_name="greeting")

0 commit comments

Comments
 (0)