get_decayed_graph
Retrieve a decayed Memento MCP knowledge graph by applying time-based decay to confidence values, using optional reference timestamp and decay factor for customization.
Instructions
Get your Memento MCP knowledge graph memory with confidence values decayed based on time
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| decay_factor | No | Optional decay factor override (normally calculated from half-life) | |
| reference_time | No | Optional reference timestamp (in milliseconds since epoch) for decay calculation |
Implementation Reference
- Core implementation of getDecayedGraph in the Neo4j storage provider. Loads the current graph and applies exponential decay to relation confidence values based on their age relative to the configured half-life, with a minimum confidence floor. Includes decay diagnostics.async getDecayedGraph(): Promise<KnowledgeGraph> { try { // If decay is not enabled, just return the regular graph if (!this.decayConfig.enabled) { return this.loadGraph(); } const startTime = Date.now(); // Load entities const entityQuery = ` MATCH (e:Entity) WHERE e.validTo IS NULL RETURN e `; const entityResult = await this.connectionManager.executeQuery(entityQuery, {}); const entities = entityResult.records.map((record) => { const node = record.get('e').properties; return this.nodeToEntity(node); }); // Calculate decay factor const halfLifeMs = this.decayConfig.halfLifeDays * 24 * 60 * 60 * 1000; const decayFactor = Math.log(0.5) / halfLifeMs; // Load relations and apply decay const relationQuery = ` MATCH (from:Entity)-[r:RELATES_TO]->(to:Entity) WHERE r.validTo IS NULL RETURN r, from.name AS fromName, to.name AS toName `; const relationResult = await this.connectionManager.executeQuery(relationQuery, {}); const relations = relationResult.records.map((record) => { const rel = record.get('r').properties; const fromName = record.get('fromName'); const toName = record.get('toName'); // Create base relation const relation = this.relationshipToRelation(rel, fromName, toName); // Apply decay if confidence is present if (relation.confidence !== null && relation.confidence !== undefined) { const extendedRelation = relation as ExtendedRelation; const ageDiff = startTime - (extendedRelation.validFrom || extendedRelation.createdAt || startTime); let decayedConfidence = relation.confidence * Math.exp(decayFactor * ageDiff); // Don't let confidence decay below minimum if (decayedConfidence < this.decayConfig.minConfidence) { decayedConfidence = this.decayConfig.minConfidence; } relation.confidence = decayedConfidence; } return relation; }); const timeTaken = Date.now() - startTime; // Return the graph with decayed confidence values return { entities, relations, total: entities.length, timeTaken, diagnostics: { decay_info: { enabled: this.decayConfig.enabled, halfLifeDays: this.decayConfig.halfLifeDays, minConfidence: this.decayConfig.minConfidence, decayFactor, }, }, }; } catch (error) { logger.error('Error getting decayed graph from Neo4j', error); throw error; } }
- src/KnowledgeGraphManager.ts:1160-1166 (handler)KnowledgeGraphManager proxy method for getDecayedGraph that delegates to the underlying storage provider if the method is supported.async getDecayedGraph(): Promise<KnowledgeGraph & { decay_info?: Record<string, unknown> }> { if (!this.storageProvider || typeof this.storageProvider.getDecayedGraph !== 'function') { throw new Error('Storage provider does not support decay operations'); } return this.storageProvider.getDecayedGraph(); }
- src/server/handlers/listToolsHandler.ts:461-479 (registration)Tool registration in listToolsHandler including name, description, and input schema definition for get_decayed_graph.{ name: 'get_decayed_graph', description: 'Get your Memento MCP knowledge graph memory with confidence values decayed based on time', inputSchema: { type: 'object', properties: { reference_time: { type: 'number', description: 'Optional reference timestamp (in milliseconds since epoch) for decay calculation', }, decay_factor: { type: 'number', description: 'Optional decay factor override (normally calculated from half-life)', }, }, }, },
- Dispatch handler in callToolHandler that processes get_decayed_graph tool calls, extracts optional parameters, calls KnowledgeGraphManager.getDecayedGraph, and formats the response.case 'get_decayed_graph': try { // Extract optional parameters if provided by client const options: { referenceTime?: number; decayFactor?: number; } = {}; if (args.reference_time) { options.referenceTime = Number(args.reference_time); } if (args.decay_factor) { options.decayFactor = Number(args.decay_factor); } // Pass options to getDecayedGraph if any are provided const graph = Object.keys(options).length > 0 ? await knowledgeGraphManager.getDecayedGraph(options) : await knowledgeGraphManager.getDecayedGraph(); return { content: [{ type: 'text', text: JSON.stringify(graph, null, 2) }] }; } catch (error: Error | unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text', text: `Error retrieving decayed graph: ${errorMessage}` }], }; }