pub enum ToolRanker {
Bm25,
Semantic,
}Expand description
A swappable tool ranking strategy. BM25 is the default; Semantic is a real
embedder-backed second strategy (enum-dispatch in ToolRanker::rank), not a
placeholder — it embeds the query + candidates and ranks by cosine similarity.
Variants§
Bm25
Classic BM25 lexical ranking over name + description + arg names.
Semantic
Embedding-based semantic ranking via the registry [Embedder]
(cosine over doc_text). Falls back to BM25 ordering when the embedder is
unreachable (documented graceful fallback, not a stub error).
Implementations§
Source§impl ToolRanker
impl ToolRanker
Sourcepub fn from_pref(s: Option<&str>) -> ToolRanker
pub fn from_pref(s: Option<&str>) -> ToolRanker
Resolve the ranker from a pref string; defaults to BM25.
Sourcepub async fn rank(
self,
query: &str,
items: Vec<ToolDescriptor>,
limit: usize,
embedder: Option<&dyn ToolEmbedder>,
) -> Vec<ToolDescriptor>
pub async fn rank( self, query: &str, items: Vec<ToolDescriptor>, limit: usize, embedder: Option<&dyn ToolEmbedder>, ) -> Vec<ToolDescriptor>
Rank descriptors against a query, mutating score and sorting descending.
Returns the top limit.
Semantic embeds the query + each candidate’s [doc_text] via the
injected ToolEmbedder and ranks by cosine similarity; it falls back to
BM25 ordering when the embedder is absent/unreachable (or the query is
empty), so it degrades gracefully rather than erroring. Bm25 is the pure
lexical path and ignores embedder.
Trait Implementations§
Source§impl Clone for ToolRanker
impl Clone for ToolRanker
Source§fn clone(&self) -> ToolRanker
fn clone(&self) -> ToolRanker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more