fix: feature-detect setConnectionsCodec before wiring the connections codec

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.
This commit is contained in:
David Snelling 2026-06-10 10:50:46 -07:00
parent cfb051cc5a
commit 747ab974f3

View file

@ -9469,6 +9469,11 @@ export class Brainy<T = any> implements BrainyInterface<T> {
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) {