Package dev.langchain4j.rag.query.router
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 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 LanguageModelQueryRouter.FallbackStrategy
for more details. Default value: LanguageModelQueryRouter.FallbackStrategy.DO_NOT_ROUTE
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Strategy applied if the call to the LLM fails of if LLM does not return a valid response. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ChatLanguageModel
static final PromptTemplate
protected final LanguageModelQueryRouter.FallbackStrategy
protected final Map
<Integer, ContentRetriever> protected final String
protected final PromptTemplate
-
Constructor Summary
ConstructorsConstructorDescriptionLanguageModelQueryRouter
(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription) LanguageModelQueryRouter
(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription, PromptTemplate promptTemplate, LanguageModelQueryRouter.FallbackStrategy fallbackStrategy) -
Method Summary
Modifier and TypeMethodDescriptionprotected Prompt
createPrompt
(Query query) protected Collection
<ContentRetriever> protected Collection
<ContentRetriever> Routes the givenQuery
to one or multipleContentRetriever
s.
-
Field Details
-
DEFAULT_PROMPT_TEMPLATE
-
chatLanguageModel
-
promptTemplate
-
options
-
idToRetriever
-
fallbackStrategy
-
-
Constructor Details
-
LanguageModelQueryRouter
public LanguageModelQueryRouter(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription) -
LanguageModelQueryRouter
public LanguageModelQueryRouter(ChatLanguageModel chatLanguageModel, Map<ContentRetriever, String> retrieverToDescription, PromptTemplate promptTemplate, LanguageModelQueryRouter.FallbackStrategy fallbackStrategy)
-
-
Method Details
-
route
Description copied from interface:QueryRouter
Routes the givenQuery
to one or multipleContentRetriever
s.- Specified by:
route
in interfaceQueryRouter
- Parameters:
query
- TheQuery
to be routed.- Returns:
- A collection of one or more
ContentRetriever
s to which theQuery
should be routed.
-
fallback
-
createPrompt
-
parse
-