11from pathlib import Path
2- from typing import Any , ClassVar , Dict , List , Optional , Type , Union
2+ from typing import Any , Dict , List , Optional , Type , Union
33
44import redis .commands .search .reducers as reducers
55import yaml
2323from redisvl .redis .connection import RedisConnectionFactory
2424from redisvl .redis .utils import convert_bytes , hashify , make_dict
2525from redisvl .utils .log import get_logger
26- from redisvl .utils .utils import deprecated_argument , model_to_dict
26+ from redisvl .utils .utils import deprecated_argument , model_to_dict , scan_by_pattern
2727from redisvl .utils .vectorize .base import BaseVectorizer
2828from redisvl .utils .vectorize .text .huggingface import HFTextVectorizer
2929
@@ -43,7 +43,6 @@ class SemanticRouter(BaseModel):
4343 """Configuration for routing behavior."""
4444
4545 _index : SearchIndex = PrivateAttr ()
46- _persist_config : bool = PrivateAttr ()
4746
4847 model_config = ConfigDict (arbitrary_types_allowed = True )
4948
@@ -170,7 +169,7 @@ def _initialize_index(
170169
171170 if not existed or overwrite :
172171 # write the routes to Redis
173- self .add_routes (self .routes )
172+ self ._add_routes (self .routes )
174173
175174 @property
176175 def route_names (self ) -> List [str ]:
@@ -213,7 +212,7 @@ def _route_ref_key(index: SearchIndex, route_name: str, reference_hash: str) ->
213212 """Generate the route reference key."""
214213 return f"{ index .prefix } :{ route_name } :{ reference_hash } "
215214
216- def add_routes (self , routes : List [Route ]):
215+ def _add_routes (self , routes : List [Route ]):
217216 """Add routes to the router and index.
218217
219218 Args:
@@ -719,8 +718,8 @@ def get_route_references(
719718 queries = self ._make_filter_queries (reference_ids )
720719 elif route_name :
721720 if not keys :
722- _ , keys = self . _index . client . scan ( # type: ignore
723- cursor = 0 , match = f"{ self ._index .prefix } :{ route_name } :*"
721+ keys = scan_by_pattern (
722+ self . _index . client , f"{ self ._index .prefix } :{ route_name } :*" # type: ignore
724723 )
725724
726725 queries = self ._make_filter_queries (
@@ -757,10 +756,9 @@ def delete_route_references(
757756 res = self ._index .batch_query (queries )
758757 keys = [r [0 ]["id" ] for r in res if len (r ) > 0 ]
759758 elif not keys :
760- _ , keys = self . _index . client . scan ( # type: ignore
761- cursor = 0 , match = f"{ self ._index .prefix } :{ route_name } :*"
759+ keys = scan_by_pattern (
760+ self . _index . client , f"{ self ._index .prefix } :{ route_name } :*" # type: ignore
762761 )
763- keys = convert_bytes (keys )
764762
765763 if not keys :
766764 raise ValueError (f"No references found for route { route_name } " )
0 commit comments