/** * SQLiteFTS5Engine - Native SQLite FTS5 Engine * * Implements the FTSEngine interface using SQLite FTS5 via better-sqlite3. * This engine provides high-performance keyword search for large codebases. * * Key features: * - Native SQLite performance (C-based) * - Disk-backed persistence (survives restarts) * - Full FTS5 features (phrase search, prefix, boolean operators) * - Efficient incremental updates (add/remove) * - BM25 scoring for relevance ranking * - Porter stemming for better matching * * Limitations: * - Requires native module (better-sqlite3) * - May fail to install on some platforms without build tools * - Larger package size than pure JS solution */ import { FTSEngine, FTSEngineType, FTSChunk, FTSSearchResult, FTSStats } from './ftsEngine.js'; /** * Options for creating the SQLiteFTS5Engine */ export interface SQLiteFTS5Options { /** Path to the SQLite database file (will be created if doesn't exist) */ dbPath: string; } /** * Check if the better-sqlite3 native module is available. * * This function uses dynamic import to avoid crashes when the module * is not installed. The result is cached for subsequent calls. * * @returns Promise resolving to true if native module is available */ export declare function isNativeAvailable(): Promise; /** * Reset the native availability cache (mainly for testing) */ export declare function resetNativeAvailableCache(): void; /** * SQLite FTS5 based FTS engine for high-performance keyword search. * * Uses SQLite's Full-Text Search 5 extension with BM25 scoring. * Provides disk-backed persistence and efficient incremental updates. */ export declare class SQLiteFTS5Engine implements FTSEngine { readonly engineType: FTSEngineType; /** SQLite database instance */ private db; /** Path to the database file */ private dbPath; /** Prepared statements cache */ private statements; constructor(options: SQLiteFTS5Options); /** * Initialize the database connection and create FTS5 table. * Must be called before using the engine. */ initialize(): Promise; /** * Prepare commonly used SQL statements for better performance */ private prepareStatements; /** * Ensure the database is initialized before operations */ private ensureInitialized; /** * Add multiple chunks to the index using a transaction for efficiency */ addChunks(chunks: FTSChunk[]): Promise; /** * Add a single chunk to the index */ addChunk(chunk: FTSChunk): Promise; /** * Remove all chunks for a file path */ removeByPath(filePath: string): void; /** * Search the index with a query string using FTS5 MATCH */ search(query: string, topK: number): FTSSearchResult[]; /** * Fallback search using LIKE for invalid FTS queries */ private fallbackSearch; /** * Escape and format query for FTS5 MATCH syntax. * * FTS5 special characters: " * ^ - + ( ) : OR AND NOT NEAR * * Strategy: * - If query looks like it uses FTS5 syntax (contains operators), pass through * - Otherwise, wrap each word in quotes to match literally */ private escapeQuery; /** * Normalize search scores to 0-1 range. * * FTS5 bm25() returns negative scores where more negative = better match. * This method converts them to positive 0-1 range for hybrid search. */ normalizeScores(results: FTSSearchResult[]): FTSSearchResult[]; /** * Get index statistics */ getStats(): FTSStats; /** * Check if the index has any data */ hasData(): boolean; /** * Serialize the engine state. * * For SQLiteFTS5Engine, the actual data is persisted in the SQLite database. * This method returns metadata about the database location. */ serialize(): string; /** * Load engine state from serialized data. * * For SQLiteFTS5Engine, this verifies the database path matches * and ensures the database is initialized. * * @returns true if successful, false otherwise */ deserialize(data: string): boolean; /** * Clear all data from the index */ clear(): void; /** * Close the database connection and cleanup resources */ close(): void; } /** * Create and initialize a new SQLiteFTS5Engine instance. * * This is the recommended way to create the engine as it handles * initialization automatically. * * @param dbPath - Path to the SQLite database file * @returns Initialized SQLiteFTS5Engine instance * @throws If native module is not available or initialization fails */ export declare function createSQLiteFTS5Engine(dbPath: string): Promise; //# sourceMappingURL=sqliteFTS5.d.ts.map