diff --git a/src/hnsw/hnswIndex.ts b/src/hnsw/hnswIndex.ts index ff074daf..10cb69f8 100644 --- a/src/hnsw/hnswIndex.ts +++ b/src/hnsw/hnswIndex.ts @@ -17,7 +17,7 @@ import { getGlobalCache, UnifiedCache } from '../utils/unifiedCache.js' import { prodLog } from '../utils/logger.js' import { quantizeSQ8, distanceSQ8 } from '../utils/vectorQuantization.js' import type { SQ8QuantizedVector } from '../utils/vectorQuantization.js' -import type { HnswProvider } from '../plugin.js' +import type { VectorIndexProvider } from '../plugin.js' import { MmapVectorBackend } from './mmapVectorBackend.js' import { ConnectionsCodec, compressedConnectionsKey } from './connectionsCodec.js' @@ -30,11 +30,11 @@ const DEFAULT_CONFIG: HNSWConfig = { } /** - * Implements {@link HnswProvider}: the vector-index surface Brainy calls on - * whatever the `'hnsw'` factory returns (its own `HNSWIndex`, or Cortex's - * native engine). + * Implements {@link VectorIndexProvider}: the vector-index surface Brainy calls + * on whatever the `'vector'` factory returns (its own `HNSWIndex`, or a native + * acceleration provider). */ -export class HNSWIndex implements HnswProvider { +export class HNSWIndex implements VectorIndexProvider { private nouns: Map = new Map() private entryPointId: string | null = null private maxLevel = 0 diff --git a/src/plugin.ts b/src/plugin.ts index 4145daf3..4efaed8e 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -192,15 +192,20 @@ export interface GraphIndexProvider { } /** - * The object returned by the `'hnsw'` provider factory — a drop-in for - * `HNSWIndex`. Brainy calls this surface via `this.index.*` plus the - * transactional add/remove operations. `enableCOW`, `getItem`, and - * `setPersistMode` are intentionally absent: Brainy guards each with - * feature-detection (`typeof x === 'function'`), so they are optional and not - * part of the required contract (Brainy's own `HNSWIndex` omits - * `setPersistMode`, for instance). + * The object returned by the `'vector'` provider factory — Brainy's vector + * index contract. Implementations include Brainy's own JS HNSW index and any + * native acceleration provider (e.g. cortex's Adaptive DiskANN). + * + * Brainy calls this surface via `this.index.*` plus the transactional add/remove + * operations. `enableCOW`, `getItem`, and `setPersistMode` are intentionally + * absent: Brainy guards each with feature-detection (`typeof x === 'function'`), + * so they are optional and not part of the required contract (Brainy's own JS + * HNSW index omits `setPersistMode`, for instance). + * + * **Provider key:** registered under `'vector'`. The legacy `'hnsw'` key is + * accepted as a compat shim in 8.0 and retired in a future release. */ -export interface HnswProvider { +export interface VectorIndexProvider { addItem(item: VectorDocument): Promise removeItem(id: string): Promise search( @@ -217,29 +222,22 @@ export interface HnswProvider { } /** - * The `'diskann'` provider — a billion-scale alternative to HNSW backed - * by cortex's pure-Rust Vamana + Product Quantization implementation - * (see ADR-002 in the cortex repo). - * - * Structurally a drop-in for [`HnswProvider`]: brainy calls the same - * `addItem` / `search` / `rebuild` surface and never needs to know - * which index is underneath. The differences are operational: - * - * - **Memory footprint**: ~16 GB RAM at 1 B vectors (PQ codes only). - * HNSW would need ~1.5 TB to keep the full vectors resident. - * - **Build model**: build-once, query-many. Dynamic insertions buffer - * to an in-memory delta brute-forced alongside the main index; - * `rebuild()` folds them in. - * - **Storage**: requires a local filesystem path (NVMe SSD for the - * published latency numbers). Cloud-storage adapters continue using - * HNSW. - * - * Engagement is automatic when the cortex provider is registered, the - * storage adapter exposes `getBinaryBlobPath`, and the metadata index - * has a stable `idMapper`. Users force the legacy index via - * `config.index.type = 'hnsw'`. + * @deprecated Renamed to {@link VectorIndexProvider} in Brainy 8.0. The + * interface shape is byte-for-byte identical; only the name changed because + * "vector index" describes the role, while "HNSW" was the name of one + * specific implementation. This alias is provided as a compatibility shim + * for code mid-migration; new code should import `VectorIndexProvider`. */ -export type DiskAnnProvider = HnswProvider +export type HnswProvider = VectorIndexProvider + +/** + * @deprecated The `'diskann'` provider key has been folded into `'vector'` in + * Brainy 8.0. The vector index contract is implementation-neutral: any provider + * registered under `'vector'` may be HNSW, DiskANN, or a future algorithm. The + * type alias is preserved so existing imports compile while consumers migrate + * to `VectorIndexProvider`. + */ +export type DiskAnnProvider = VectorIndexProvider /** * The `'entityIdMapper'` provider — a drop-in for `EntityIdMapper`. Injected