Class VectorToolSearchStrategy
java.lang.Object
dev.langchain4j.service.tool.search.vector.VectorToolSearchStrategy
- All Implemented Interfaces:
ToolSearchStrategy
A
ToolSearchStrategy that uses vector similarity search
to find relevant tools based on the semantic meaning of their names and descriptions.
NOTE: It is important that the tool description (ToolSpecification.description())
is present and comprehensive to ensure that vector search performs effectively.
NOTE:
By default, embeddings of tool descriptions are cached (since they rarely change).
You can disable this by setting VectorToolSearchStrategy.Builder.cacheEmbeddings(Boolean) to false.
The embedding of a query is never cached.
To simplify the implementation, the cache is not cleared automatically because the risk of a memory leak is minimal.
The number of tools in an application is typically limited and does not increase over time.
The cache can be cleared manually by calling clearEmbeddingsCache().
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidprotected Stringformat(ToolSpecification tool) getToolSearchTools(InvocationContext context) Returns one or more tool specifications that are exposed to the LLM and are used to perform tool searches.search(ToolSearchRequest request) Executes a tool search request generated by the LLM and matching it against searchable tools.
-
Constructor Details
-
VectorToolSearchStrategy
-
VectorToolSearchStrategy
-
-
Method Details
-
getToolSearchTools
Description copied from interface:ToolSearchStrategyReturns one or more tool specifications that are exposed to the LLM and are used to perform tool searches.- Specified by:
getToolSearchToolsin interfaceToolSearchStrategy- Parameters:
context- the AI Service invocation context- Returns:
- list containing one or more tool search tools
-
search
Description copied from interface:ToolSearchStrategyExecutes a tool search request generated by the LLM and matching it against searchable tools.- Specified by:
searchin interfaceToolSearchStrategy- Parameters:
request- the tool search request- Returns:
- the search result containing matching tool names
-
format
-
clearEmbeddingsCache
public void clearEmbeddingsCache() -
builder
-