diff --git a/v3/@claude-flow/cli/__tests__/embeddings-search-zero-threshold.test.ts b/v3/@claude-flow/cli/__tests__/embeddings-search-zero-threshold.test.ts index a781f958e3..d9093b71bf 100644 --- a/v3/@claude-flow/cli/__tests__/embeddings-search-zero-threshold.test.ts +++ b/v3/@claude-flow/cli/__tests__/embeddings-search-zero-threshold.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { mkdtempSync, rmSync } from 'node:fs'; +import { mkdtempSync, readFileSync, rmSync } from 'node:fs'; import { join } from 'node:path'; import { tmpdir } from 'node:os'; @@ -18,6 +18,7 @@ vi.mock('../src/memory/memory-initializer.js', () => ({ const { embeddingsTools } = await import('../src/mcp-tools/embeddings-tools.js'); const init = embeddingsTools.find(tool => tool.name === 'embeddings_init')!; const search = embeddingsTools.find(tool => tool.name === 'embeddings_search')!; +const neural = embeddingsTools.find(tool => tool.name === 'embeddings_neural')!; let originalCwd: string; let workdir: string; @@ -48,3 +49,31 @@ describe('embeddings_search threshold', () => { expect(result.metadata.threshold).toBe(0.5); }); }); + +describe('embeddings_neural init', () => { + it('honours an explicit 0 for decayRate and driftThreshold', async () => { + const result = await neural.handler({ action: 'init', decayRate: 0, driftThreshold: 0 }) as any; + expect(result.success).toBe(true); + expect(result.neural.decayRate).toBe(0); + expect(result.neural.driftThreshold).toBe(0); + }); + + it('persists the 0 values to the embeddings config', async () => { + await neural.handler({ action: 'init', decayRate: 0, driftThreshold: 0 }); + const saved = JSON.parse(readFileSync(join(workdir, '.claude-flow', 'embeddings.json'), 'utf-8')); + expect(saved.neural.decayRate).toBe(0); + expect(saved.neural.driftThreshold).toBe(0); + }); + + it('still defaults to 0.3 and 0.01 when the values are omitted', async () => { + const result = await neural.handler({ action: 'init' }) as any; + expect(result.neural.driftThreshold).toBe(0.3); + expect(result.neural.decayRate).toBe(0.01); + }); + + it('keeps non-zero values as given', async () => { + const result = await neural.handler({ action: 'init', decayRate: 0.05, driftThreshold: 0.7 }) as any; + expect(result.neural.decayRate).toBe(0.05); + expect(result.neural.driftThreshold).toBe(0.7); + }); +}); diff --git a/v3/@claude-flow/cli/src/mcp-tools/embeddings-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/embeddings-tools.ts index 18dc0b590b..9985f22c54 100644 --- a/v3/@claude-flow/cli/src/mcp-tools/embeddings-tools.ts +++ b/v3/@claude-flow/cli/src/mcp-tools/embeddings-tools.ts @@ -636,8 +636,9 @@ export const embeddingsTools: MCPTool[] = [ case 'init': config.neural = { enabled: true, - driftThreshold: (input.driftThreshold as number) || 0.3, - decayRate: (input.decayRate as number) || 0.01, + // `??`, not `||`: an explicit 0 is a valid value for both. + driftThreshold: (input.driftThreshold as number) ?? 0.3, + decayRate: (input.decayRate as number) ?? 0.01, ruvector: { enabled: true, sona: true,