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

@ -11,7 +11,7 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { v4 as uuidv4 } from 'uuid'
import { HNSWIndex } from '../../../src/hnsw/hnswIndex.js'
import { JsHnswVectorIndex } from '../../../src/hnsw/hnswIndex.js'
import { euclideanDistance } from '../../../src/utils/index.js'
import { MemoryStorage } from '../../../src/storage/adapters/memoryStorage.js'
@ -43,12 +43,12 @@ describe('Lazy Vector Loading (B2)', () => {
// 1. LAZY MODE: VECTOR EVICTION
// =================================================================
describe('vector eviction in lazy mode', () => {
let index: HNSWIndex
let index: JsHnswVectorIndex
let storage: MemoryStorage
beforeEach(async () => {
storage = new MemoryStorage()
index = new HNSWIndex(
index = new JsHnswVectorIndex(
{
M: 8,
efConstruction: 100,
@ -116,7 +116,7 @@ describe('Lazy Vector Loading (B2)', () => {
describe('memory mode retains vectors (default)', () => {
it('should keep vectors in memory by default', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{ M: 4, efConstruction: 50, efSearch: 20 },
euclideanDistance,
{ useParallelization: false, storage }
@ -135,7 +135,7 @@ describe('Lazy Vector Loading (B2)', () => {
it('should work without storage adapter in memory mode', async () => {
// No storage adapter provided
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{ M: 4, efConstruction: 50, efSearch: 20 },
euclideanDistance,
{ useParallelization: false }
@ -157,7 +157,7 @@ describe('Lazy Vector Loading (B2)', () => {
describe('lazy mode without storage', () => {
it('should not evict vectors when no storage adapter is configured', async () => {
// vectorStorage: 'lazy' but no storage — vectors should stay in memory
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{
M: 4,
efConstruction: 50,
@ -185,7 +185,7 @@ describe('Lazy Vector Loading (B2)', () => {
describe('lazy mode with quantization', () => {
it('should use SQ8 for traversal and load full vectors for rerank', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{
M: 8,
efConstruction: 100,
@ -221,7 +221,7 @@ describe('Lazy Vector Loading (B2)', () => {
it('should return results sorted by exact distance after rerank', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{
M: 8,
efConstruction: 100,
@ -257,7 +257,7 @@ describe('Lazy Vector Loading (B2)', () => {
describe('multiple searches in lazy mode', () => {
it('should handle repeated searches correctly', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{
M: 8,
efConstruction: 100,

View file

@ -21,7 +21,7 @@ import {
serializeSQ8,
deserializeSQ8
} from '../../../src/utils/vectorQuantization.js'
import { HNSWIndex } from '../../../src/hnsw/hnswIndex.js'
import { JsHnswVectorIndex } from '../../../src/hnsw/hnswIndex.js'
import { euclideanDistance } from '../../../src/utils/index.js'
import { MemoryStorage } from '../../../src/storage/adapters/memoryStorage.js'
@ -286,14 +286,14 @@ describe('SQ8 Quantization', () => {
// 4. HNSW SEARCH WITH QUANTIZATION
// =================================================================
describe('HNSW search with quantization', () => {
let index: HNSWIndex
let index: JsHnswVectorIndex
let storage: MemoryStorage
const dim = 32 // Small dimension for fast tests
let ids: string[]
beforeEach(async () => {
storage = new MemoryStorage()
index = new HNSWIndex(
index = new JsHnswVectorIndex(
{
M: 8,
efConstruction: 100,
@ -365,7 +365,7 @@ describe('SQ8 Quantization', () => {
describe('two-phase rerank', () => {
it('should accept rerank options in search', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{
M: 8,
efConstruction: 100,
@ -399,7 +399,7 @@ describe('SQ8 Quantization', () => {
it('reranked results should be sorted by exact distance', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{
M: 8,
efConstruction: 100,
@ -432,7 +432,7 @@ describe('SQ8 Quantization', () => {
describe('configuration defaults', () => {
it('should disable quantization by default', async () => {
const storage = new MemoryStorage()
const defaultIndex = new HNSWIndex(
const defaultIndex = new JsHnswVectorIndex(
{ M: 4, efConstruction: 50, efSearch: 20 },
euclideanDistance,
{ useParallelization: false, storage }
@ -456,7 +456,7 @@ describe('SQ8 Quantization', () => {
it('should use default rerankMultiplier of 3', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{
M: 4,
efConstruction: 50,
@ -480,7 +480,7 @@ describe('SQ8 Quantization', () => {
it('should default vectorStorage to memory mode', async () => {
const storage = new MemoryStorage()
const index = new HNSWIndex(
const index = new JsHnswVectorIndex(
{ M: 4, efConstruction: 50, efSearch: 20 },
euclideanDistance,
{ useParallelization: false, storage }