brainy/CRITICAL-API-AUDIT.md
David Snelling 26c7d61185 CHECKPOINT: Brainy 2.0 API refactor - pre-fixes state
Current state:
- Unified augmentation system to BrainyAugmentation interface
- Changed methods to specific noun/verb naming (addNoun, getNoun, etc)
- Made old methods private
- Combined getNouns into single unified method
- Neural API exists and is complete
- Triple Intelligence uses correct Brainy operators (not MongoDB)

Issues identified:
- Documentation incorrectly shows MongoDB operators (code is correct)
- Need to ensure all features are properly exposed
- Need to verify nothing was lost in simplification

This commit serves as a rollback point before applying fixes.
2025-08-25 09:52:32 -07:00

5.5 KiB

🚨 CRITICAL API AUDIT - What We Changed & Lost

📅 Timeline of Changes (Friday-Saturday)

Friday Changes:

  1. Started unifying augmentation system to single BrainyAugmentation interface
  2. Made old methods (add, get, delete) private
  3. Created new specific methods (addNoun, getNoun, deleteNoun)
  4. Started removing backward compatibility

Saturday Changes:

  1. Combined getNounsByIds and queryNouns into single getNouns method
  2. Simplified search API (may have oversimplified!)
  3. Accidentally introduced MongoDB operators ($gt, $in, etc.)
  4. May have removed critical features while "simplifying"

CRITICAL MISTAKES WE MADE:

// ❌ WRONG - We accidentally added:
where: { field: {$gt: value} }

// ✅ CORRECT - Should be:
where: { field: {greaterThan: value} }

2. Lost Neural API Methods

// ❌ MISSING - These were removed or not properly exposed:
brain.neural.similar(a, b)
brain.neural.clusters()
brain.neural.hierarchy(id)
brain.neural.neighbors(id)
brain.neural.outliers()
brain.neural.semanticPath(from, to)
brain.neural.visualize()        // Critical for external tools!
brain.neural.clusterFast()      // O(n) performance
brain.neural.clusterLarge()     // Million-item support

3. Lost Import Capabilities

// ❌ WRONG - We made it too complex:
neuralImport.csv()
neuralImport.json()
neuralImport.text()

// ✅ CORRECT - Should be ONE simple method:
brain.neuralImport(data, options?)  // Auto-detects format!

4. Lost Clustering for Visualization

The visualization data format for external tools (D3, Cytoscape, GraphML) is missing!

// ❌ MISSING - Critical for external visualization:
{
  format: 'd3' | 'cytoscape' | 'graphml',
  nodes: [...],
  edges: [...],
  layout: {...}
}
// ❌ REMOVED too many methods:
searchByNounTypes()
searchWithinItems()  
searchByStandardField()
searchVerbs()
searchNounsByVerbs()

// ✅ BUT this is actually OK if find() handles everything!
// Just need to ensure find() is complete

🔍 COMPARISON: Backup vs Current

Methods in BACKUP but NOT in current:

// From backup's brainyData.ts:
brain.neural                    // ❌ Not properly exposed
brain.visualize()               // ❌ Missing
brain.clusters()                // ❌ Missing  
brain.similar()                 // ❌ Missing
brain.neuralImport()            // ❌ Wrong implementation

// Operators in backup:
greaterThan, lessThan, equals   // ❌ Replaced with $gt, $lt, $eq
oneOf, contains, matches        // ❌ Replaced with $in, $contains, $regex

Methods we ADDED (some good, some questionable):

// New specific methods (GOOD ✅):
addNoun(), getNoun(), deleteNoun()

// Unified method (GOOD if complete ✅):
getNouns(idsOrOptions)  

// But lost flexibility (BAD ❌):
- Can't do complex queries easily
- Lost specific search methods

📊 Feature Comparison Table

Feature Backup Current Status
Operators greaterThan, lessThan $gt, $lt WRONG
Neural API Complete (10+ methods) Missing/Hidden BROKEN
Clustering Full support Missing LOST
Visualization D3/Cytoscape export None LOST
Import Simple neuralImport() Complex multi-method WRONG
Search Multiple specific Simplified to 2 ⚠️ OK if complete
Verb Scoring Full intelligence Partial ⚠️ CHECK
Synapses External connectors Unknown ⚠️ CHECK
Conduits Brainy-to-Brainy Partial ⚠️ CHECK

🔧 WHAT WE NEED TO FIX IMMEDIATELY:

Priority 1 (CRITICAL):

  1. Replace ALL MongoDB operators with Brainy operators

    • This is a legal requirement!
    • greaterThan not $gt
  2. Restore Neural API completely

    • brain.neural must have all methods
    • Visualization MUST work for external tools
  3. Fix neuralImport to be simple

    • ONE method that auto-detects
    • Not multiple complex methods

Priority 2 (IMPORTANT):

  1. Restore clustering APIs

    • For visualization tools
    • For analysis
  2. Verify Triple Intelligence is complete

    • find() must handle everything
    • All operators must work
  3. Check augmentation system

    • Synapses (external)
    • Conduits (internal)

🎯 RECOVERY PLAN:

  • Find all $gt, $lt, $in, $regex references
  • Replace with greaterThan, lessThan, oneOf, matches
  • Update all documentation

Step 2: Restore Neural API

  • Ensure brain.neural is properly exposed
  • All methods available: similar, clusters, hierarchy, etc.
  • Visualization must return proper format

Step 3: Fix Import

  • Single neuralImport() method
  • Auto-detection of format
  • Simple options

Step 4: Verify Nothing Lost

  • Compare method-by-method with backup
  • Test all features
  • Update documentation

💡 LESSONS LEARNED:

  1. Don't oversimplify - We lost important features
  2. Check legal requirements - MongoDB operators were avoided for a reason
  3. Preserve all features - Even if reorganizing
  4. Test against backup - Always compare functionality
  5. Document changes - Track what and why

🚀 NEXT ACTIONS:

  1. STOP all other work
  2. Fix operators IMMEDIATELY (legal risk)
  3. Restore neural API completely
  4. Test everything works
  5. Document the final API properly