Repository navigation
Closed
Labels
Description
Overview
Implement ML-based intent classification as a clarity gatekeeper that validates user prompts before handing off to LLM function calling. This two-stage pipeline ensures only clear, unambiguous prompts proceed to expensive LLM operations.
Context: Two-Stage Pipeline Architecture
Stage 1: ML Gatekeeper (this issue)
- Fast classification to detect prompt clarity and intent
- Validates single-intent vs multi-intent
- Asks users to clarify/simplify ambiguous prompts
- Only clear prompts proceed to Stage 2
Stage 2: LLM Function Calling (separate from this issue)
- LLM decides which tool/API to call
- Receives only validated, clear prompts from Stage 1
- Uses llama.cpp-rs + Gemma 3 (with future LoRA fine-tuning)
Pipeline Flow
User Prompt
↓
ML Classifier (DistilBERT - base model initially)
↓
┌────────────────┬──────────────────┬───────────────────┐
│ High Conf │ Medium Conf │ Low Conf/Multi │
│ (>0.85) │ (0.65-0.85) │ (<0.65) │
├────────────────┼──────────────────┼───────────────────┤
│ Clear single │ Ask user to │ Ask user to │
│ intent │ confirm intent │ simplify/break │
│ │ │ down │
└────────┬───────┴──────────────────┴───────────────────┘
│
↓ (only if clear)
LLM Function Caller (Gemma 3 + LoRA)
↓
Tool/API Execution
Implementation Strategy
Phase 1: Base Model (Initial Implementation)
- Use base DistilBERT without fine-tuning
- Focus on confidence scoring and multi-intent detection
- Gather real-world usage data to inform future fine-tuning
- Validate architecture and user experience patterns
Phase 2: Fine-Tuning (Future)
- Fine-tune DistilBERT on NodeSpace-specific intents
- Train on collected usage data and edge cases
- Optimize for NodeSpace's specific intent categories
- Only proceed when patterns are clear and stable
Rationale: Start with base models to understand actual usage patterns before investing in fine-tuning. This prevents premature optimization and ensures training data quality.
Implementation Tasks
Core ML Classifier
- Create IntentClassifier using Candle + DistilBERT (base model)
- Follow patterns from
bert-implementation-guide.md - Implement confidence scoring (high/medium/low thresholds)
- Add multi-intent detection capability
- Create clarity validation logic
Intent Categories (Initial Set)
- Define 7 core intent categories:
- CREATE_SCHEMA - Schema/entity creation
- RETRIEVE_DATA - Query/search operations
- UPDATE_RECORD - Data modification
- DELETE_DATA - Data removal
- AGGREGATE - Analytics/calculations
- RAG_SEARCH - Semantic/document search
- CREATE_WORKFLOW - Workflow automation
User Interaction
- Implement clarification prompts for medium confidence
- Create breakdown prompts for multi-intent detection
- Add intent confirmation UI flow
- Handle user feedback loop
Integration
- Integrate with Tauri AppState
- Add DashMap caching for repeated queries
- Create handoff to LLM function caller
- Add performance metrics tracking
Future Fine-Tuning Preparation
- Log classification results and confidence scores
- Track user confirmations/corrections
- Build training dataset from real usage
- Document edge cases and ambiguities
Acceptance Criteria
- BERT classifier in
packages/desktop-app/src-tauri/src/intent_classifier.rs - Uses base DistilBERT (no fine-tuning initially)
- Confidence thresholds: high (≥0.85), medium (0.65-0.84), low (<0.65)
- Multi-intent detection using dual classification heads
- Clear prompts (>0.85 confidence) proceed to LLM stage
- Ambiguous prompts trigger clarification UI
- Multi-intent prompts ask user to break down
- DashMap caching for <5ms repeated queries
- Performance: 70%+ requests classified in <50ms
- Logging infrastructure for future fine-tuning data
Technical Specifications
Dependencies:
# In packages/desktop-app/src-tauri/Cargo.toml
candle-core = { git = "https://github.com/huggingface/candle.git", features = ["metal"] }
candle-nn = { git = "https://github.com/huggingface/candle.git" }
candle-transformers = { git = "https://github.com/huggingface/candle.git" }
tokenizers = { version = "0.15", default-features = false, features = ["onig"] }
hf-hub = "0.4.2"
dashmap = "5.0"
[features]
intent-classification = ["candle-core", "candle-nn", "candle-transformers"]Model: distilbert-base-uncased (66M parameters, base model)
Classification Output:
pub enum ClassificationResult {
Clear {
intent: IntentCategory,
confidence: f32, // >0.85
},
NeedsConfirmation {
intent: IntentCategory,
confidence: f32, // 0.65-0.85
alternatives: Vec<IntentCategory>,
},
NeedsClarification {
confidence: f32, // <0.65
detected_fragments: Vec<String>,
},
MultiIntent {
intents: Vec<IntentCategory>,
suggestion: String, // "Consider breaking this into X separate requests"
},
}Dependencies
- Enables: LLM function calling (separate issue/implementation)
- Blocks: Nothing - can be implemented independently
- Related: Initialize packages/nlp-engine with embedding service #108 (embeddings - different use case)
Migration Path
Current State → Phase 1:
- Implement base DistilBERT classifier
- Integrate with UI for clarification prompts
- Collect usage data and edge cases
Phase 1 → Phase 2 (Future):
- Analyze collected data for patterns
- Create fine-tuning dataset from real usage
- Fine-tune DistilBERT on NodeSpace-specific intents
- A/B test base vs fine-tuned performance
- Deploy fine-tuned model if improvement justifies cost
Performance Targets
- Classification latency: <50ms (base model)
- Cache hit latency: <5ms
- Accuracy target: >80% for clear prompts (base model)
- Multi-intent detection: >70% recall (base model)
References
This establishes the ML gatekeeper that ensures prompt clarity before expensive LLM operations.
Activity
malibio commentedon May 17, 2026
Closing — intent classification is now handled by the skill confidence system (#1090) and prompt assembler. No longer a standalone work item under the new architecture.