UNPKG

@nomyx/assistant

Version:

A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)

57 lines (56 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EnhancedSemanticCacheManager = void 0; const SemanticCacheManager_1 = require("./SemanticCacheManager"); class EnhancedSemanticCacheManager { constructor(embeddingProvider, defaultTTL) { this.defaultTTL = 3600000; // 1 hour in milliseconds this.cacheManager = new SemanticCacheManager_1.SemanticCacheManagerImpl(embeddingProvider); this.embeddingProvider = embeddingProvider; if (defaultTTL) { this.defaultTTL = defaultTTL; } } async set(key, value, ttl) { const actualTTL = ttl || this.defaultTTL; const entry = { key, value, embedding: await this.embeddingProvider.embed(key), expiresAt: Date.now() + actualTTL, createdAt: Date.now(), }; await this.cacheManager.set(key, entry, actualTTL); } async get(key) { const entry = await this.cacheManager.get(key); if (entry && entry.expiresAt > Date.now()) { return entry.value; } return undefined; } async refresh(key) { const entry = await this.cacheManager.get(key); if (entry) { const newTTL = entry.expiresAt - entry.createdAt; await this.set(key, entry.value, newTTL); } } async delete(key) { await this.cacheManager.delete(key); } async clear() { await this.cacheManager.clear(); } async search(query, threshold) { const results = await this.cacheManager.search(query, threshold); return results.filter(entry => entry.expiresAt > Date.now()); } setDefaultTTL(ttl) { this.defaultTTL = ttl; } getDefaultTTL() { return this.defaultTTL; } } exports.EnhancedSemanticCacheManager = EnhancedSemanticCacheManager;