1
1
from pathlib import Path
2
- from typing import Any , ClassVar , Dict , List , Optional , Type , Union
2
+ from typing import Any , Dict , List , Optional , Type , Union
3
3
4
4
import redis .commands .search .reducers as reducers
5
5
import yaml
23
23
from redisvl .redis .connection import RedisConnectionFactory
24
24
from redisvl .redis .utils import convert_bytes , hashify , make_dict
25
25
from 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
27
27
from redisvl .utils .vectorize .base import BaseVectorizer
28
28
from redisvl .utils .vectorize .text .huggingface import HFTextVectorizer
29
29
@@ -43,7 +43,6 @@ class SemanticRouter(BaseModel):
43
43
"""Configuration for routing behavior."""
44
44
45
45
_index : SearchIndex = PrivateAttr ()
46
- _persist_config : bool = PrivateAttr ()
47
46
48
47
model_config = ConfigDict (arbitrary_types_allowed = True )
49
48
@@ -170,7 +169,7 @@ def _initialize_index(
170
169
171
170
if not existed or overwrite :
172
171
# write the routes to Redis
173
- self .add_routes (self .routes )
172
+ self ._add_routes (self .routes )
174
173
175
174
@property
176
175
def route_names (self ) -> List [str ]:
@@ -213,7 +212,7 @@ def _route_ref_key(index: SearchIndex, route_name: str, reference_hash: str) ->
213
212
"""Generate the route reference key."""
214
213
return f"{ index .prefix } :{ route_name } :{ reference_hash } "
215
214
216
- def add_routes (self , routes : List [Route ]):
215
+ def _add_routes (self , routes : List [Route ]):
217
216
"""Add routes to the router and index.
218
217
219
218
Args:
@@ -719,8 +718,8 @@ def get_route_references(
719
718
queries = self ._make_filter_queries (reference_ids )
720
719
elif route_name :
721
720
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
724
723
)
725
724
726
725
queries = self ._make_filter_queries (
@@ -757,10 +756,9 @@ def delete_route_references(
757
756
res = self ._index .batch_query (queries )
758
757
keys = [r [0 ]["id" ] for r in res if len (r ) > 0 ]
759
758
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
762
761
)
763
- keys = convert_bytes (keys )
764
762
765
763
if not keys :
766
764
raise ValueError (f"No references found for route { route_name } " )
0 commit comments