Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions v3/@claude-flow/memory/src/controller-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,34 @@ describe('ControllerRegistry', () => {
const report = await registry.healthCheck();
expect(report.initTimeMs).toBeGreaterThan(0);
});

it('should pass vectorBackend config to AgentDB and expose via getController', async () => {
const mockVectorBackend = { type: 'ruvector', search: vi.fn() };

// Mock agentdb module to return instance with vectorBackend property
vi.doMock('agentdb', () => ({
AgentDB: class MockAgentDB {
vectorBackend = mockVectorBackend;
vectorBackendName = 'ruvector';
vectorDimension = 384;
initialized = false;
async initialize() { this.initialized = true; }
async close() {}
get database() { return null; }
getController(name: string) {
if (['reflexion', 'memory', 'skills', 'causal', 'causalGraph'].includes(name)) return null;
throw new Error(`Unknown controller: ${name}`);
}
},
}));

const reg = new ControllerRegistry();
await reg.initialize({ backend: mockBackend, vectorBackend: 'rvf', dimension: 384 });

const vb = reg.get('vectorBackend');
expect(vb).not.toBeNull();
expect(vb).toBe(mockVectorBackend);
});
});

// ----- Level-Based Ordering -----
Expand Down
18 changes: 17 additions & 1 deletion v3/@claude-flow/memory/src/controller-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export interface RuntimeConfig {
/** Vector dimension (default: 384 for MiniLM) */
dimension?: number;

/** Vector backend to use (default: 'auto') */
vectorBackend?: 'auto' | 'rvf' | 'hnswlib';

/** Embedding generator function */
embeddingGenerator?: EmbeddingGenerator;

Expand Down Expand Up @@ -480,7 +483,11 @@ export class ControllerRegistry extends EventEmitter {
return;
}

this.agentdb = new AgentDBClass({ dbPath });
this.agentdb = new AgentDBClass({
dbPath,
vectorBackend: config.vectorBackend ?? 'auto',
vectorDimension: config.dimension ?? 384,
});

// Suppress agentdb's noisy info-level output during init
// using stderr redirect instead of monkey-patching console.log
Expand Down Expand Up @@ -910,6 +917,15 @@ export class ControllerRegistry extends EventEmitter {
// These are accessed via AgentDB internal state, not direct construction
if (!this.agentdb) return null;
try {
// vectorBackend is exposed as a direct property on AgentDB instance.
// Note: agentdb.getController() does not support 'vectorBackend'
// (only reflexion/skills/causalGraph). Accessing via direct property
// is intentional — if AgentDB changes internals, this should be
// replaced by a proper getController('vectorBackend') upstream.
// TODO: request getController('vectorBackend') support in agentdb.
if (name === 'vectorBackend' && this.agentdb.vectorBackend) {
return this.agentdb.vectorBackend;
}
if (typeof this.agentdb.getController === 'function') {
return this.agentdb.getController(name) ?? null;
}
Expand Down