Toolkit
The Vectorsearches of an LLMClient, as tools that the LLM can call.
An LLMClient lists Vectorsearches in its manifest’s spec.vectorsearches. On each prompt,
VectorsearchToolkit offers each enabled one to the LLM as a function tool whose one argument
is a search query. When the LLM calls it, the toolkit runs the Vectorsearch with
run_vectorsearch(), as the REST api does: it searches the
Vectorsearch’s Vectorstore with the Vectorsearch’s settings (its search type, k, score threshold,
MMR settings and metadata filter), within the Vectorsearch’s budget, and returns the passages that it
found, most similar first, for the LLM to answer from.
The LLM chooses when to search, and what for. A question that the documents can’t help with costs no search, and a question that needs two searches can make them.
- smarter.apps.vectorsearch.toolkit.FUNCTION_NAME_PREFIX = 'smarter_vectorsearch_'
The prefix of a Vectorsearch tool’s function name, which ends with the Vectorsearch’s id.
- class smarter.apps.vectorsearch.toolkit.VectorsearchToolkit(vectorsearches, service_class=None)[source]
Bases:
objectAn LLMClient’s Vectorsearches, as function tools.
- Parameters:
vectorsearches (
list[Vectorsearch]) – The Vectorsearches, e.g. fromvectorsearches_for().service_class – A callable that returns the service that searches a Vectorstore, given the Vectorstore. By default,
VectorstoreService. Tests pass one with a fake backend.
- call(function_name, arguments=None)[source]
Run a Vectorsearch with the LLM’s query, and return the passages that it found, for the LLM.
An error, such as a missing query, a budget that forbids the search, or a Vectorstore that isn’t ready, is returned as
{"error": "..."}, so that the LLM can recover.- Parameters:
- Return type:
TypeAliasType- Returns:
The Vectorsearch’s and its Vectorstore’s names, and the results, as
VectorsearchApiResults, or an error.
- is_vectorsearch_function(function_name)[source]
Return whether a function name is one of this toolkit’s tools.
- property tools: list[dict[str, Any]]
Return the OpenAI function tool of each Vectorsearch.
- Returns:
One
{"type": "function", "function": {...}}per Vectorsearch.
- smarter.apps.vectorsearch.toolkit.function_name_for(vectorsearch)[source]
Return the function name of a Vectorsearch’s tool, e.g.
smarter_vectorsearch_42.- Parameters:
vectorsearch (
Vectorsearch) – The Vectorsearch.- Return type:
- Returns:
The function name, unique to the Vectorsearch.