Skip to main content

toolhub_recommender/
params.rs

1//! Shared recommend-pipeline tuning constants + helpers.
2//!
3//! Used by both the CLI `recommend` command and the MCP server so changes
4//! land in one place.
5
6pub const VEC_CANDIDATES: usize = 50;
7pub const FTS_CANDIDATES: usize = 50;
8pub const COS_WEIGHT: f32 = 0.6;
9pub const FTS_WEIGHT: f32 = 0.4;
10
11/// Tokenise on whitespace, double-quote each token (escaping internal quotes),
12/// and OR-join. OR keeps recall when only some words match.
13pub fn build_fts_query(task: &str) -> String {
14    let toks: Vec<String> = task
15        .split_whitespace()
16        .filter(|t| !t.is_empty())
17        .map(|t| {
18            let cleaned = t.replace('"', "");
19            format!("\"{cleaned}\"")
20        })
21        .collect();
22    toks.join(" OR ")
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn empty_input_yields_empty_query() {
31        assert_eq!(build_fts_query(""), "");
32        assert_eq!(build_fts_query("   "), "");
33    }
34
35    #[test]
36    fn quotes_each_token_and_or_joins() {
37        assert_eq!(build_fts_query("design tokens"), "\"design\" OR \"tokens\"");
38    }
39
40    #[test]
41    fn strips_embedded_quotes() {
42        assert_eq!(build_fts_query("ab\"cd"), "\"abcd\"");
43    }
44}