/** * Query Intent Detection Module (SMCP-085) * * Implements query intent detection to classify search queries into categories * (function search, error handling, database, API, auth, testing, etc.). * Enables dynamic chunk type boosting and query optimization for better search results. * * Inspired by claude-context-local's intent detection system. * * Features: * - Multi-intent detection (queries can match multiple categories) * - Confidence scores per intent * - Fast keyword-based detection (< 10ms overhead) * - CamelCase and snake_case aware tokenization * - Configurable keyword patterns * * @module queryIntent */ /** * Intent categories for code search queries. * Each category represents a common search intent pattern. */ export declare enum IntentCategory { /** Searching for functions, methods, or callable code */ FUNCTION = "function", /** Searching for classes, types, structs, or interfaces */ CLASS = "class", /** Searching for error handling, exceptions, or error-related code */ ERROR = "error", /** Searching for database-related code (SQL, ORM, queries) */ DATABASE = "database", /** Searching for API endpoints, routes, or HTTP-related code */ API = "api", /** Searching for authentication, authorization, or security code */ AUTH = "auth", /** Searching for tests, specs, or test utilities */ TEST = "test", /** Searching for configuration, settings, or environment code */ CONFIG = "config" } /** * Result of intent detection for a single category. */ export interface IntentMatch { /** The detected intent category */ category: IntentCategory; /** Confidence score (0.0 - 1.0) */ confidence: number; /** Keywords that triggered this intent */ matchedKeywords: string[]; } /** * Complete query intent analysis result. */ export interface QueryIntent { /** Original query string */ query: string; /** Detected intents with confidence scores, sorted by confidence (highest first) */ intents: IntentMatch[]; /** Primary intent (highest confidence), or null if no intents detected */ primaryIntent: IntentCategory | null; /** Normalized tokens from the query */ queryTokens: string[]; /** Time taken for detection in milliseconds */ detectionTimeMs: number; } /** * Pattern definition for a single intent category. */ export interface IntentPattern { /** Keywords that trigger this intent (matched as word boundaries) */ keywords: string[]; /** Regex patterns for more complex matching */ patterns?: RegExp[]; /** Base confidence when any keyword matches */ baseConfidence?: number; } /** * Configuration for intent detection. */ export interface IntentDetectionConfig { /** Enable/disable intent detection */ enabled: boolean; /** Custom keyword patterns (merged with defaults) */ customPatterns?: Partial>; /** Minimum confidence threshold to include an intent (default: 0.3) */ minConfidence?: number; /** Maximum number of intents to return (default: 3) */ maxIntents?: number; } /** * Default keyword patterns for each intent category. * These are based on common code search patterns and inspired by * claude-context-local's implementation. */ export declare const DEFAULT_INTENT_PATTERNS: Record; /** * Normalize a text string into tokens, handling CamelCase and snake_case. * * @param text - The text to tokenize * @returns Array of lowercase tokens * * @example * normalizeToTokens("getUserById") * // Returns: ["get", "user", "by", "id"] * * @example * normalizeToTokens("get_user_by_id") * // Returns: ["get", "user", "by", "id"] */ export declare function normalizeToTokens(text: string): string[]; /** * Check if a query looks like an entity/type name (likely searching for a class). * * @param query - Original query string * @param queryTokens - Normalized tokens from the query * @returns True if the query appears to be searching for an entity */ export declare function isEntityLikeQuery(query: string, queryTokens: string[]): boolean; /** * Detect intents from a search query. * * This is the main entry point for intent detection. It analyzes the query * string and returns detected intents with confidence scores. * * @param query - The search query to analyze * @param config - Optional configuration overrides * @returns QueryIntent object with detected intents * * @example * const intent = detectQueryIntent("function that handles authentication"); * // Returns: * // { * // query: "function that handles authentication", * // intents: [ * // { category: IntentCategory.FUNCTION, confidence: 0.7, matchedKeywords: ["function"] }, * // { category: IntentCategory.AUTH, confidence: 0.6, matchedKeywords: ["authentication"] } * // ], * // primaryIntent: IntentCategory.FUNCTION, * // queryTokens: ["function", "that", "handles", "authentication"], * // detectionTimeMs: 1 * // } */ export declare function detectQueryIntent(query: string, config?: Partial): QueryIntent; /** * Chunk type boost factors for search ranking. * These factors are applied based on detected query intent. */ export interface ChunkTypeBoosts { function: number; class: number; method: number; module: number; other: number; } /** * Get chunk type boost factors based on detected query intent. * * @param intent - The detected query intent * @returns Boost factors for different chunk types */ export declare function getChunkTypeBoosts(intent: QueryIntent): ChunkTypeBoosts; /** * Get intent-based tag boost factor. * * Returns a multiplier based on overlap between detected intents * and chunk tags. * * @param intent - Detected query intent * @param chunkTags - Tags associated with a chunk * @returns Boost multiplier (1.0 = no boost) */ export declare function getIntentTagBoost(intent: QueryIntent, chunkTags: string[]): number; /** * Create an intent detector with pre-configured settings. * * @param config - Configuration options * @returns A configured intent detection function */ export declare function createIntentDetector(config?: Partial): (query: string) => QueryIntent; /** * Extract intent category names from a QueryIntent for logging/display. * * @param intent - The query intent * @returns Array of intent category names */ export declare function getIntentNames(intent: QueryIntent): string[]; /** * Check if a specific intent category was detected. * * @param intent - The query intent * @param category - The category to check for * @param minConfidence - Minimum confidence threshold (default: 0) * @returns True if the category was detected with sufficient confidence */ export declare function hasIntent(intent: QueryIntent, category: IntentCategory, minConfidence?: number): boolean; //# sourceMappingURL=queryIntent.d.ts.map