/** * SQLite Persistence Layer for QE ReasoningBank * ADR-021: QE ReasoningBank for Pattern Learning * * Uses better-sqlite3 for real, performant SQLite persistence. * Features: * - ACID transactions * - Prepared statements for performance * - BLOB storage for embeddings * - JSON storage for pattern data */ import { type Database as DatabaseType } from 'better-sqlite3'; import type { QEPattern, QEDomain } from './qe-patterns.js'; /** * SQLite persistence configuration */ export interface SQLitePersistenceConfig { /** Database file path */ dbPath: string; /** Enable WAL mode for better concurrency */ walMode: boolean; /** Memory-mapped I/O size in bytes */ mmapSize: number; /** Cache size in pages (-ve = KB) */ cacheSize: number; /** Enable foreign keys */ foreignKeys: boolean; } export declare const DEFAULT_SQLITE_CONFIG: SQLitePersistenceConfig; /** * SQLite-based pattern persistence */ export declare class SQLitePatternStore { private db; private readonly config; private prepared; private initialized; constructor(config?: Partial); /** * Initialize the database */ initialize(): Promise; /** * Create database schema */ private createSchema; /** * Prepare commonly used statements */ private prepareStatements; /** * Store a pattern */ storePattern(pattern: QEPattern, embedding?: number[]): string; /** * Get a pattern by ID */ getPattern(id: string): QEPattern | null; /** * Get all patterns with optional domain filter */ getPatterns(options?: { domain?: QEDomain; limit?: number; }): QEPattern[]; /** * Get all embeddings for HNSW indexing */ getAllEmbeddings(): Array<{ patternId: string; embedding: number[]; }>; /** * Record pattern usage */ recordUsage(patternId: string, success: boolean, metrics?: Record, feedback?: string): void; /** * Promote pattern to long-term tier */ promotePattern(patternId: string): void; /** * Get statistics */ getStats(): { totalPatterns: number; byDomain: Record; byTier: Record; }; /** * Convert database row to QEPattern */ private rowToPattern; /** * Update pattern fields (for feedback loop) */ updatePattern(patternId: string, updates: Partial<{ usageCount: number; successfulUses: number; successRate: number; qualityScore: number; confidence: number; tier: 'short-term' | 'working' | 'long-term'; }>): void; /** * Close the database */ close(): void; /** * Run raw SQL (for migrations, testing) */ exec(sql: string): void; /** * Get the underlying database (for advanced operations) */ getDb(): DatabaseType; } /** * Create a SQLite pattern store */ export declare function createSQLitePatternStore(config?: Partial): SQLitePatternStore; //# sourceMappingURL=sqlite-persistence.d.ts.map