Interface QueryRouter
- All Known Implementing Classes:
DefaultQueryRouter, LanguageModelQueryRouter
public interface QueryRouter
Routes the given
The goal is to ensure that
Some potential approaches include:
Query to one or multiple ContentRetrievers.
The goal is to ensure that
Content is retrieved only from relevant data sources.
Some potential approaches include:
- Using an LLM (seeLanguageModelQueryRouter) - Using anEmbeddingModel(aka "semantic routing", seeEmbeddingModelTextClassifierin thelangchain4jmodule) - Using keyword-based routing - Route depending on the user (query.metadata().chatMemoryId()) and/or permissions
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionRoutes the givenQueryto one or multipleContentRetrievers.default CompletableFuture<Collection<ContentRetriever>> routeAsync(Query query) Non-blocking counterpart ofroute(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.
-
Method Details
-
route
Routes the givenQueryto one or multipleContentRetrievers.- Parameters:
query- TheQueryto be routed.- Returns:
- A collection of one or more
ContentRetrievers to which theQueryshould be routed.
-
routeAsync
Non-blocking counterpart ofroute(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.The default implementation returns a failed future carrying
AsyncNotSupportedException: a router backed by a blocking LLM call (e.g.LanguageModelQueryRouter) must opt in by overriding this method to stay off the calling thread. A router that cannot be made non-blocking is still usable from these modes viaDefaultRetrievalAugmentor, which offloads the blockingroute(Query)to its executor.- Parameters:
query- TheQueryto be routed.- Returns:
- A
CompletableFutureof one or moreContentRetrievers to route theQueryto. - Since:
- 1.20.0
-