Class SemanticRouter

java.lang.Object
com.redis.vl.extensions.router.SemanticRouter

public class SemanticRouter extends Object
Semantic Router for managing and querying route vectors. Ported from Python: redisvl/extensions/router/semantic.py:33
  • Constructor Details

    • SemanticRouter

      public SemanticRouter(String name)
      Legacy constructor for backwards compatibility.
      Parameters:
      name - the router name
  • Method Details

    • builder

      public static SemanticRouter.SemanticRouterBuilder builder()
      Create a new builder for SemanticRouter.
      Returns:
      a new SemanticRouterBuilder
    • getRouteNames

      public List<String> getRouteNames()
      Get the list of route names. Ported from Python: route_names property (line 187)
      Returns:
      list of route names
    • getRouteThresholds

      public Map<String,Double> getRouteThresholds()
      Get the distance thresholds for each route. Ported from Python: route_thresholds property (line 196)
      Returns:
      map of route names to distance thresholds
    • toDict

      public Map<String,Object> toDict()
      Convert router to dictionary for JSON serialization. Ported from Python: to_dict() (line 562)
      Returns:
      Map representation of the router
    • get

      public Route get(String routeName)
      Get a route by its name. Ported from Python: get() (line 262)
      Parameters:
      routeName - the name of the route
      Returns:
      the route, or null if not found
    • updateRoutingConfig

      public void updateRoutingConfig(RoutingConfig newConfig)
      Update the routing configuration. Ported from Python: update_routing_config() (line 204)
      Parameters:
      newConfig - the new routing configuration
    • toMap

      public Map<String,Object> toMap()
      Convert the SemanticRouter to a Map representation. Ported from Python: to_dict() (line 562)
      Returns:
      map representation of the router
    • clear

      public void clear()
      Clear all route data from Redis. Ported from Python: clear() (line 501)
    • delete

      public void delete()
      Delete the semantic router index from Redis. Ported from Python: delete() (line 497)
    • route

      public RouteMatch route(String text)
      Route a query to the best matching route. Ported from Python: __call__() (line 410-439)
      Parameters:
      text - the query text to route
      Returns:
      the best matching route, or RouteMatch with null name if no match
    • route

      public RouteMatch route(String text, float[] vector, DistanceAggregationMethod aggregationMethod)
      Route a query to the best matching route with full control. Ported from Python: __call__() (line 410-439)
      Parameters:
      text - the query text (optional if vector provided)
      vector - pre-computed embedding vector (optional if text provided)
      aggregationMethod - method to aggregate distances (null uses config default)
      Returns:
      the best matching route, or RouteMatch with null name if no match
    • routeMany

      public List<RouteMatch> routeMany(String text)
      Route a query to multiple matching routes. Ported from Python: route_many() (line 442-477)
      Parameters:
      text - the query text to route
      Returns:
      list of matching routes
    • routeMany

      public List<RouteMatch> routeMany(String text, Integer maxK, float[] vector, DistanceAggregationMethod aggregationMethod)
      Route a query to multiple matching routes with full control. Ported from Python: route_many() (line 442-477)
      Parameters:
      text - the query text (optional if vector provided)
      maxK - maximum number of routes to return (null uses config default)
      vector - pre-computed embedding vector (optional if text provided)
      aggregationMethod - method to aggregate distances (null uses config default)
      Returns:
      list of matching routes
    • addRouteReferences

      public List<String> addRouteReferences(String routeName, List<String> references)
      Add reference(s) to an existing route. Ported from Python: add_route_references() (line 651)
      Parameters:
      routeName - the name of the route to add references to
      references - the list of references to add
      Returns:
      list of added reference keys
    • getRouteReferences

      public List<Map<String,Object>> getRouteReferences(String routeName, List<String> referenceIds, List<String> keys)
      Get references for an existing route. Ported from Python: get_route_references() (line 714)
      Parameters:
      routeName - the name of the route (optional if referenceIds or keys provided)
      referenceIds - list of reference IDs to retrieve (optional)
      keys - list of fully qualified keys to retrieve (optional)
      Returns:
      list of reference documents
    • deleteRouteReferences

      public int deleteRouteReferences(String routeName, List<String> referenceIds, List<String> keys)
      Delete references from an existing route. Ported from Python: delete_route_references() (line 750)
      Parameters:
      routeName - the name of the route (optional if referenceIds or keys provided)
      referenceIds - list of reference IDs to delete (optional)
      keys - list of fully qualified keys to delete (optional)
      Returns:
      number of deleted references