brainy/src
David Snelling 42cd241305 feat: graph link compression — delta-varint connections (2.4.0 #3)
Cortex registers a graph:compression provider exposing `encode`/`decode`
for HNSW connection lists (delta-varint, ~4× smaller edges than the
JSON-UUID-array shape brainy has persisted since the beginning). This
wires the consumer side without changing the saveHNSWData/getHNSWData
adapter signatures.

Architecture:

- NEW ConnectionsCodec (src/hnsw/connectionsCodec.ts) — translates between
  UUID-keyed Map<level, Set<UUID>> and a single compact per-node buffer
  via the provider + stable EntityIdMapper. Custom wire format:
  [count: u8] [[level: u8] [len: u32 LE] [bytes...]]*. One blob per node
  regardless of level count, so the storage I/O is identical to the
  legacy path (one saveHNSWData call) plus a single saveBinaryBlob.

- HNSWIndex changes — a `connectionsCodec: ConnectionsCodec | null` field
  with `setConnectionsCodec()` setter. THREE save sites (deferred flush,
  immediate-mode entity persist, immediate-mode neighbor updates) now go
  through a single `persistNodeConnections(nodeId, noun)` helper: when the
  codec is wired AND the storage adapter exposes saveBinaryBlob, it
  encodes the connections, stores them at `_hnsw_conn/<nodeId>`, and
  records `connections: {}` in saveHNSWData as the marker. Otherwise the
  legacy JSON-array path is taken. TWO load sites use a matching
  `restoreNodeConnections` helper that tries loadBinaryBlob first and
  falls back to the legacy hnswData.connections field on miss / decode
  error. Format convergence is lazy: pre-2.4.0 nodes still load via the
  legacy path, then write the compressed form on next dirty save.

- brainy.ts wireConnectionsCodec — runs alongside wireMmapVectorBackend
  during init. Activates when (a) the graph:compression provider is
  registered and (b) the metadata index exposes its idMapper. Unlike the
  mmap-vector backend, this layer engages on EVERY brainy 7.25.0
  adapter — the blob primitive itself is universal; only the codec
  presence gates activation.

- Provider interface GraphCompressionProvider in plugin.ts — encode +
  decode static signatures. Brainy depends on the interface; cortex's
  registered { encode: encodeConnections, decode: decodeConnections }
  satisfies it structurally.

Tests (1437 total, +4 vs prior tip):

- tests/unit/hnsw/connections-codec.test.ts — 4 unit tests with a JSON
  mock provider: single-level round-trip, empty-Map round-trip (one-byte
  buffer), multi-level fan-out round-trip, and silent-drop of UUIDs the
  decoding idMapper no longer knows. The real cross-language byte
  format is exercised when cortex 2.4.0 wires its delta-varint
  encode/decode in.

This completes the brainy half of the 2.4.0 storage foundation: stable
ids (#23), mmap vectors (#24), graph link compression (#25), and
column-store interchange (#26). Coordinated release as brainy 7.26.0 +
cortex 2.4.0 follows.
2026-05-28 10:37:01 -07:00
..
aggregation fix: deterministic code-point string collation for column store + aggregation 2026-05-26 17:35:18 -07:00
api refactor: remove src/cortex/ directory and fix README claims 2026-02-01 11:07:26 -08:00
cli feat: multi-process safety + read-only inspector mode 2026-05-15 11:25:05 -07:00
config fix: remove dead model config code for true zero-config 2025-12-18 10:31:02 -08:00
critical feat: replace transformers.js with direct ONNX WASM for Bun compatibility 2025-12-17 17:42:37 -08:00
data feat: Phase 3 - Unified Semantic Type Inference (Nouns + Verbs) 2025-10-16 10:59:26 -07:00
distributed feat(v4.0.0): Complete metadata/vector separation architecture with Azure support 2025-10-17 12:29:27 -07:00
embeddings fix: suppress misleading 'Using Q8 WASM' log when Cortex native is active 2026-03-22 14:53:48 -07:00
errors fix: find()/stats() correctness + Cortex compat (BR-FIND-WHERE-ZERO, BR-DEFENSIVE-INTERFACE) 2026-05-15 12:31:28 -07:00
graph feat: export provider contracts for the plugin surface brainy consumes 2026-05-27 14:45:40 -07:00
hnsw feat: graph link compression — delta-varint connections (2.4.0 #3) 2026-05-28 10:37:01 -07:00
import fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
importers refactor: remove augmentation system and semantic type matching 2026-02-01 10:48:56 -08:00
indexes/columnStore feat: column-store JS↔native interchange — raw-blob unify (2.4.0 #4) 2026-05-28 10:24:48 -07:00
integrations refactor: remove augmentation system and semantic type matching 2026-02-01 10:48:56 -08:00
interfaces fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
mcp refactor: remove augmentation system and semantic type matching 2026-02-01 10:48:56 -08:00
migration feat: add migration system with error handling, validation, and enterprise hardening 2026-02-09 16:13:14 -08:00
neural feat: array-unnest groupBy for aggregates + batch-embed entity extraction 2026-05-26 14:20:40 -07:00
patterns 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00
scripts feat: add node: protocol to all Node.js built-in imports for bundler compatibility 2025-09-17 14:20:21 -07:00
storage merge: storage binary-blob primitive across all adapters 2026-05-27 11:54:18 -07:00
streaming feat: Brainy 3.0 - Production-ready Triple Intelligence database 2025-09-11 16:23:32 -07:00
transaction fix: flush all native providers on shutdown to prevent data loss 2026-02-01 16:23:49 -08:00
triple fix: flush all native providers on shutdown to prevent data loss 2026-02-01 16:23:49 -08:00
types feat: exact percentile and distinctCount aggregation ops 2026-05-26 16:18:47 -07:00
universal fix: prevent fs adapter from throwing on import in browser 2025-09-17 16:22:02 -07:00
utils feat: stable EntityIdMapper — rebuild() no longer renumbers UUID→int 2026-05-28 09:45:22 -07:00
versioning fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
vfs fix: set verb.source/target to entity UUID instead of NounType 2026-02-02 09:20:38 -08:00
brainy.ts feat: graph link compression — delta-varint connections (2.4.0 #3) 2026-05-28 10:37:01 -07:00
coreTypes.ts feat(storage): add raw binary-blob primitive to every storage adapter 2026-05-27 11:50:04 -07:00
index.ts feat: add stddev/variance aggregation ops with Welford's online algorithm 2026-02-17 17:04:11 -08:00
internals.ts feat: export resolveEntityField + STANDARD_ENTITY_FIELDS from internals 2026-04-09 16:28:54 -07:00
pipeline.ts refactor: remove augmentation system and semantic type matching 2026-02-01 10:48:56 -08:00
plugin.ts feat: graph link compression — delta-varint connections (2.4.0 #3) 2026-05-28 10:37:01 -07:00
setup.ts fix: exclude __words__ keyword index from corruption detection and getStats() 2026-01-27 15:38:21 -08:00
unified.ts chore: enforce consistent coding style and semicolon removal 2025-09-29 09:50:59 -07:00
worker.ts 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00