Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(memory): schema vector_indexes dim 768β†’384 + CI guard (#1947, #1942, #1952) (#1956)

rUv4abef4b83f33
diff --git a/.github/workflows/v3-ci.yml b/.github/workflows/v3-ci.yml
index e33d2549f1..5e1dfd338e 100644
--- a/.github/workflows/v3-ci.yml
+++ b/.github/workflows/v3-ci.yml
@@ -558,6 +558,28 @@ jobs:
PATH= "$BASH" "$sh" modify-bash </dev/null || { echo "::error::$sh did not exit 0 with no CLI on PATH"; exit 1; }
done
+ vector-dim-audit:
+ # Regression guard for #1947 / #1942 / #1952 β€” `vector_indexes` rows for
+ # the `default` and `patterns` namespaces must use `dimensions = 384` to
+ # match the default ONNX embedding model (Xenova/all-MiniLM-L6-v2). A
+ # mismatched dim (the historical 768) is silent: HNSW rejects every
+ # `memory_store --vector` insert and `memory_search` always returns 0.
+ name: Vector-index dimension audit (#1947)
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: '22'
+
+ - name: Run vector-dim audit
+ shell: bash
+ run: node scripts/audit-vector-dim.mjs
+
witness-verify:
# Cryptographic regression guard: runs `ruflo verify --manifest` against
# the local build to confirm every documented fix in verification.md.json
@@ -584,7 +606,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
- needs: [smoke-install-no-bsqlite, plugin-hooks-smoke, mcp-protocol-smoke, memory-import-smoke, tool-descriptions-audit, mcp-roundtrip-smoke, plugin-package-audit, hook-command-audit]
+ needs: [smoke-install-no-bsqlite, plugin-hooks-smoke, mcp-protocol-smoke, memory-import-smoke, tool-descriptions-audit, mcp-roundtrip-smoke, plugin-package-audit, hook-command-audit, vector-dim-audit]
steps:
- name: Checkout code
diff --git a/scripts/audit-vector-dim.mjs b/scripts/audit-vector-dim.mjs
new file mode 100755
index 0000000000..5d51dd7f06
--- /dev/null
+++ b/scripts/audit-vector-dim.mjs
@@ -0,0 +1,132 @@
+#!/usr/bin/env node
+/**
+ * Vector-index dimension audit (regression guard for #1947 / #1942 / #1952).
+ *
+ * Issue #1947 root cause: the bundled SQL schema initialises the `default` and
+ * `patterns` rows in `vector_indexes` with `dimensions = 768`, but the
+ * default ONNX embedding model (`Xenova/all-MiniLM-L6-v2`) produces 384-dim
+ * vectors. HNSW rejects every insert with the mismatched dim, so
+ * `memory_store --vector` succeeds but `memory_search` always returns 0 hits.
+ *
+ * The fix is purely a number change in 11 `.swarm/schema.sql` files plus the
+ * inline schema string in `v3/@claude-flow/cli/src/memory/memory-initializer.ts`.
+ * This script blocks the next regression: every `INSERT ... INTO
+ * vector_indexes (id, name, dimensions) VALUES ('default'|'patterns', ..., N)`
+ * must have `N === EXPECTED_DIM` (currently 384 β€” track the default model).
+ *
+ * Anything caught here would silently break every "memory_search returns 0"
+ * scenario in the bug cluster: #1947, #1942, #1952 (Windows), and the
+ * downstream bridge-import issues that imported 384-dim vectors into 768-dim
+ * indexes (#1941, #1940).
+ *
+ * Usage:
+ * node scripts/audit-vector-dim.mjs # audit, exit 1 on mismatch
+ * node scripts/audit-vector-dim.mjs --json # machine-readable report
+ */
+
+import { readdirSync, readFileSync, statSync } from 'node:fs';
+import { join, relative } from 'node:path';
+
+const REPO_ROOT = process.cwd();
+const EXPECTED_DIM = 384; // matches Xenova/all-MiniLM-L6-v2 default
+const JSON_OUT = process.argv.includes('--json');
+
+// Patterns that catch both the SQL files and the inline TS-string schema.
+// We match a fairly loose form so the audit also catches reformatted
+// variants (e.g. with extra whitespace, comments between fields).
+const ROW_RE = /\(\s*'(default|patterns)'\s*,\s*'(?:default|patterns)'\s*,\s*(\d+)\s*\)/g;
+
+// Roots to scan. Skip build outputs / vendor dirs.
+const ROOTS = ['v3', 'ruflo'];
+const SKIP_DIRS = new Set([
+ 'node_modules',
+ 'dist',
+ 'build',
+ '.git',
+ 'target',
+ 'coverage',
+ '.swarm-data',
+]);
+const EXT_OK = new Set(['.sql', '.ts', '.js', '.mjs', '.cjs']);
+
+function walk(dir, out = []) {
+ let entries;
+ try {
+ entries = readdirSync(dir, { withFileTypes: true });
+ } catch {
+ return out;
+ }
+ for (const e of entries) {
+ if (e.name.startsWith('.') && e.name !== '.swarm') continue;
+ if (SKIP_DIRS.has(e.name)) continue;
+ const p = join(dir, e.name);
+ let s;
+ try {
+ s = statSync(p);
+ } catch {
+ continue;
+ }
+ if (s.isDirectory()) {
+ walk(p, out);
+ } else if (s.isFile()) {
+ const dot = e.name.lastIndexOf('.');
+ const ext = dot >= 0 ? e.name.slice(dot) : '';
+ if (EXT_OK.has(ext)) out.push(p);
+ }
+ }
+ return out;
+}
+
+const offenders = [];
+const ok = [];
+
+for (const root of ROOTS) {
+ const start = join(REPO_ROOT, root);
+ try {
+ statSync(start);
+ } catch {
+ continue;
+ }
+ for (const file of walk(start)) {
+ let src;
+ try {
+ src = readFileSync(file, 'utf8');
+ } catch {
+ continue;
+ }
+ let m;
+ ROW_RE.lastIndex = 0;
+ while ((m = ROW_RE.exec(src)) !== null) {
+ const [, name, dimStr] = m;
+ const dim = Number(dimStr);
+ const rel = relative(REPO_ROOT, file);
+ // Locate the line number for a useful error.
+ const lineNo = src.slice(0, m.index).split('\n').length;
+ if (dim !== EXPECTED_DIM) {
+ offenders.push({ file: rel, line: lineNo, name, dim });
+ } else {
+ ok.push({ file: rel, line: lineNo, name, dim });
+ }
+ }
+ }
+}
+
+if (JSON_OUT) {
+ process.stdout.write(JSON.stringify({ expectedDim: EXPECTED_DIM, offenders, okCount: ok.length }, null, 2) + '\n');
+ process.exit(offenders.length === 0 ? 0 : 1);
+}
+
+console.log(`vector-index dimension audit β€” expecting dimensions=${EXPECTED_DIM} (Xenova/all-MiniLM-L6-v2)`);
+console.log(` scanned ${ROOTS.join(', ')}, found ${ok.length + offenders.length} matching INSERT row(s)`);
+
+if (offenders.length === 0) {
+ console.log(` βœ“ all rows set dimensions=${EXPECTED_DIM}`);
+ process.exit(0);
+}
+
+console.error(`\n βœ— ${offenders.length} row(s) with wrong dim β€” #1947 regression:`);
+for (const o of offenders) {
+ console.error(` ${o.file}:${o.line} '${o.name}' row has dim=${o.dim}, expected ${EXPECTED_DIM}`);
+}
+console.error('\n Fix: change the dim literal to ' + EXPECTED_DIM + ', or update EXPECTED_DIM in this script if the default embedding model has changed.');
+process.exit(1);
diff --git a/v3/@claude-flow/cli/src/memory/memory-initializer.ts b/v3/@claude-flow/cli/src/memory/memory-initializer.ts
index 09c8401d65..9a8ca2e2d6 100644
--- a/v3/@claude-flow/cli/src/memory/memory-initializer.ts
+++ b/v3/@claude-flow/cli/src/memory/memory-initializer.ts
@@ -985,10 +985,13 @@ INSERT OR REPLACE INTO metadata (key, value) VALUES
('temporal_decay', 'enabled'),
('hnsw_indexing', 'enabled');
--- Create default vector index configuration
+-- Create default vector index configuration. Dimension matches the default
+-- ONNX embedding model (Xenova/all-MiniLM-L6-v2, 384-dim); HNSW rejects
+-- inserts whose dim does not match this row, so a 768 here breaks every
+-- memory_store --vector and memory_search on a fresh install (#1947).
INSERT OR IGNORE INTO vector_indexes (id, name, dimensions) VALUES
- ('default', 'default', 768),
- ('patterns', 'patterns', 768);
+ ('default', 'default', 384),
+ ('patterns', 'patterns', 384);
`;
}