From a537b3664bd91937de3fb4c58113e9fd4c08f948 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Thu, 11 Jun 2026 09:17:15 -0700 Subject: [PATCH] fix: feature-detect setVectorBackend before wiring the mmap-vector backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A production deployment on the native plugin reported the mmap-vector wiring failing one step past the 7.31.3 capacity fix: "this.index.setVectorBackend is not a function". Under the native plugin the active vector index is the provider's own class, which manages vector storage internally and exposes no external-backend hook — only Brainy's built-in JS HNSW index consumes one. Feature-detect the hook before doing any work (same pattern as 7.31.4's setConnectionsCodec guard), checked BEFORE opening the mmap file so no stray vector file is created for an index that will never read it. When the hook is absent the skip is logged at info level as expected behavior rather than surfacing as a scary error: the provider's index serves vectors its own way, and per-entity reads remain the designed fallback path. --- src/brainy.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/brainy.ts b/src/brainy.ts index f7a102b7..1c188c96 100644 --- a/src/brainy.ts +++ b/src/brainy.ts @@ -9400,6 +9400,24 @@ export class Brainy implements BrainyInterface { const provider = this.pluginRegistry.getProvider('vectorStore:mmap') if (!provider) return + // Feature-detect: only Brainy's own JS HNSW index consumes an external + // vector backend. A native vector-index provider manages its own vector + // storage and exposes no setVectorBackend hook — skip silently (same + // pattern as the setConnectionsCodec feature-detect). Checked BEFORE + // opening the backend so no mmap file is created that nothing will read. + const indexWithBackend = this.index as unknown as { + setVectorBackend?: (backend: MmapVectorBackend) => void + } + if (typeof indexWithBackend.setVectorBackend !== 'function') { + if (!this.config.silent) { + console.log( + '[brainy] mmap-vector backend not wired (vector index manages its own ' + + 'vector storage; no setVectorBackend hook) — per-entity reads in use' + ) + } + return + } + const storageWithBlob = this.storage as unknown as { getBinaryBlobPath?: (key: string) => string | null }