/** * Phrase Matching Service * * Pure functions for content-based phrase matching. This enables * exact phrase searches to find results even when semantic/BM25 * scores are low. * * @module domain/services/phraseMatch */ /** * Result of phrase matching analysis. */ export interface PhraseMatchResult { /** Whether the exact query phrase was found in content */ exactMatch: boolean; /** Proportion of query tokens found in content (0-1) */ coverage: number; /** Number of query tokens found in content */ matchedTokenCount: number; /** Total number of tokens in query */ totalTokenCount: number; /** Additive score boost based on match quality */ boost: number; /** Whether this match is significant enough to bypass filters */ isSignificant: boolean; } /** * Constants for phrase matching scoring. */ export declare const PHRASE_MATCH_CONSTANTS: { /** Major boost for exact phrase match */ readonly EXACT_PHRASE_BOOST: 0.5; /** Boost for high token coverage (80%+) */ readonly HIGH_COVERAGE_BOOST: 0.2; /** Boost for medium token coverage (60%+) */ readonly MEDIUM_COVERAGE_BOOST: 0.1; /** Coverage threshold for "high" classification */ readonly HIGH_COVERAGE_THRESHOLD: 0.8; /** Coverage threshold for "medium" classification */ readonly MEDIUM_COVERAGE_THRESHOLD: 0.6; /** Minimum query length to consider for exact matching */ readonly MIN_QUERY_LENGTH: 3; }; /** * Tokenize a string into words for matching. * Normalizes to lowercase and filters out punctuation. * * @param text - Text to tokenize * @param filterStopWords - Whether to filter out stop words * @returns Array of normalized tokens */ export declare function tokenizeForMatching(text: string, filterStopWords?: boolean): string[]; /** * Calculate phrase match score for content against a query. * * This function checks: * 1. Exact phrase match (query substring in content) * 2. Token coverage (what % of query tokens appear in content) * * @param content - The chunk content to search in * @param query - The search query * @returns PhraseMatchResult with match details and boost * * @example * const result = calculatePhraseMatch( * "This explains the authentication flow for new users", * "authentication flow for new users" * ); * // result.exactMatch = true * // result.boost = 0.5 (EXACT_PHRASE_BOOST) * * @example * const result = calculatePhraseMatch( * "User authentication and session flow", * "authentication flow for users" * ); * // result.exactMatch = false * // result.coverage = 0.75 (3/4 tokens found) * // result.boost = 0.1 (MEDIUM_COVERAGE_BOOST) */ export declare function calculatePhraseMatch(content: string, query: string): PhraseMatchResult; /** * Quick check if content might contain the query phrase. * Useful for early filtering before full phrase matching. * * @param content - The chunk content * @param query - The search query * @returns true if exact phrase is found */ export declare function hasExactPhrase(content: string, query: string): boolean; /** * Calculate token coverage between content and query. * Faster than full phrase matching when only coverage is needed. * * @param content - The chunk content * @param query - The search query * @returns Coverage ratio (0-1) */ export declare function calculateTokenCoverage(content: string, query: string): number;