Classification Extraction
Classification Extraction
Section titled “Classification Extraction”Classification extraction allows your classification sets to automatically split compound queries into individual sub-queries and classify each one.
Overview
Section titled “Overview”When enabled, the LLM can detect when a query contains multiple distinct intents and extract them into separate queries. Each extracted query is then classified using the same classification set.
Example
Section titled “Example”Input: “Turn on kitchen lights and turn off bedroom lights”
Without extraction:
{ "classification": "", "extraction_needed": true, "confidence": 0.95}With extraction:
{ "classification": "", "extraction_needed": true, "confidence": 0.95, "extracted": [ { "query": "turn on kitchen lights", "classification": "kitchen", "confidence": 0.97 }, { "query": "turn off bedroom lights", "classification": "bedroom", "confidence": 0.96 } ]}When to Use Extraction
Section titled “When to Use Extraction”Enable extraction when:
- Your queries may contain multiple distinct intents
- You need to process each intent separately
- You want to save HTTP round trips
Don’t enable extraction when:
- All queries are single-intent
- You handle multi-intent queries differently
- Cost is a primary concern
Cost Impact
Section titled “Cost Impact”Extraction increases request usage:
- Without extraction: 1 request per classification
- With extraction: 2 requests (1 classify + 1 extract with sub-classifications)
Example:
- “Turn on kitchen lights” → 1 request (extraction_needed: false)
- “Turn on kitchen and turn off bedroom” → 2 requests (extraction with 2 sub-classifications)
Benefit: Saves N-1 requests vs manual approach (which would need 1 + N requests)
How It Works
Section titled “How It Works”- You enable extraction on a classification set
- When classifying, the LLM determines if extraction is needed (returns extraction_needed flag)
- If needed AND extraction is enabled, a second LLM call extracts and classifies all sub-queries
- Results are returned in a single response
Enabling Extraction
Section titled “Enabling Extraction”Via Console
Section titled “Via Console”- Go to your app’s Classification Sets
- Create or edit a classification set
- Check “Enable Automatic Extraction”
- Save
Via API
Section titled “Via API”// Create with extraction enabledconst response = await fetch('https://api.intentgine.dev/v1/classification-sets', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ signature: 'my-classifier-v1', name: 'My Classifier', classes: [ { label: 'class1', description: 'First class' }, { label: 'class2', description: 'Second class' } ], enable_extraction: true })});Response Format
Section titled “Response Format”When extraction is performed, the response includes an extracted array:
interface ClassificationResult { input: string; classification: string; extraction_needed: boolean; confidence: number; extracted?: Array<{ query: string; classification: string; confidence: number; }>;}Response Fields
Section titled “Response Fields”classification(string): One of the defined classes, or empty string if no matchextraction_needed(boolean): LLM’s determination of whether extraction should be performedextracted(array, optional): Array of extracted sub-queries with classificationsmetadata.extraction_performed(boolean): Whether extraction was actually performedmetadata.sub_classifications_performed(number): Number of sub-queries classified
Best Practices
Section titled “Best Practices”- Test thoroughly: Verify extraction works for your use case
- Monitor costs: Track request usage with extraction enabled
- Use appropriate classes: Ensure your classes support multi-intent detection
- Handle both cases: Code should handle results with and without extraction
Examples
Section titled “Examples”Multi-Intent Detection
Section titled “Multi-Intent Detection”// Classification set{ "signature": "intent-type-v1", "classes": [ { "label": "single-intent", "description": "One action" }, { "label": "multi-intent", "description": "Multiple actions" } ], "enable_extraction": true}
// Query"Turn on kitchen lights and turn off bedroom lights"
// Response{ "results": [{ "input": "turn on kitchen lights and turn off bedroom lights", "classification": "", "extraction_needed": true, "confidence": 0.95, "extracted": [ { "query": "turn on kitchen lights", "classification": "single-intent", "confidence": 0.98 }, { "query": "turn off bedroom lights", "classification": "single-intent", "confidence": 0.97 } ] }], "metadata": { "requests_used": 2, "extraction_performed": true, "sub_classifications_performed": 2, "source": "compute", "requests_remaining": 9998 }}Area-Based Routing
Section titled “Area-Based Routing”// Classification set{ "signature": "area-router-v1", "classes": [ { "label": "kitchen", "description": "Kitchen area" }, { "label": "bedroom", "description": "Bedroom area" }, { "label": "living-room", "description": "Living room area" } ], "enable_extraction": true}
// Query"Turn on kitchen and bedroom lights"
// Response{ "classification": "", "extraction_needed": true, "extracted": [ { "query": "turn on kitchen lights", "classification": "kitchen", "confidence": 0.96 }, { "query": "turn on bedroom lights", "classification": "bedroom", "confidence": 0.95 } ]}Configuring Extraction Prompt
Section titled “Configuring Extraction Prompt”Admins can customize the extraction prompt in the system settings:
- Navigate to System → System Settings
- Edit the “Classification Extraction Prompt”
- Save changes
The default prompt guides the LLM to:
- Extract when: Different actions, devices, or areas
- Don’t extract when: Same action on multiple targets
Troubleshooting
Section titled “Troubleshooting”Extraction not working
Section titled “Extraction not working”- Verify
enable_extractionis true on the classification set - Check that queries actually contain multiple intents
- Review extraction prompt configuration
Unexpected costs
Section titled “Unexpected costs”- Monitor
requests_usedin response metadata - Check
extraction_performedflag - Consider disabling extraction for single-intent use cases
Low confidence scores
Section titled “Low confidence scores”- Review class descriptions for clarity
- Adjust extraction prompt if needed
- Test with different query phrasings