pub struct QueryExplanation {
pub query: String,
pub query_terms: Vec<String>,
pub unmatched_catalog_terms: Vec<String>,
pub candidates: Vec<ToolExplanation>,
}Expand description
Full explainable routing diagnostic returned by explain_query.
Fields§
§query: StringRaw input query string.
query_terms: Vec<String>Normalized query terms used for BM25 scoring.
unmatched_catalog_terms: Vec<String>Query terms that matched zero tools in the entire catalog (vocabulary gaps).
candidates: Vec<ToolExplanation>Top-k ranked candidate tools with per-term & per-field score attribution.
Implementations§
Source§impl QueryExplanation
impl QueryExplanation
Sourcepub fn to_text(&self) -> String
pub fn to_text(&self) -> String
Formats a concise human/agent-readable breakdown of why tools ranked in this order.
Examples found in repository?
examples/multi_server_compose.rs (line 106)
6fn main() {
7 let github = Catalog::from_mcp_json(
8 r#"{
9 "tools": [
10 {
11 "name": "create_issue",
12 "description": "Creates a new GitHub issue in a repository and returns its issue URL.",
13 "inputSchema": {
14 "type": "object",
15 "properties": {
16 "owner": { "type": "string", "description": "Repository owner." },
17 "repo": { "type": "string", "description": "Repository name." },
18 "title": { "type": "string", "description": "Issue title." }
19 },
20 "required": ["owner", "repo", "title"]
21 }
22 },
23 {
24 "name": "search_repositories",
25 "description": "Searches GitHub repositories by keyword and returns a paginated list.",
26 "inputSchema": {
27 "type": "object",
28 "properties": {
29 "query": { "type": "string", "description": "GitHub search query." },
30 "perPage": { "type": "integer", "description": "Results per page." }
31 },
32 "required": ["query"]
33 }
34 }
35 ]
36 }"#,
37 )
38 .expect("valid github catalog");
39
40 let gitlab = Catalog::from_mcp_json(
41 r#"{
42 "tools": [
43 {
44 "name": "create_issue",
45 "description": "Creates a new GitLab issue in a project and returns its issue IID.",
46 "inputSchema": {
47 "type": "object",
48 "properties": {
49 "project_id": { "type": "string", "description": "Project ID or URL-encoded path." },
50 "title": { "type": "string", "description": "Issue title." }
51 },
52 "required": ["project_id", "title"]
53 }
54 },
55 {
56 "name": "list_merge_requests",
57 "description": "Lists open GitLab merge requests for a project with pagination.",
58 "inputSchema": {
59 "type": "object",
60 "properties": {
61 "project_id": { "type": "string", "description": "Project ID." },
62 "limit": { "type": "integer", "description": "Max rows returned." }
63 },
64 "required": ["project_id"]
65 }
66 }
67 ]
68 }"#,
69 )
70 .expect("valid gitlab catalog");
71
72 // 1) Multi-server composition & namespace simulation
73 let composed = compose_catalogs(
74 &[
75 ("github".into(), github.clone()),
76 ("gitlab".into(), gitlab.clone()),
77 ],
78 &AuditConfig::default(),
79 );
80 println!("{}", composed.to_text());
81
82 // 2) Pre-indexed Bm25Index on the namespaced catalog + explainability
83 let mut combined = github.with_namespace_prefix("github").tools().to_vec();
84 combined.extend(
85 gitlab
86 .with_namespace_prefix("gitlab")
87 .tools()
88 .iter()
89 .cloned(),
90 );
91 let namespaced = Catalog::new(combined);
92
93 let index = Bm25Index::build(&namespaced);
94 let hits = index.search("open gitlab merge requests", 2);
95 println!(
96 "Top Bm25Index hit: {} ({:.3})",
97 hits[0].tool_name, hits[0].score
98 );
99
100 let explanation = explain_query(
101 &namespaced,
102 "open gitlab merge requests",
103 Bm25Ranker::default(),
104 2,
105 );
106 println!("{}", explanation.to_text());
107
108 // 3) Side-by-side ranker comparison on an auto-generated adversarial suite
109 let suite = EvalSuite::generate_adversarial(&namespaced);
110 let tfidf = TfIdfRanker::default();
111 let hybrid = HybridRanker::default();
112 let cmp = compare_rankers(
113 &suite,
114 &namespaced,
115 &[("bm25", &index), ("tfidf", &tfidf), ("hybrid", &hybrid)],
116 3,
117 );
118 println!("{}", cmp.to_text());
119}Trait Implementations§
Source§impl Clone for QueryExplanation
impl Clone for QueryExplanation
Source§impl Debug for QueryExplanation
impl Debug for QueryExplanation
Source§impl<'de> Deserialize<'de> for QueryExplanation
impl<'de> Deserialize<'de> for QueryExplanation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for QueryExplanation
impl PartialEq for QueryExplanation
Source§impl Serialize for QueryExplanation
impl Serialize for QueryExplanation
impl StructuralPartialEq for QueryExplanation
Auto Trait Implementations§
impl Forget for QueryExplanation
impl Freeze for QueryExplanationwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
PhantomData<ToolExplanation>: Freeze,
impl Move for QueryExplanation
impl RefUnwindSafe for QueryExplanation
impl Send for QueryExplanationwhere
RawVecInner: Send,
impl Sync for QueryExplanationwhere
RawVecInner: Sync,
impl Unpin for QueryExplanation
impl UnsafeUnpin for QueryExplanationwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<ToolExplanation>: UnsafeUnpin,
impl UnwindSafe for QueryExplanationwhere
RawVecInner: UnwindSafe,
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