Accepted
We needed an intent recognition system that:
- Works offline without external APIs
- Provides confidence scores for matching
- Handles variations in user phrasing
- Is fast enough for real-time conversation
- Can be tuned per scenario
We implemented a multi-metric similarity matching approach combining:
// Build IDF cache from all intent examples
const tfidf = computeTFIDF(tokens);
const similarity = cosineSimilarity(inputTFIDF, exampleTFIDF);const jaccard = jaccardSimilarity(inputTokens, exampleTokens);// Boost score for critical keywords
const keywordBoost = calculateKeywordBoost(input, pattern);const finalScore = (cosine * 0.5) + (jaccard * 0.3) + (keywordBoost * 0.2);- Exact match (button clicks, exact phrases)
- Intent-based matching (multi-metric)
- Regex patterns
- Keyword matching
- Fuzzy string matching (Levenshtein)
- ✅ 89% intent accuracy on test scenarios
- ✅ ~5ms average matching time
- ✅ Works completely offline
- ✅ Confidence thresholds allow graceful degradation
- ✅ Emotion detection adds contextual awareness
- ❌ Requires example phrases for each intent
- ❌ May miss context that LLMs would catch
- ❌ Performance degrades with very large intent sets
- Confidence thresholds prevent low-quality matches
- Fallback to fuzzy matching catches edge cases
- Intent sets are scenario-specific (typically 5-15 intents)
- Rejected due to cost, latency, and offline requirement
- Rejected due to inflexibility and maintenance burden
- Considered but TF-IDF provides better accuracy for short text