/** * Cached Embedding Provider * * Transparent caching layer for embedding providers. * Wraps any EmbeddingProvider with automatic caching using SHA-256 content hashing. * * Features: * - Transparent cache hits (0.09ms average latency) * - Automatic cache misses fallback to base provider * - Batch operation support with partial cache hits * - Cache statistics tracking (hits, misses, hit rate) * * Based on OpenClaw's EmbeddingCache pattern. */ import type { EmbeddingProvider } from "./provider.js"; import type { EmbeddingProviderConfig } from "./config.js"; import type { EmbeddingCacheStore } from "../cache/embedding-cache-contract.js"; /** * Cache statistics for monitoring performance */ export interface CacheStats { hits: number; misses: number; hitRate: number; totalRequests: number; } /** * Embedding provider with transparent caching * * Automatically caches embeddings using content-based SHA-256 hashing. * Cache hits return in ~0.09ms, cache misses fall back to base provider. */ export declare class CachedEmbeddingProvider implements EmbeddingProvider { private readonly baseProvider; private readonly cache; readonly id: string; readonly model: string; readonly dimensions: number; private hits; private misses; constructor(baseProvider: EmbeddingProvider, cache: EmbeddingCacheStore); /** * Embed a single query with caching * * Flow: * 1. Check cache (SHA-256 hash of text) * 2. If hit: return cached embedding (~0.09ms) * 3. If miss: call base provider, cache result, return */ embedQuery(text: string): Promise; /** * Embed batch with partial cache hits * * Optimized flow: * 1. Check cache for all texts (parallel) * 2. Identify cache misses * 3. Batch embed only misses * 4. Cache new embeddings * 5. Merge cached + new results in original order */ embedBatch(texts: string[]): Promise; /** * Check if base provider is available */ isAvailable(): Promise; /** * Get base provider configuration */ getConfig(): EmbeddingProviderConfig; /** * Get cache statistics */ getStats(): CacheStats; /** * Reset statistics counters */ resetStats(): void; /** * Get cache statistics from underlying cache */ getCacheInfo(): Promise<{ totalEntries: number; cacheSize: number; hitRate: number; avgDimensions: number; }>; /** * Cleanup expired cache entries * * @param maxAgeMs Maximum age in milliseconds (default: 7 days) */ cleanup(maxAgeMs?: number): Promise; } /** * Factory function to wrap a provider with caching */ export declare function withCache(provider: EmbeddingProvider, cache: EmbeddingCacheStore): CachedEmbeddingProvider; //# sourceMappingURL=cached-provider.d.ts.map