Class DefaultQueryRouter
java.lang.Object
dev.langchain4j.rag.query.router.DefaultQueryRouter
- All Implemented Interfaces:
QueryRouter
Default implementation of
It's important to note that while efforts will be made to avoid breaking changes, the default behavior of this class may be updated in the future if it's found that the current behavior does not adequately serve the majority of use cases. Such changes would be made to benefit both current and future users.
This implementation always routes all
QueryRouter intended to be suitable for the majority of use cases.
It's important to note that while efforts will be made to avoid breaking changes, the default behavior of this class may be updated in the future if it's found that the current behavior does not adequately serve the majority of use cases. Such changes would be made to benefit both current and future users.
This implementation always routes all
Querys
to one or multiple ContentRetrievers provided in the constructor.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultQueryRouter(ContentRetriever... contentRetrievers) DefaultQueryRouter(Collection<ContentRetriever> contentRetrievers) -
Method Summary
Modifier and TypeMethodDescriptionRoutes the givenQueryto one or multipleContentRetrievers.routeAsync(Query query) Non-blocking counterpart ofQueryRouter.route(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.
-
Constructor Details
-
DefaultQueryRouter
-
DefaultQueryRouter
-
-
Method Details
-
route
Description copied from interface:QueryRouterRoutes the givenQueryto one or multipleContentRetrievers.- Specified by:
routein interfaceQueryRouter- Parameters:
query- TheQueryto be routed.- Returns:
- A collection of one or more
ContentRetrievers to which theQueryshould be routed.
-
routeAsync
Description copied from interface:QueryRouterNon-blocking counterpart ofQueryRouter.route(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 blockingQueryRouter.route(Query)to its executor.- Specified by:
routeAsyncin interfaceQueryRouter- Parameters:
query- TheQueryto be routed.- Returns:
- A
CompletableFutureof one or moreContentRetrievers to route theQueryto.
-