Class VectorToolSearchStrategy.Builder

java.lang.Object
dev.langchain4j.service.tool.search.vector.VectorToolSearchStrategy.Builder
Enclosing class:
VectorToolSearchStrategy

public static class VectorToolSearchStrategy.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • embeddingModel

      public VectorToolSearchStrategy.Builder embeddingModel(EmbeddingModel embeddingModel)
      Sets the EmbeddingModel used to generate embeddings for the query and available tools.

      This property is required and has no default value.

    • maxResults

      public VectorToolSearchStrategy.Builder maxResults(Integer maxResults)
      Sets the maximum number of tools to return from the vector similarity search.

      Default value is 5.

    • toolName

      public VectorToolSearchStrategy.Builder toolName(String toolName)
      Sets the name of the tool that performs the tool search.

      Default value is "tool_search_tool".

    • toolDescription

      public VectorToolSearchStrategy.Builder toolDescription(String toolDescription)
      Sets the description of the tool that performs the tool search.

      Default value is "Finds available tools using semantic vector search".

    • toolArgumentName

      public VectorToolSearchStrategy.Builder toolArgumentName(String toolArgumentName)
      Sets the name of the tool argument that contains the natural language query.

      Default value is "query".

    • toolArgumentDescription

      public VectorToolSearchStrategy.Builder toolArgumentDescription(String toolArgumentDescription)
      Sets the description of the tool argument that contains the natural language query.

      Default value is "Natural language query describing desired tool".

    • throwToolArgumentsExceptions

      public VectorToolSearchStrategy.Builder throwToolArgumentsExceptions(Boolean throwToolArgumentsExceptions)
      Controls which exception type is thrown when tool arguments are missing, invalid, or cannot be parsed.

      Although all errors produced by this tool are argument-related, this strategy throws ToolExecutionException by default instead of ToolArgumentsException.

      The reason is historical: by default, AI Services fail fast when a ToolArgumentsException is thrown, whereas ToolExecutionException allows the error message to be returned to the LLM. For this tool, returning the error message to the LLM is usually the desired behavior.

      If this flag is set to true, ToolArgumentsException will be thrown instead.

      Parameters:
      throwToolArgumentsExceptions - whether to throw ToolArgumentsException
      Returns:
      this builder
    • cacheEmbeddings

      public VectorToolSearchStrategy.Builder cacheEmbeddings(Boolean cacheEmbeddings)
      Controls whether embeddings generated by the embedding model are cached.

      Default value is true.

    • toolResultMessageTextProvider

      public VectorToolSearchStrategy.Builder toolResultMessageTextProvider(Function<List<String>, String> toolResultMessageTextProvider)
      Sets a function that produces a human-readable message describing the tool search result, based on the list of found tool names.

      By default, returns:

      • "No matching tools found" when no tools are found
      • "Tools found: tool_1, tool_2, ..." otherwise
    • build

      public VectorToolSearchStrategy build()