Skip to content

bug: SonaEngine.forceLearn() always returns 'insufficient trajectories' after completed trajectories #258

@PogeystickJoe

Description

@PogeystickJoe

Summary

SonaEngine.forceLearn() in ruvector 0.2.12 always returns "skipped: insufficient trajectories" even after completing multiple trajectories with beginTrajectory → addStep (x3) → endTrajectory in the same session. The trajectories complete without error, but forceLearn() reports 0 trajectories available.

Environment

  • ruvector: 0.2.12
  • Node.js: 22.17.1
  • Platform: Windows (MINGW64), win32-x64

Steps to Reproduce

const { SonaEngine } = require('ruvector');
const sona = new SonaEngine(384);

// Create proper 384-dim vectors
const mkEmb = (seed) => new Array(384).fill(0).map((_, i) => Math.sin(i * 0.1 + seed) * 0.1);
const attn = new Array(384).fill(0).map(() => Math.random() * 0.05);

// Complete 5 distinct trajectories
for (let t = 0; t < 5; t++) {
  const tid = sona.beginTrajectory(mkEmb(t));     // Returns 0, 1, 2, 3, 4
  sona.addStep(tid, mkEmb(t+0.1), attn, 0.85);   // No error
  sona.addStep(tid, mkEmb(t+0.2), attn, 0.70);   // No error
  sona.addStep(tid, mkEmb(t+0.3), attn, 0.60);   // No error
  sona.endTrajectory(tid, 0.75 + t * 0.02);       // No error
}

const patterns = sona.forceLearn();
console.log(patterns);
// Output: "Forced learning: 0 trajectories -> 0 patterns, status: skipped: insufficient trajectories"

Expected Behavior

After 5 completed trajectories with 3 steps each (15 total steps), forceLearn() should process them and extract patterns. Or at minimum, report 5 trajectories instead of 0 trajectories.

Actual Behavior

  • beginTrajectory() returns incrementing IDs (0-4) — suggests they're being created
  • addStep() and endTrajectory() return without error
  • forceLearn() reports 0 trajectories as if none were stored
  • The message says "insufficient trajectories" but doesn't specify the minimum threshold

Questions

  1. Is there a minimum number of trajectories required? If so, what is it?
  2. Does endTrajectory() actually persist the trajectory, or does it get dropped?
  3. Is there a required minimum diversity threshold between trajectory embeddings?
  4. Does the SONA coordinator buffer need to be flushed before forceLearn()?

Additional Context

The SONA getStats() method (see #257) shows trajectories_buffered: 0 after all 5 trajectories complete, which suggests trajectories may be getting dropped during endTrajectory() rather than buffered for learning.

The buffer_success_rate: 1.0 is also suspicious — if 0 trajectories were buffered but success rate is 100%, it may indicate the buffer was never attempted rather than trajectories failing.

Workaround

Currently using RuVector MCP hooks_batch_learn and hooks_trajectory_begin/step/end as the learning pathway instead of the native SONA engine. The MCP hooks do process and store learning data (confirmed 36 updates via batch_learn), but SONA pattern extraction specifically does not work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions