UNPKG

@codai/memorai-core

Version:

Simplified advanced memory engine - no tiers, just powerful semantic search with persistence

116 lines 3.33 kB
/** * High-Performance Memory Cache with TTL and LRU Eviction * Significantly improves MCP recall performance */ import type { MemoryResult } from '../types/index.js'; export interface CacheConfig { maxSize: number; defaultTtl: number; enableCompression: boolean; enableStatistics: boolean; } export interface CacheStats { hits: number; misses: number; hitRate: number; size: number; memoryUsage: number; } export declare class HighPerformanceCache<T = any> { private cache; private accessOrder; private config; private stats; constructor(config?: Partial<CacheConfig>); /** * Get value from cache with automatic TTL and LRU handling */ get(key: string): T | null; /** * Set value in cache with optional TTL */ set(key: string, value: T, ttl?: number): void; /** * Intelligent cache key generation for memory queries */ static generateMemoryQueryKey(query: string, tenantId: string, agentId?: string, options?: any): string; /** * Cache memory search results with smart invalidation */ cacheMemoryResults(query: string, tenantId: string, results: MemoryResult[], agentId?: string, options?: any): void; /** * Get cached memory results */ getCachedMemoryResults(query: string, tenantId: string, agentId?: string, options?: any): MemoryResult[] | null; /** * Invalidate cache entries for a tenant (when memories are added/removed) */ invalidateTenant(tenantId: string): void; /** * Bulk cache operations for better performance */ setMultiple(entries: Array<{ key: string; value: T; ttl?: number; }>): void; getMultiple(keys: string[]): Map<string, T | null>; /** * Get cache statistics */ getStats(): CacheStats; /** * Clear all cache entries */ clear(): void; /** * Get cache size info */ getSizeInfo(): { entries: number; memoryUsage: number; maxSize: number; }; private compress; private decompress; private evictLRU; private updateAccessOrder; private removeFromAccessOrder; private cleanup; private recordHit; private recordMiss; private updateHitRate; private updateStats; private resetStats; private calculateMemoryUsage; } /** * Global cache instance for memory operations */ export declare const memoryCache: HighPerformanceCache<{ memory: { type: "personality" | "procedure" | "preference" | "fact" | "thread" | "task" | "emotion"; id: string; content: string; confidence: number; createdAt: Date; updatedAt: Date; lastAccessedAt: Date; accessCount: number; importance: number; tags: string[]; tenant_id: string; embedding?: number[] | undefined; emotional_weight?: number | undefined; context?: Record<string, unknown> | undefined; agent_id?: string | undefined; ttl?: Date | undefined; }; score: number; relevance_reason?: string | undefined; }[]>; /** * Context cache for frequently accessed context data */ export declare const contextCache: HighPerformanceCache<unknown>; //# sourceMappingURL=HighPerformanceCache.d.ts.map