From 747ab974f31890ffca5822739be2c57161317aea Mon Sep 17 00:00:00 2001 From: David Snelling Date: Wed, 10 Jun 2026 10:50:46 -0700 Subject: [PATCH] fix: feature-detect setConnectionsCodec before wiring the connections codec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wireConnectionsCodec() called this.index.setConnectionsCodec(codec) unconditionally. Vector-index providers that don't keep per-node connection lists (single-file graph formats) have no such hook — the unconditional call forced them to carry a no-op shim just to survive brain.init(). Guard with a typeof check and skip silently: the delta-varint codec only applies to the JS HNSW connection layout, so providers without the hook lose nothing. Providers can now drop their shims. --- src/brainy.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/brainy.ts b/src/brainy.ts index e04df2c4..f7a102b7 100644 --- a/src/brainy.ts +++ b/src/brainy.ts @@ -9469,6 +9469,11 @@ export class Brainy implements BrainyInterface { const idMapper = this.metadataIndex.getIdMapper?.() if (!idMapper) return + // Feature-detect: vector-index providers without per-node connection + // lists (e.g. single-file graph formats) don't expose this hook. Skip + // silently — the codec only applies to the JS HNSW connection layout. + if (typeof this.index.setConnectionsCodec !== 'function') return + const codec = new ConnectionsCodec(provider, idMapper) this.index.setConnectionsCodec(codec) if (!this.config.silent) {