Class LanguageModelQueryRouter

java.lang.Object
dev.langchain4j.rag.query.router.LanguageModelQueryRouter
All Implemented Interfaces:
QueryRouter

public class LanguageModelQueryRouter extends Object implements QueryRouter
A QueryRouter that utilizes a ChatModel to make a routing decision.
Each ContentRetriever provided in the constructor should be accompanied by a description which should help the LLM to decide where to route a Query.
Refer to DEFAULT_PROMPT_TEMPLATE and implementation for more details.

Configurable parameters (optional):
- promptTemplate: The prompt template used to ask the LLM for routing decisions.
- fallbackStrategy: The strategy applied if the call to the LLM fails of if LLM does not return a valid response. Please check LanguageModelQueryRouter.FallbackStrategy for more details. Default value: LanguageModelQueryRouter.FallbackStrategy.DO_NOT_ROUTE

On the asynchronous path (routeAsync(Query)), a chat model without native asynchronous support makes routing fail with an AsyncNotSupportedException instead of applying the fallback strategy. To use such a chat model there, set offloadBlocking(true) on the DefaultRetrievalAugmentor: it then routes with route(Query) on another thread.
See Also: