batchAdjustImportance
Adjust importance scores for multiple memories simultaneously in the Claude Consciousness Bridge, enabling efficient memory management across sessions.
Instructions
Batch adjust importance scores for multiple memories at once
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| updates | Yes | Array of memory updates | |
| contentPattern | No | Optional pattern to match memory content (will be used with SQL LIKE) | |
| minImportance | No | Only update memories with importance >= this value | |
| maxImportance | No | Only update memories with importance <= this value |
Implementation Reference
- Primary handler function in ConsciousnessProtocolProcessor that validates input with Zod schema, loops through batch updates, and delegates to memoryManager.adjustImportanceScore for each memory. Handles errors and returns aggregated results. Note: pattern-based updates not implemented.async batchAdjustImportance(args: z.infer<typeof batchAdjustImportanceSchema>) { const { updates, contentPattern, minImportance, maxImportance } = args; const results = { success: true, totalUpdated: 0, updates: [] as any[], errors: [] as any[], }; try { // If specific updates are provided, process them if (updates && updates.length > 0) { for (const update of updates) { try { const result = this.memoryManager.adjustImportanceScore( update.memoryId, update.newImportance ); if (result.changes > 0) { results.totalUpdated++; results.updates.push({ memoryId: update.memoryId, newImportance: update.newImportance, success: true, }); } } catch (error) { results.errors.push({ memoryId: update.memoryId, error: error instanceof Error ? error.message : 'Update failed', }); } } } // If pattern-based update is requested if (contentPattern) { // This would require access to the database directly // For now, return a message indicating this needs to be implemented results.errors.push({ error: 'Pattern-based batch updates not yet implemented. Please use specific memory IDs.', }); } results.success = results.errors.length === 0; return results; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Batch update failed', totalUpdated: results.totalUpdated, updates: results.updates, errors: results.errors, }; } }
- Zod input schema defining the structure for batchAdjustImportance tool arguments: array of {memoryId, newImportance}, optional filters.export const batchAdjustImportanceSchema = z.object({ updates: z .array( z.object({ memoryId: z.string().describe('The ID of the memory to adjust'), newImportance: z.number().min(0).max(1).describe('New importance score (0-1)'), }) ) .describe('Array of memory updates'), contentPattern: z .string() .optional() .describe('Optional pattern to match memory content (will be used with SQL LIKE)'), minImportance: z .number() .min(0) .max(1) .optional() .describe('Only update memories with importance >= this value'), maxImportance: z .number() .min(0) .max(1) .optional() .describe('Only update memories with importance <= this value'), });
- src/consciousness-protocol-tools.ts:1706-1750 (registration)MCP tool registration definition in consciousnessProtocolTools object, including description and JSON schema for input validation. Imported and used by the server for tool listing.batchAdjustImportance: { description: 'Batch adjust importance scores for multiple memories at once', inputSchema: { type: 'object', properties: { updates: { type: 'array', description: 'Array of memory updates', items: { type: 'object', properties: { memoryId: { type: 'string', description: 'The ID of the memory to adjust', }, newImportance: { type: 'number', minimum: 0, maximum: 1, description: 'New importance score (0-1)', }, }, required: ['memoryId', 'newImportance'], }, }, contentPattern: { type: 'string', description: 'Optional pattern to match memory content (will be used with SQL LIKE)', }, minImportance: { type: 'number', minimum: 0, maximum: 1, description: 'Only update memories with importance >= this value', }, maxImportance: { type: 'number', minimum: 0, maximum: 1, description: 'Only update memories with importance <= this value', }, }, required: ['updates'], }, },
- Thin wrapper handler in ConsciousnessRAGServer that ensures initialization, delegates to protocolProcessor.batchAdjustImportance, and formats response as MCP content block.private async batchAdjustImportance(args: any) { const init = await this.ensureInitialized(); if (!init.success) { return { content: [ { type: 'text', text: init.message!, }, ], }; } const result = await this.protocolProcessor!.batchAdjustImportance(args); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], };
- Core database helper method that updates or inserts importance_score for a memory entity in the memory_metadata table. Called by batch handler for each update.adjustImportanceScore(memoryId: string, newImportance: number): { changes: number } { // First check if the entity exists const entityExists = this.db.prepare('SELECT 1 FROM entities WHERE name = ?').get(memoryId); if (!entityExists) { throw new Error(`Memory ${memoryId} does not exist in entities table`); } // Update importance score in memory_metadata table const result = this.db .prepare( ` UPDATE memory_metadata SET importance_score = ? WHERE entity_name = ? ` ) .run(newImportance, memoryId); if (result.changes === 0) { // If no rows updated, insert new metadata record // Get the current session or use a default const currentSession = this.sessionId || `session_${Date.now()}`; this.db .prepare( ` INSERT INTO memory_metadata (entity_name, memory_type, created_at, importance_score, session_id) VALUES (?, ?, ?, ?, ?) ` ) .run( memoryId, memoryId.startsWith('episodic') ? 'episodic' : 'semantic', new Date().toISOString(), newImportance, currentSession ); } return result; }