@@ -86,8 +86,9 @@ def __init__(
8686 vectorizer : Optional [BaseVectorizer ] = None ,
8787 routing_config : Optional [RoutingConfig ] = None ,
8888 redis_client : Optional [Redis ] = None ,
89- redis_url : Optional [ str ] = None ,
89+ redis_url : str = "redis://localhost:6379" ,
9090 overwrite : bool = False ,
91+ connection_kwargs : Dict [str , Any ] = {},
9192 ** kwargs ,
9293 ):
9394 """Initialize the SemanticRouter.
@@ -98,9 +99,10 @@ def __init__(
9899 vectorizer (BaseVectorizer, optional): The vectorizer used to embed route references. Defaults to default HFTextVectorizer.
99100 routing_config (RoutingConfig, optional): Configuration for routing behavior. Defaults to the default RoutingConfig.
100101 redis_client (Optional[Redis], optional): Redis client for connection. Defaults to None.
101- redis_url (Optional[ str] , optional): Redis URL for connection . Defaults to None .
102+ redis_url (str, optional): The redis url . Defaults to redis://localhost:6379 .
102103 overwrite (bool, optional): Whether to overwrite existing index. Defaults to False.
103- **kwargs: Additional arguments.
104+ connection_kwargs (Dict[str, Any]): The connection arguments
105+ for the redis client. Defaults to empty {}.
104106 """
105107 # Set vectorizer default
106108 if vectorizer is None :
@@ -115,12 +117,12 @@ def __init__(
115117 vectorizer = vectorizer ,
116118 routing_config = routing_config ,
117119 )
118- self ._initialize_index (redis_client , redis_url , overwrite )
120+ self ._initialize_index (redis_client , redis_url , overwrite , ** connection_kwargs )
119121
120122 def _initialize_index (
121123 self ,
122124 redis_client : Optional [Redis ] = None ,
123- redis_url : Optional [ str ] = None ,
125+ redis_url : str = "redis://localhost:6379" ,
124126 overwrite : bool = False ,
125127 ** connection_kwargs ,
126128 ):
@@ -132,8 +134,6 @@ def _initialize_index(
132134 self ._index .set_client (redis_client )
133135 elif redis_url :
134136 self ._index .connect (redis_url = redis_url , ** connection_kwargs )
135- else :
136- raise ValueError ("Must provide either a redis client or redis url string." )
137137
138138 existed = self ._index .exists ()
139139 self ._index .create (overwrite = overwrite )
@@ -479,19 +479,12 @@ def clear(self) -> None:
479479 def from_dict (
480480 cls ,
481481 data : Dict [str , Any ],
482- redis_client : Optional [Redis ] = None ,
483- redis_url : Optional [str ] = None ,
484- overwrite : bool = False ,
485482 ** kwargs ,
486483 ) -> "SemanticRouter" :
487484 """Create a SemanticRouter from a dictionary.
488485
489486 Args:
490487 data (Dict[str, Any]): The dictionary containing the semantic router data.
491- redis_client (Optional[Redis]): Redis client for connection.
492- redis_url (Optional[str]): Redis URL for connection.
493- overwrite (bool): Whether to overwrite existing index.
494- **kwargs: Additional arguments.
495488
496489 Returns:
497490 SemanticRouter: The semantic router instance.
@@ -533,9 +526,6 @@ def from_dict(
533526 routes = routes ,
534527 vectorizer = vectorizer ,
535528 routing_config = routing_config ,
536- redis_client = redis_client ,
537- redis_url = redis_url ,
538- overwrite = overwrite ,
539529 ** kwargs ,
540530 )
541531
@@ -565,19 +555,12 @@ def to_dict(self) -> Dict[str, Any]:
565555 def from_yaml (
566556 cls ,
567557 file_path : str ,
568- redis_client : Optional [Redis ] = None ,
569- redis_url : Optional [str ] = None ,
570- overwrite : bool = False ,
571558 ** kwargs ,
572559 ) -> "SemanticRouter" :
573560 """Create a SemanticRouter from a YAML file.
574561
575562 Args:
576563 file_path (str): The path to the YAML file.
577- redis_client (Optional[Redis]): Redis client for connection.
578- redis_url (Optional[str]): Redis URL for connection.
579- overwrite (bool): Whether to overwrite existing index.
580- **kwargs: Additional arguments.
581564
582565 Returns:
583566 SemanticRouter: The semantic router instance.
@@ -603,9 +586,6 @@ def from_yaml(
603586 yaml_data = yaml .safe_load (f )
604587 return cls .from_dict (
605588 yaml_data ,
606- redis_client = redis_client ,
607- redis_url = redis_url ,
608- overwrite = overwrite ,
609589 ** kwargs ,
610590 )
611591
0 commit comments