22# SPDX-License-Identifier: BSD-3-Clause
33
44"""Main asero semantic router classes."""
5-
5+ import asyncio
66import logging
77import re
88
@@ -448,7 +448,7 @@ def top_n_routes(
448448 only_leaves : bool = True ,
449449 allowed_paths : list [str ] | None = None
450450 ) -> list [tuple [str , float , int , bool ]]:
451- """For a given query, return the top-N most similar semantic routes in the hierarchy.
451+ """Get (synchronously) for a given query, the top-N most similar semantic routes in the hierarchy.
452452
453453 Args:
454454 query (str): User query string.
@@ -469,6 +469,28 @@ def top_n_routes(
469469 allowed_paths = allowed_paths ,
470470 )
471471
472+ async def atop_n_routes (
473+ self ,
474+ query : str ,
475+ top_n : int = 3 ,
476+ only_leaves : bool = True ,
477+ allowed_paths : list [str ] | None = None
478+ ) -> list [tuple [str , float , int , bool ]]:
479+ """Get (asynchronously) for a given query, the top-N most similar semantic routes in the hierarchy.
480+
481+ Args:
482+ query (str): User query string.
483+ top_n (int): Number of top routes to return.
484+ only_leaves (bool): If True, only return leaf nodes.
485+ allowed_paths (list[str]): List of allowed paths to filter results.
486+
487+ Returns:
488+ list[tuple[str, float, int, bool]]: List of tuples:
489+ (route_path, similarity_score, depth, is_leaf)
490+
491+ """
492+ return await asyncio .to_thread (self .top_n_routes , query , top_n , only_leaves , allowed_paths )
493+
472494 def add_utterance (
473495 self ,
474496 path : list [str ],
0 commit comments