/** * Semantic Cache for LLM responses * * Cache LLM responses with similarity-based retrieval for cost savings. * Uses database prefix scanning to store and retrieve cached responses. */ import { EmbeddedDatabase } from './embedded'; export interface CacheEntry { key: string; value: string; embedding: number[]; timestamp: number; ttl?: number; metadata?: Record; } export interface CacheHit extends CacheEntry { score: number; } export interface CacheStats { count: number; hits: number; misses: number; hitRate: number; memoryUsage: number; } /** * Semantic Cache with vector similarity matching * * @example * ```typescript * const cache = new SemanticCache(db, 'llm_responses'); * * // Store response * await cache.put( * 'What is Python?', * 'Python is a high-level programming language...', * embedding, * 3600 // TTL in seconds * ); * * // Check cache * const hit = await cache.get(queryEmbedding, 0.85); * if (hit) { * console.log(`Cache HIT: ${hit.value} (similarity: ${hit.score})`); * } * ``` */ export declare class SemanticCache { private db; private cacheName; private prefix; private hits; private misses; constructor(db: EmbeddedDatabase, cacheName: string); /** * Store a cached response */ put(key: string, value: string, embedding: number[], ttlSeconds?: number, metadata?: Record): Promise; /** * Retrieve cached response by similarity * * @param queryEmbedding - Query embedding vector * @param threshold - Minimum cosine similarity (0-1) * @returns Best matching cache entry or null */ get(queryEmbedding: number[], threshold?: number): Promise; /** * Delete a specific cache entry */ delete(key: string): Promise; /** * Clear all entries in this cache */ clear(): Promise; /** * Get cache statistics */ stats(): Promise; /** * Purge expired entries */ purgeExpired(): Promise; } //# sourceMappingURL=semantic-cache.d.ts.map