Class DecisionModelQueryRouter.Builder
java.lang.Object
dev.langchain4j.rag.query.router.DecisionModelQueryRouter.Builder
- Enclosing class:
DecisionModelQueryRouter
- Since:
- 1.21.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()decisionModel(DecisionModel decisionModel) Sets the decision model that decides which retrievers to use.fallbackStrategy(DecisionModelQueryRouter.FallbackStrategy fallbackStrategy) Sets what happens when the decision model fails.maxMessageLength(Integer maxMessageLength) Sets the maximum length, in characters, of the text of each message the decision model receives, other than system messages, and of the arguments of each tool call.maxMessages(Integer maxMessages) Sets how many of the last messages of the conversation are taken into account, including the query itself: the previous messages (plus the previous user message, if it is older) are sent together with the query, so that follow-up questions are understood.messageFilter(Predicate<? super ChatMessage> messageFilter) Sets which messages of the conversation the decision model receives; it also applies to the last user message.minProbability(Double minProbability) Sets the minimum probability of "yes" for a retriever to be used.questionTemplate(PromptTemplate questionTemplate) Sets the template of the yes/no question asked for each retriever, which must contain the{{description}}variable (the description of the retriever).retrieverToDescription(Map<ContentRetriever, String> retrieverToDescription) Sets the retrievers to route to, each with a description of the content it can retrieve.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
decisionModel
Sets the decision model that decides which retrievers to use. Required. -
retrieverToDescription
public DecisionModelQueryRouter.Builder retrieverToDescription(Map<ContentRetriever, String> retrieverToDescription) Sets the retrievers to route to, each with a description of the content it can retrieve. Required. -
questionTemplate
Sets the template of the yes/no question asked for each retriever, which must contain the{{description}}variable (the description of the retriever). The query is the input.Default value is
DecisionModelQueryRouter.DEFAULT_QUESTION_TEMPLATE. -
minProbability
Sets the minimum probability of "yes" for a retriever to be used.Default value is 0.5.
-
fallbackStrategy
public DecisionModelQueryRouter.Builder fallbackStrategy(DecisionModelQueryRouter.FallbackStrategy fallbackStrategy) Sets what happens when the decision model fails.Default value is
DecisionModelQueryRouter.FallbackStrategy.DO_NOT_ROUTE. -
maxMessages
Sets how many of the last messages of the conversation are taken into account, including the query itself: the previous messages (plus the previous user message, if it is older) are sent together with the query, so that follow-up questions are understood. An AI message with tool calls and each tool result count as one message each. Tool results whose AI message does not fit are left out. With parallel tool calls, set it higher than the number of tool calls in one round. The previous messages are only sent when the query comes from a conversation with a chat memory. The system message, if any, is sent in addition and does not count.Default value is 10: the query and the 9 previous messages. More messages can make an older topic of the conversation outweigh the query. When the queries are already made self-contained, for example by a
CompressingQueryTransformer, set it to 1. The system message is still sent then; leave it out withmessageFilter(Predicate). -
maxMessageLength
Sets the maximum length, in characters, of the text of each message the decision model receives, other than system messages, and of the arguments of each tool call. A longer text is shortened in the middle: its beginning and its end are kept, with a note of about 90 characters saying how many characters were left out. Long tool results and user messages with retrieved content are the usual cases. As a rough guide, 4 characters make one token in English text.Default value is 2000.
- Since:
- 1.23.0
-
messageFilter
Sets which messages of the conversation the decision model receives; it also applies to the last user message. For example,message -> !(message instanceof SystemMessage)leaves out the system message, andmessage -> !(message instanceof ToolExecutionResultMessage)leaves out tool results, which can be large.By default, all messages are sent: system messages, user messages, AI messages with their tool calls, and tool results.
- Since:
- 1.23.0
-
build
-