is_valid
RouterConfig Objects
__init__
routes(List[Route]): A list of routes.encoder_type(str): The type of encoder to use.encoder_name(Optional[str]): The name of the encoder to use.
from_file
path(str): The path to the file to load the RouterConfig from.
from_tuples
route_tuples(List[Tuple[str, str]]): A list of tuples, each containing a route name and an associated utterance.encoder_type(str, optional): The type of encoder to use, defaults to “openai”.encoder_name(Optional[str], optional): The name of the encoder to use, defaults to None.
from_index
index(BaseIndex): The index to initialize the RouterConfig from.encoder_type(str, optional): The type of encoder to use, defaults to “openai”.encoder_name(Optional[str], optional): The name of the encoder to use, defaults to None.
to_dict
Dict[str, Any]: A dictionary representation of the RouterConfig.
to_file
path(str): The path to save the RouterConfig to.
to_utterances
List[Utterance]: A list of Utterance objects.
add
route(Route): The route to add.
get
name(str): The name of the route to get.
Optional[Route]: The route if found, otherwise None.
remove
name(str): The name of the route to remove.
get_hash
ConfigParameter: The hash of the RouterConfig.
xq_reshape
xq(List[float] | np.ndarray): The query vector.
np.ndarray: The reshaped query vector.
BaseRouter Objects
__init__
encoder(Optional[DenseEncoder]): The encoder to use.sparse_encoder(Optional[SparseEncoder]): The sparse encoder to use.llm(Optional[BaseLLM]): The LLM to use.routes(Optional[List[Route]]): The routes to use.index(Optional[BaseIndex]): The index to use.Optional[DenseEncoder]0 (Optional[DenseEncoder]1): The number of routes to return.Optional[DenseEncoder]2 (Optional[DenseEncoder]3): The aggregation method to use.Optional[DenseEncoder]4 (Optional[DenseEncoder]5): The auto sync mode to use.
check_for_matching_routes
top_class(str): The top class to check for.
Optional[Route]: The matching route if found, otherwise None.
__call__
text(Optional[str]): The text to route.vector(Optional[List[float] | np.ndarray]): The vector to route.simulate_static(bool): Whether to simulate a static route.route_filter(Optional[List[str]]): The route filter to use.limit(int | None): The number of routes to return, defaults to 1. If set to None, no limit is applied and all routes are returned.
Optional[str]0: The route choice.
acall
text(Optional[str]): The text to route.vector(Optional[List[float] | np.ndarray]): The vector to route.simulate_static(bool): Whether to simulate a static route (ie avoid dynamic route LLM calls during fit or evaluate).route_filter(Optional[List[str]]): The route filter to use.
RouteChoice: The route choice.
sync
sync_mode(str): The mode to sync the routes with the remote index.force(bool, optional): Whether to force the sync even if the local and remote hashes already match. Defaults to False.wait(int): The number of seconds to wait for the index to be unlocked before proceeding with the sync. If set to 0, will raise an error if index is already locked/unlocked.
List[str]: A list of diffs describing the addressed differences between
the local and remote route layers.
async_sync
sync_mode(str): The mode to sync the routes with the remote index.force(bool, optional): Whether to force the sync even if the local and remote hashes already match. Defaults to False.wait(int): The number of seconds to wait for the index to be unlocked before proceeding with the sync. If set to 0, will raise an error if index is already locked/unlocked.
List[str]: A list of diffs describing the addressed differences between
the local and remote route layers.
from_json
file_path(str): The path to the JSON file.
RouterConfig: The RouterConfig object.
from_yaml
file_path(str): The path to the YAML file.
RouterConfig: The RouterConfig object.
from_config
config(RouterConfig): The RouterConfig object.index(Optional[BaseIndex]): The index to use.
add
route(Route): The route to add.
aadd
route(Route): The route to add.
update
name(str): The name of the route to update.threshold(Optional[float]): The threshold to update.utterances(Optional[List[str]]): The utterances to update.
delete
route_name: the name of the route to be deleted
adelete
route_name: the name of the route to be deleted
is_synced
bool: True if the local and remote route layers are synchronized,
False otherwise.
async_is_synced
bool: True if the local and remote route layers are synchronized,
False otherwise.
get_utterance_diff
include_metadata(bool): Whether to include metadata in the diff.
List[str]: A list of strings showing the difference between the local and remote
utterances.
aget_utterance_diff
include_metadata(bool): Whether to include metadata in the diff.
List[str]: A list of strings showing the difference between the local and remote
utterances.
get
name(str): The name of the route to get.
Optional[Route]: The route.
group_scores_by_class
query_results(List[Dict]): The query results to group. Expected format is a list of dictionaries with “route” and “score” keys.
Dict[str, List[float]]: A dictionary of route names and their associated scores.
set_threshold
threshold of 0.0
will mean that the route will be returned no matter how low it scores whereas
a threshold of 1.0 will mean that a route must contain an exact utterance match
to be returned.
Arguments:
threshold(float): The threshold to set.route_name(str | None): The name of the route to set the threshold for. If None, the threshold will be set for all routes.
to_config
RouterConfig: The RouterConfig object.
to_json
file_path(str): The path to the JSON file.
to_yaml
file_path(str): The path to the YAML file.
get_thresholds
Dict[str, float]: A dictionary of route names and their associated thresholds.
fit
None utterances.
Arguments:
X(List[str]): The input data.y(List[str]): The output data.batch_size(int): The batch size to use for fitting.max_iter(int): The maximum number of iterations to use for fitting.local_execution(X0): Whether to execute the fitting locally.
evaluate
X(List[str]): The input data.y(List[str]): The output data.batch_size(int): The batch size to use for evaluation.
float: The accuracy of the route selection.
threshold_random_search
route_layer(BaseRouter): The route layer to search.search_range(Union[int, float]): The search range to use.
Dict[str, float]: A dictionary of route names and their associated thresholds.
