Class LanguageModelQueryRouter
java.lang.Object
dev.langchain4j.rag.query.router.LanguageModelQueryRouter
- All Implemented Interfaces:
QueryRouter
A
Each
Refer to
Configurable parameters (optional):
-
-
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- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumStrategy applied if the call to the LLM fails of if LLM does not return a valid response.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ChatModelstatic final PromptTemplateprotected final LanguageModelQueryRouter.FallbackStrategyprotected final Map<Integer, ContentRetriever> protected final Stringprotected final PromptTemplate -
Constructor Summary
ConstructorsConstructorDescriptionLanguageModelQueryRouter(ChatModel chatModel, Map<ContentRetriever, String> retrieverToDescription) LanguageModelQueryRouter(ChatModel chatModel, Map<ContentRetriever, String> retrieverToDescription, PromptTemplate promptTemplate, LanguageModelQueryRouter.FallbackStrategy fallbackStrategy) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()protected PromptcreatePrompt(Query query) protected Collection<ContentRetriever> protected Collection<ContentRetriever> Routes the givenQueryto one or multipleContentRetrievers.
-
Field Details
-
DEFAULT_PROMPT_TEMPLATE
-
chatModel
-
promptTemplate
-
options
-
idToRetriever
-
fallbackStrategy
-
-
Constructor Details
-
LanguageModelQueryRouter
public LanguageModelQueryRouter(ChatModel chatModel, Map<ContentRetriever, String> retrieverToDescription) -
LanguageModelQueryRouter
public LanguageModelQueryRouter(ChatModel chatModel, Map<ContentRetriever, String> retrieverToDescription, PromptTemplate promptTemplate, LanguageModelQueryRouter.FallbackStrategy fallbackStrategy)
-
-
Method Details
-
builder
-
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.
-
fallback
-
createPrompt
-
parse
-