Skip to main content
Glama

get_decayed_graph

Retrieve knowledge graph memories with confidence values adjusted for time decay to maintain relevance and accuracy.

Instructions

Get your Memento MCP knowledge graph memory with confidence values decayed based on time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
reference_timeNoOptional reference timestamp (in milliseconds since epoch) for decay calculation
decay_factorNoOptional decay factor override (normally calculated from half-life)

Implementation Reference

  • Registers the 'get_decayed_graph' tool and defines its input schema (optional reference_time and decay_factor).
    { 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)', }, }, }, },
  • MCP CallTool handler for 'get_decayed_graph': parses arguments, calls KnowledgeGraphManager.getDecayedGraph() with options if provided, returns JSON stringified result.
    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}` }], }; }
  • KnowledgeGraphManager.getDecayedGraph(): checks if storageProvider supports it and delegates the call.
    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(); }
  • Core implementation of getDecayedGraph in Neo4jStorageProvider: loads current entities and relations, applies exponential decay to relation confidences based on age using configurable half-life and min confidence, adds decay_info 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; } }
  • StorageProvider interface definition for optional getDecayedGraph method.
    getDecayedGraph?(): Promise<KnowledgeGraph>;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gannonh/memento-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server