Class DecisionModelQueryRouter.Builder

java.lang.Object
dev.langchain4j.rag.query.router.DecisionModelQueryRouter.Builder
Enclosing class:
DecisionModelQueryRouter

public static class DecisionModelQueryRouter.Builder extends Object
Since:
1.21.0
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • decisionModel

      public DecisionModelQueryRouter.Builder decisionModel(DecisionModel 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

      public DecisionModelQueryRouter.Builder 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). The query is the input.

      Default value is DecisionModelQueryRouter.DEFAULT_QUESTION_TEMPLATE.

    • minProbability

      public DecisionModelQueryRouter.Builder minProbability(Double minProbability)
      Sets the minimum probability of "yes" for a retriever to be used.

      Default value is 0.5.

    • fallbackStrategy

      Sets what happens when the decision model fails.

      Default value is DecisionModelQueryRouter.FallbackStrategy.DO_NOT_ROUTE.

    • maxMessages

      public DecisionModelQueryRouter.Builder 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. 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 with messageFilter(Predicate).

    • maxMessageLength

      public DecisionModelQueryRouter.Builder 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. 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

      public DecisionModelQueryRouter.Builder messageFilter(Predicate<? super ChatMessage> 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, and message -> !(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

      public DecisionModelQueryRouter build()