Files
ruflo/v3/@claude-flow/cli/src/memory/embedding-policy.ts
T
rUv 4b55fb0fc7 De-Lattice the WASM embedder tier + enforceable no-stub mode (3.25.1) (#2582)
* fix(embeddings): de-Lattice the WASM tier (no such package) + enforceable no-stub mode

Two honest corrections after discovering @ruvector/lattice-wasm does not exist
(npm 404; no 'Lattice' embedder package in the ruvector ecosystem):

1. DE-LATTICE the optional WASM embedder tier. Renamed lattice-wasm.ts →
   wasm-embedder.ts; removed the fictional 'Lattice' branding and the 404
   default package. It is now OPT-IN: EMBED_WASM_PKG defaults to EMPTY (with
   RUFLO_EMBED_WASM_PKG / back-compat RUFLO_LATTICE_WASM_PKG to point it at a
   real wasm-bindgen embedder). Unset ⇒ tier is INERT ⇒ embeddings resolve to
   ruvector ONNX exactly as before (verified _realEmbedding:true). Still
   fail-closed + tolerant-probing. This turns dead-misleading code into a real,
   honest, opt-in pluggable primary-tier seam. (The published 3.25.0 release
   notes + gist were also corrected to state the tier is inactive.)

2. ENFORCEABLE 'no more stubs' — embedding-policy.ts: RUFLO_REQUIRE_REAL_EMBEDDINGS
   makes every hash last-resort THROW loudly instead of silently returning a
   semantically-meaningless vector. Guards the three TS embedder sites
   (neural-tools, vector-db, memory-initializer). Off by default (unchanged
   degrade behavior); set it in any env that must never serve pseudo-embeddings.
   Full replacement of the sync/128-dim/native-Rust fallbacks with real vectors
   is a dims-consistency refactor — this fail-or-serve policy is the safe,
   enforceable step.

Additive · backwards-compatible · fail-closed. Build clean; 47 embedding/policy/
router tests green; flywheel-proof + clean-room-replay guards pass.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* chore: untrack runtime proven-config adoption state accidentally swept into the no-stub commit

.claude/proven-config.json + .claude/.proven-config-version are per-install
runtime adoption state (written by the ADR-177 startup adopt/apply), not source —
they were accidentally staged by 'git add -A'. Untrack + gitignore them; revert
the runtime change to the tracked agentdb.rvf.lock. No code change.
2026-07-05 14:09:11 -04:00

33 lines
1.5 KiB
TypeScript

/**
* Embedding policy — "no more stubs" enforcement.
*
* Every embedder in the codebase tries REAL models first (Lattice WASM →
* ruvector ONNX → AgentDB bridge → transformers.js) and only falls back to a
* deterministic HASH embedding when none loads. A hash embedding has no semantic
* meaning — it silently degrades similarity search into noise.
*
* This module makes that failure mode a POLICY choice instead of a silent
* default. With RUFLO_REQUIRE_REAL_EMBEDDINGS truthy, any hash last-resort throws
* loudly ("no stubs") rather than returning a meaningless vector — fail-closed,
* so a broken embedding substrate is a hard error, not corrupt retrieval.
*
* Default (unset): unchanged behavior (warn + degrade), so nothing breaks for
* installs where a real embedder genuinely can't load. Set the flag in any
* environment that must never serve pseudo-embeddings.
*/
export function requireRealEmbeddings(): boolean {
return /^(1|true|yes|on|strict)$/i.test(process.env.RUFLO_REQUIRE_REAL_EMBEDDINGS ?? '');
}
/** Throw the canonical "no stubs" error if strict mode is on; else no-op. */
export function enforceNoStub(where: string): void {
if (requireRealEmbeddings()) {
throw new Error(
`[no-stub] real embeddings required but only a hash fallback was available at ${where}. ` +
`RUFLO_REQUIRE_REAL_EMBEDDINGS is set — install a real embedder ` +
`(ruvector, or @claude-flow/embeddings with "embeddings init --download") ` +
`or unset the flag to allow degraded hash embeddings.`,
);
}
}