Class LanguageModelQueryRouter
-
- All Implemented Interfaces:
-
dev.langchain4j.rag.query.router.QueryRouter
public class LanguageModelQueryRouter implements QueryRouter
A QueryRouter that utilizes a ChatLanguageModel 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 FallbackStrategy for more details. Default value: DO_NOT_ROUTE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enum
LanguageModelQueryRouter.FallbackStrategy
Strategy applied if the call to the LLM fails of if LLM does not return a valid response. It could be because it was formatted improperly, or it is unclear where to route.
public class
LanguageModelQueryRouter.LanguageModelQueryRouterBuilder
-
Field Summary
Fields Modifier and Type Field Description public final static PromptTemplate
DEFAULT_PROMPT_TEMPLATE
-
Constructor Summary
Constructors Constructor Description LanguageModelQueryRouter(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription)
LanguageModelQueryRouter(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription, PromptTemplate promptTemplate, LanguageModelQueryRouter.FallbackStrategy fallbackStrategy)
-
Method Summary
Modifier and Type Method Description static LanguageModelQueryRouter.LanguageModelQueryRouterBuilder
builder()
Collection<ContentRetriever>
route(Query query)
Routes the given Query to one or multiple ContentRetrievers. -
-
Constructor Detail
-
LanguageModelQueryRouter
LanguageModelQueryRouter(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription)
-
LanguageModelQueryRouter
LanguageModelQueryRouter(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription, PromptTemplate promptTemplate, LanguageModelQueryRouter.FallbackStrategy fallbackStrategy)
-
-
Method Detail
-
builder
static LanguageModelQueryRouter.LanguageModelQueryRouterBuilder builder()
-
route
Collection<ContentRetriever> route(Query query)
Routes the given Query to one or multiple ContentRetrievers.
- Parameters:
query
- The Query to be routed.- Returns:
A collection of one or more ContentRetrievers to which the Query should be routed.
-
-
-
-