pub struct ToolSelector { /* private fields */ }Expand description
Selects 3–5 relevant tools per task using TF-IDF + cosine similarity, with Jaccard as a fallback for very short descriptions.
§Selection rules
- Compute TF-IDF vectors for each tool description at registration time.
- At query time, compute the TF-IDF vector for the intent and score via cosine.
- Sort tools by descending similarity score.
- Return between 3 and min(5, tool_count) tools.
- If no tool has similarity > threshold, return the default tool set instead.
Implementations§
Source§impl ToolSelector
impl ToolSelector
Sourcepub fn new(_model_path: &Path, preset: &Preset) -> Result<Self>
pub fn new(_model_path: &Path, preset: &Preset) -> Result<Self>
Create a new ToolSelector from a Preset.
model_path is accepted for API compatibility but is unused.
Sourcepub fn register_tools(&mut self, tools: &[ToolDefinition]) -> Result<()>
pub fn register_tools(&mut self, tools: &[ToolDefinition]) -> Result<()>
Register a slice of tools, computing TF-IDF vectors for each description.
Sourcepub fn select(&self, intent: &str, max_tools: usize) -> Result<Vec<ToolId>>
pub fn select(&self, intent: &str, max_tools: usize) -> Result<Vec<ToolId>>
Select between 3 and min(5, tool_count) tools whose descriptions best match intent.
Uses TF-IDF + cosine similarity for scoring. Falls back to Jaccard for very short intents (< 3 words) where TF-IDF has insufficient signal.
Returns the default tool set when no tool exceeds the similarity threshold.
Sourcepub fn update_tool(&mut self, tool: &ToolDefinition) -> Result<()>
pub fn update_tool(&mut self, tool: &ToolDefinition) -> Result<()>
Re-embed a single tool on description change.
Auto Trait Implementations§
impl Freeze for ToolSelector
impl RefUnwindSafe for ToolSelector
impl Send for ToolSelector
impl Sync for ToolSelector
impl Unpin for ToolSelector
impl UnsafeUnpin for ToolSelector
impl UnwindSafe for ToolSelector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more