Package com.redis.vl.extensions.router
Class SemanticRouter
java.lang.Object
com.redis.vl.extensions.router.SemanticRouter
Semantic Router for managing and querying route vectors. Ported from Python:
redisvl/extensions/router/semantic.py:33
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder for SemanticRouter. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddRouteReferences
(String routeName, List<String> references) Add reference(s) to an existing route.builder()
Create a new builder for SemanticRouter.void
clear()
Clear all route data from Redis.void
delete()
Delete the semantic router index from Redis.int
Delete references from an existing route.Get a route by its name.Get the list of route names.Get references for an existing route.Get the distance thresholds for each route.Route a query to the best matching route.route
(String text, float[] vector, DistanceAggregationMethod aggregationMethod) Route a query to the best matching route with full control.Route a query to multiple matching routes.routeMany
(String text, Integer maxK, float[] vector, DistanceAggregationMethod aggregationMethod) Route a query to multiple matching routes with full control.toDict()
Convert router to dictionary for JSON serialization.toMap()
Convert the SemanticRouter to a Map representation.void
updateRoutingConfig
(RoutingConfig newConfig) Update the routing configuration.
-
Constructor Details
-
SemanticRouter
Legacy constructor for backwards compatibility.- Parameters:
name
- the router name
-
-
Method Details
-
builder
Create a new builder for SemanticRouter.- Returns:
- a new SemanticRouterBuilder
-
getRouteNames
Get the list of route names. Ported from Python: route_names property (line 187)- Returns:
- list of route names
-
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
Convert router to dictionary for JSON serialization. Ported from Python: to_dict() (line 562)- Returns:
- Map representation of the router
-
get
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
Update the routing configuration. Ported from Python: update_routing_config() (line 204)- Parameters:
newConfig
- the new routing configuration
-
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
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
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
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
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 toreferences
- 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
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
-