/** * Query Expansion & Synonyms Module (SMCP-095) * * Implements query expansion with synonym mappings to improve search recall. * When users search for "auth", the query is expanded to include * "authentication authorize login session token". * * Inspired by mcp-vector-search's query expansion system with 59+ expansion rules. * * Features: * - 60+ expansion mappings organized by category * - Preserves original query terms (expansion, not replacement) * - Removes duplicate terms for efficiency * - Configurable enable/disable * - Low overhead (< 1ms per expansion) * - Bidirectional matching (abbreviation <-> full term) * * @module queryExpansion */ /** * Configuration for query expansion. */ export interface QueryExpansionConfig { /** Enable/disable query expansion (default: true) */ enabled: boolean; /** Maximum number of expansion terms to add (default: 10) */ maxExpansionTerms?: number; /** Custom expansion mappings (merged with defaults) */ customExpansions?: Record; } /** * Result of query expansion. */ export interface QueryExpansionResult { /** Original query */ originalQuery: string; /** Expanded query with synonym terms added */ expandedQuery: string; /** Terms that were expanded */ expandedTerms: string[]; /** Expansion mappings that were applied */ appliedExpansions: string[]; /** Time taken for expansion in milliseconds */ expansionTimeMs: number; } /** * Default query expansion mappings organized by category. * * Each key maps to space-separated expansion terms. When the key is found * in a query, the expansion terms are added to improve recall. * * Categories: * - Authentication & Security * - Database & Storage * - API & HTTP * - Async & Concurrency * - Errors & Exceptions * - Configuration & Settings * - Common Abbreviations * - Programming Concepts * - Testing * - Logging & Debugging * - File & I/O * - Networking */ export declare const DEFAULT_QUERY_EXPANSIONS: Record; /** * Default configuration for query expansion. */ export declare const DEFAULT_EXPANSION_CONFIG: QueryExpansionConfig; /** * Expand a query with synonym mappings. * * Takes a search query and adds related terms based on the expansion mappings. * The original query terms are preserved, and expansion terms are appended. * Duplicate terms are removed to avoid redundancy. * * @param query - The search query to expand * @param config - Optional configuration overrides * @returns The expanded query string * * @example * ```typescript * expandQuery('auth middleware') * // Returns: 'auth middleware authentication authorize authorization login logout session token' * * expandQuery('db query') * // Returns: 'db query database data storage sql' * * expandQuery('auth', { enabled: false }) * // Returns: 'auth' (expansion disabled) * ``` */ export declare function expandQuery(query: string, config?: Partial): string; /** * Expand a query and return detailed information about the expansion. * * This function provides full details about which terms were expanded * and which mappings were applied. * * @param query - The search query to expand * @param config - Optional configuration overrides * @returns QueryExpansionResult with expansion details * * @example * ```typescript * const result = expandQueryWithDetails('auth'); * // result.expandedTerms: ['authentication', 'authorize', ...] * // result.appliedExpansions: ['auth'] * // result.expansionTimeMs: 0.5 * ``` */ export declare function expandQueryWithDetails(query: string, config?: Partial): QueryExpansionResult; /** * Check if a term has expansion mappings. * * @param term - The term to check * @param customExpansions - Optional custom expansions to include * @returns True if the term has expansion mappings */ export declare function hasExpansion(term: string, customExpansions?: Record): boolean; /** * Get expansion terms for a specific term. * * @param term - The term to get expansions for * @param customExpansions - Optional custom expansions to include * @returns Array of expansion terms, or empty array if none */ export declare function getExpansionTerms(term: string, customExpansions?: Record): string[]; /** * Get all available expansion keys. * * @param customExpansions - Optional custom expansions to include * @returns Array of all expansion keys (terms that can be expanded) */ export declare function getExpansionKeys(customExpansions?: Record): string[]; /** * Get the total number of expansion mappings. * * @param customExpansions - Optional custom expansions to include * @returns Number of expansion mappings */ export declare function getExpansionCount(customExpansions?: Record): number; /** * Create a query expander with pre-configured settings. * * @param config - Configuration options * @returns A configured expand function * * @example * ```typescript * const expand = createQueryExpander({ maxExpansionTerms: 5 }); * const expandedQuery = expand('auth login'); * ``` */ export declare function createQueryExpander(config?: Partial): (query: string) => string; /** * Create a query expander that returns detailed results. * * @param config - Configuration options * @returns A configured expand function that returns QueryExpansionResult */ export declare function createDetailedQueryExpander(config?: Partial): (query: string) => QueryExpansionResult; /** * Categories of expansion mappings for documentation purposes. */ export declare const EXPANSION_CATEGORIES: readonly ["Authentication & Security", "Database & Storage", "API & HTTP", "Async & Concurrency", "Errors & Exceptions", "Configuration & Settings", "Common Abbreviations", "Programming Concepts", "Testing", "Logging & Debugging", "File & I/O", "Networking"]; export type ExpansionCategory = (typeof EXPANSION_CATEGORIES)[number]; //# sourceMappingURL=queryExpansion.d.ts.map