refactor(8.0): rename HNSWIndex class → JsHnswVectorIndex (scaffold step 3)

Step 3 of the brainy 8.0 rename scaffolding. The class name now matches
its role: the JS HNSW implementation of the VectorIndexProvider contract.
Per planning § 2.3: this is NOT cosmetic — leaving HNSWIndex when the
public contract is VectorIndexProvider creates a confusing read at the
implementation layer.

CHANGES

Repo-wide mechanical rename: HNSWIndex → JsHnswVectorIndex across 52
references in src/ + 5 references in tests/ via sed. Class declaration,
imports, JSDoc, comments, and identifiers all updated.

src/index.ts
- Primary public export: JsHnswVectorIndex (the new name).
- Backwards-compat alias: `export const HNSWIndex = JsHnswVectorIndex`
  with @deprecated note. Removed in the final 8.0 cleanup commit.

NO-OP scope

No behavioural change. The class is exactly the same; only the name
moved. Tests + build green.

VERIFICATION

- npx tsc --noEmit: clean
- npm test: 1468 / 1468 unit
This commit is contained in:
David Snelling 2026-06-09 13:07:56 -07:00
parent 8f87b35614
commit f39d420cb4
11 changed files with 80 additions and 70 deletions

View file

@ -6,8 +6,8 @@
*/
import { v4 as uuidv4 } from './universal/uuid.js'
import { HNSWIndex } from './hnsw/hnswIndex.js'
// TypeAwareHNSWIndex removed from default path — single unified HNSWIndex is faster
import { JsHnswVectorIndex } from './hnsw/hnswIndex.js'
// TypeAwareHNSWIndex removed from default path — single unified JsHnswVectorIndex is faster
// for the 99% of queries that don't filter by type (avoids searching 42 separate graphs)
import { createStorage } from './storage/storageFactory.js'
import { BaseStorage } from './storage/baseStorage.js'
@ -156,7 +156,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
private static instances: Brainy[] = []
// Core components
private index!: HNSWIndex
private index!: JsHnswVectorIndex
private storage!: BaseStorage
private metadataIndex!: MetadataIndexManager
private graphIndex!: GraphAdjacencyIndex
@ -606,8 +606,8 @@ export class Brainy<T = any> implements BrainyInterface<T> {
// Wire the mmap-vector backend (2.4.0 #2). When the vectorStore:mmap
// provider is registered AND the storage adapter resolves a real local
// path via getBinaryBlobPath(), open the mmap file there and inject the
// backend into HNSWIndex. Cloud adapters return null and skip silently;
// HNSWIndex's behaviour is then identical to pre-2.4.0 (per-entity reads
// backend into JsHnswVectorIndex. Cloud adapters return null and skip silently;
// JsHnswVectorIndex's behaviour is then identical to pre-2.4.0 (per-entity reads
// from canonical storage). Failures are non-fatal — the index still
// works, just without the zero-copy fast path.
await this.wireMmapVectorBackend()
@ -8324,7 +8324,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
* @param candidateIds Optional pre-resolved metadata filter IDs for metadata-first search.
* When provided, HNSW search is restricted to these candidates:
* - NativeHNSWWrapper: uses native searchWithCandidates (Rust bitmap filtering)
* - JS HNSWIndex: converts to filter function with O(1) Set lookups
* - JS JsHnswVectorIndex: converts to filter function with O(1) Set lookups
*/
private async executeVectorSearch(params: FindParams<T>, candidateIds?: string[]): Promise<Result<T>[]> {
const vector = params.vector || (await this.embed(params.query!))
@ -9070,7 +9070,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
* - Cloud storage (GCS/S3/R2/Azure): 'deferred' for 30-50x faster adds
* - Local storage (FileSystem/Memory/OPFS): 'immediate' (already fast)
*/
private setupIndex(): HNSWIndex {
private setupIndex(): JsHnswVectorIndex {
const indexConfig = {
...this.config.index,
distanceFunction: this.distance,
@ -9085,7 +9085,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
const persistMode = this.resolveHNSWPersistMode()
return new HNSWIndex(indexConfig as any, this.distance, {
return new JsHnswVectorIndex(indexConfig as any, this.distance, {
storage: this.storage,
useParallelization: true,
persistMode
@ -9106,11 +9106,11 @@ export class Brainy<T = any> implements BrainyInterface<T> {
* - The metadata index has a stable `idMapper`.
* - `config.index.type !== 'hnsw'` (no explicit opt-out).
* 3. `'hnsw'` provider if registered (cortex's native HNSW).
* 4. Brainy's built-in TS HNSWIndex (the always-available fallback).
* 4. Brainy's built-in TS JsHnswVectorIndex (the always-available fallback).
*
* See ADR-002 in the cortex repo for the engagement rationale.
*/
private createIndex(): HNSWIndex {
private createIndex(): JsHnswVectorIndex {
const persistMode = this.resolveHNSWPersistMode()
const indexType = (this.config.index as any)?.type as 'hnsw' | 'diskann' | undefined
@ -9170,7 +9170,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
private instantiateDiskAnn(
factory: (config: any, distance: DistanceFunction, options: any) => any,
persistMode: 'immediate' | 'deferred'
): HNSWIndex {
): JsHnswVectorIndex {
const storageWithBlob = this.storage as unknown as {
getBinaryBlobPath?: (key: string) => string | null
}
@ -9377,7 +9377,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
}
/**
* @description Open the mmap-vector backend and inject it into HNSWIndex.
* @description Open the mmap-vector backend and inject it into JsHnswVectorIndex.
* Called once during init after plugin activation, metadataIndex init, and
* graphIndex setup so the idMapper is available and providers are wired.
*
@ -9397,7 +9397,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
* (or a re-open) sees the correct value.
*
* Failures here are non-fatal: a debug-level log records the reason, and
* HNSWIndex continues without the mmap fast path.
* JsHnswVectorIndex continues without the mmap fast path.
*/
private async wireMmapVectorBackend(): Promise<void> {
const provider = this.pluginRegistry.getProvider<VectorStoreMmapProvider>('vectorStore:mmap')