Module search_intent

Module search_intent 

Source
Expand description

Search intent detection for proactive memory surfacing.

Detects user intent to search for information and extracts topics for memory injection.

§Architecture

This module is organized into focused submodules:

  • types: Core types (SearchIntentType, DetectionSource, SearchIntent)
  • keyword: Fast pattern-based detection (<10ms)
  • llm: LLM-powered classification for higher accuracy
  • hybrid: Combined detection with timeout support

§Detection Modes

ModeLatencyAccuracyUse Case
Keyword<10msGoodDefault, always available
LLM~200msExcellentWhen LLM provider configured
Hybrid<200msBestCombines both with fallback

§Intent Types and Detection

IntentTrigger PatternsNamespace Weights
HowTo“how do I”, “how to”, “implement”, “create”patterns (2.0), learnings (1.5)
Location“where is”, “find”, “locate”context (1.5), patterns (1.2)
Explanation“what is”, “explain”, “describe”decisions (1.5), context (1.2)
Comparison“difference between”, “vs”, “compare”decisions (2.0), patterns (1.5)
Troubleshoot“error”, “fix”, “not working”, “debug”blockers (2.0), learnings (1.5)
General“search”, “show me”All namespaces weighted equally

§Detection Flow

User Prompt
    │
    ├─► Keyword Detection (<10ms)
    │       │
    │       └─► Intent + Confidence + Topics
    │
    └─► LLM Classification (200ms timeout) [optional]
            │
            └─► Intent + Confidence + Topics
                    │
                    └─► Merge Results (hybrid mode)
                            │
                            └─► Final Intent + Topics

§Confidence-Based Memory Injection

ConfidenceMemory CountBehavior
≥ 0.8 (high)15 memoriesFull context injection
≥ 0.5 (medium)10 memoriesStandard injection
< 0.5 (low)5 memoriesMinimal injection

§Configuration

Environment VariableDescriptionDefault
SUBCOG_SEARCH_INTENT_ENABLEDEnable intent detectiontrue
SUBCOG_SEARCH_INTENT_USE_LLMEnable LLM classificationtrue
SUBCOG_SEARCH_INTENT_LLM_TIMEOUT_MSLLM timeout200
SUBCOG_SEARCH_INTENT_MIN_CONFIDENCEMinimum confidence0.5

§Examples

use subcog::hooks::search_intent::{detect_search_intent, SearchIntentType};

// Simple keyword detection
if let Some(intent) = detect_search_intent("How do I implement OAuth?") {
    assert_eq!(intent.intent_type, SearchIntentType::HowTo);
    println!("Detected: {} with confidence {}", intent.intent_type, intent.confidence);
}

Re-exports§

pub use types::DetectionSource;
pub use types::SearchIntent;
pub use types::SearchIntentType;
pub use hybrid::detect_search_intent_hybrid;
pub use hybrid::detect_search_intent_with_timeout;
pub use keyword::detect_search_intent;
pub use llm::classify_intent_with_llm;

Modules§

hybrid 🔒
Hybrid and timeout-aware search intent detection.
keyword 🔒
Keyword-based search intent detection.
llm 🔒
LLM-based search intent classification.
types 🔒
Types for search intent detection.