/** * Persistent RAG Engine for NCP * Uses transformer.js for embeddings with persistent caching */ export interface ToolEmbedding { embedding: Float32Array; hash: string; lastUpdated: string; toolName: string; description: string; enhancedDescription?: string; mcpName?: string; mcpDomain?: string; tsInterface?: string; inputSchema?: any; } export interface CacheMetadata { version: string; createdAt: string; lastValidated: string; configHash: string; mcpHashes: Record; totalTools: number; } export interface DiscoveryResult { toolId: string; confidence: number; reason: string; similarity: number; originalSimilarity?: number; domain?: string; } export declare class PersistentRAGEngine { private primaryDbPath; private swapDbPath; private activeIndexPath; private isUsingSwapIndex; private disabledMCPs; private isReindexing; /** * Get domain classification for an MCP to improve cross-domain disambiguation */ private getMCPDomain; /** * Infer likely domains from query text to improve cross-domain disambiguation */ private inferQueryDomains; /** * Add capability enhancements for reverse domain mapping * Terminal/shell tools should advertise their git, build, and development capabilities */ private getCapabilityEnhancements; /** * Generate TypeScript interface from JSON schema * Converts MCP tool input schema to TypeScript type definition */ private generateTypeScriptInterface; /** * Convert JSON schema type to TypeScript type */ private jsonSchemaTypeToTS; private model; private vectorDB; private metadataPath; private cacheMetadata; private isInitialized; private indexingQueue; private isIndexing; private semanticEnhancementEngine; /** * Get the embedding model for external use (e.g., IntentExecutor) */ getModel(): any; constructor(); /** * Validate cache against current configuration */ validateCache(currentConfig?: any): Promise; /** * Generate hash of configuration for change detection */ private hashObject; /** * Update cache metadata */ private updateCacheMetadata; /** * Initialize the RAG engine with embedding model * Falls back gracefully if transformer.js fails to load */ initialize(currentConfig?: any): Promise; /** * Index tools from an MCP (progressive loading) */ indexMCP(mcpName: string, tools: any[]): Promise; /** * Fast indexing for startup - loads from embeddings cache if available * This is called during optimized cache loading to avoid regenerating embeddings */ indexMCPFromCache(mcpName: string, tools: any[]): Promise; /** * Perform actual indexing of tools */ private performIndexing; /** * Process queued indexing tasks */ private processIndexingQueue; /** * Discover tools using semantic similarity (or fallback to keyword matching) * Includes smart re-indexing: live filtering with over-fetching */ discover(query: string, maxResults?: number, confidenceThreshold?: number): Promise; /** * Enhanced fallback keyword search when RAG fails */ private fallbackKeywordSearch; /** * Calculate cosine similarity between two vectors */ private cosineSimilarity; /** * Generate hash of tool description for change detection * @deprecated Use hashTool instead to include inputSchema */ private hashDescription; /** * Generate hash of tool for change detection (includes description + inputSchema) * This ensures we regenerate embeddings and TypeScript interfaces when schemas change */ private hashTool; /** * Load cached embeddings from disk */ private loadPersistedEmbeddings; /** * Persist embeddings to disk * @param indexPath Optional path to write to (defaults to active index) * @param vectorDB Optional vectorDB to persist (defaults to current vectorDB) */ private persistEmbeddings; /** * Ensure directory exists */ private ensureDirectoryExists; /** * Get statistics about the RAG engine */ getStats(): { isInitialized: boolean; totalEmbeddings: number; queuedTasks: number; isIndexing: boolean; isReindexing: boolean; cacheSize: string; disabledMCPs: string[]; activeIndex: string; }; /** * Force cache refresh by clearing and rebuilding */ refreshCache(): Promise; /** * Clear all cached embeddings and metadata */ clearCache(): Promise; /** * Mark an MCP as disabled (for live filtering during re-indexing) */ setMCPDisabled(mcpName: string): void; /** * Mark an MCP as enabled (for live filtering during re-indexing) */ setMCPEnabled(mcpName: string): void; /** * Check if an MCP is disabled */ isMCPDisabled(mcpName: string): boolean; /** * Calculate over-fetch multiplier based on percentage of disabled MCPs */ private calculateOverFetchMultiplier; /** * Filter out tools from disabled MCPs */ private filterDisabledMCPs; /** * Trigger background re-indexing to swap file (excludes disabled MCPs) */ triggerBackgroundReindex(): Promise; /** * Atomically swap active index to the newly built swap file */ private atomicSwap; } //# sourceMappingURL=rag-engine.d.ts.map