verso-db 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +252 -0
  4. package/dist/BinaryHeap.d.ts +25 -0
  5. package/dist/BinaryHeap.d.ts.map +1 -0
  6. package/dist/Collection.d.ts +156 -0
  7. package/dist/Collection.d.ts.map +1 -0
  8. package/dist/HNSWIndex.d.ts +357 -0
  9. package/dist/HNSWIndex.d.ts.map +1 -0
  10. package/dist/MaxBinaryHeap.d.ts +63 -0
  11. package/dist/MaxBinaryHeap.d.ts.map +1 -0
  12. package/dist/Storage.d.ts +54 -0
  13. package/dist/Storage.d.ts.map +1 -0
  14. package/dist/VectorDB.d.ts +44 -0
  15. package/dist/VectorDB.d.ts.map +1 -0
  16. package/dist/backends/DistanceBackend.d.ts +5 -0
  17. package/dist/backends/DistanceBackend.d.ts.map +1 -0
  18. package/dist/backends/JsDistanceBackend.d.ts +37 -0
  19. package/dist/backends/JsDistanceBackend.d.ts.map +1 -0
  20. package/dist/encoding/DeltaEncoder.d.ts +61 -0
  21. package/dist/encoding/DeltaEncoder.d.ts.map +1 -0
  22. package/dist/errors.d.ts +58 -0
  23. package/dist/errors.d.ts.map +1 -0
  24. package/dist/index.d.ts +64 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +3732 -0
  27. package/dist/presets.d.ts +91 -0
  28. package/dist/presets.d.ts.map +1 -0
  29. package/dist/quantization/ScalarQuantizer.d.ts +114 -0
  30. package/dist/quantization/ScalarQuantizer.d.ts.map +1 -0
  31. package/dist/storage/BatchWriter.d.ts +104 -0
  32. package/dist/storage/BatchWriter.d.ts.map +1 -0
  33. package/dist/storage/BunStorageBackend.d.ts +58 -0
  34. package/dist/storage/BunStorageBackend.d.ts.map +1 -0
  35. package/dist/storage/MemoryBackend.d.ts +44 -0
  36. package/dist/storage/MemoryBackend.d.ts.map +1 -0
  37. package/dist/storage/OPFSBackend.d.ts +59 -0
  38. package/dist/storage/OPFSBackend.d.ts.map +1 -0
  39. package/dist/storage/StorageBackend.d.ts +66 -0
  40. package/dist/storage/StorageBackend.d.ts.map +1 -0
  41. package/dist/storage/WriteAheadLog.d.ts +111 -0
  42. package/dist/storage/WriteAheadLog.d.ts.map +1 -0
  43. package/dist/storage/createStorageBackend.d.ts +40 -0
  44. package/dist/storage/createStorageBackend.d.ts.map +1 -0
  45. package/dist/storage/index.d.ts +30 -0
  46. package/dist/storage/index.d.ts.map +1 -0
  47. package/package.json +98 -0
  48. package/src/BinaryHeap.ts +131 -0
  49. package/src/Collection.ts +695 -0
  50. package/src/HNSWIndex.ts +1839 -0
  51. package/src/MaxBinaryHeap.ts +175 -0
  52. package/src/Storage.ts +435 -0
  53. package/src/VectorDB.ts +109 -0
  54. package/src/backends/DistanceBackend.ts +17 -0
  55. package/src/backends/JsDistanceBackend.ts +227 -0
  56. package/src/encoding/DeltaEncoder.ts +217 -0
  57. package/src/errors.ts +110 -0
  58. package/src/index.ts +138 -0
  59. package/src/presets.ts +229 -0
  60. package/src/quantization/ScalarQuantizer.ts +383 -0
  61. package/src/storage/BatchWriter.ts +336 -0
  62. package/src/storage/BunStorageBackend.ts +161 -0
  63. package/src/storage/MemoryBackend.ts +120 -0
  64. package/src/storage/OPFSBackend.ts +250 -0
  65. package/src/storage/StorageBackend.ts +74 -0
  66. package/src/storage/WriteAheadLog.ts +326 -0
  67. package/src/storage/createStorageBackend.ts +137 -0
  68. package/src/storage/index.ts +53 -0
@@ -0,0 +1,357 @@
1
+ import type { DistanceBackend } from './backends/DistanceBackend';
2
+ export type DistanceMetric = 'cosine' | 'euclidean' | 'dot_product';
3
+ export interface Node {
4
+ id: number;
5
+ level: number;
6
+ vector: Float32Array;
7
+ neighbors: number[][];
8
+ }
9
+ export declare class HNSWIndex {
10
+ private M;
11
+ private M0;
12
+ private efConstruction;
13
+ private levelMult;
14
+ private maxLevel;
15
+ private entryPointId;
16
+ private nodes;
17
+ private nodeCount;
18
+ private dimension;
19
+ private metric;
20
+ private maxLayers;
21
+ private distanceBackend;
22
+ private flatVectors;
23
+ private flatVectorsCapacity;
24
+ private searchHeap;
25
+ private visitedArray;
26
+ private visitedArraySize;
27
+ private visitedGeneration;
28
+ private candidatesHeap;
29
+ private resultsHeap;
30
+ private selectionHeap;
31
+ private heapCapacity;
32
+ private vectorsAreNormalized;
33
+ private distanceFn;
34
+ private scalarQuantizer;
35
+ private int8Vectors;
36
+ private quantizationEnabled;
37
+ private lazyLoadEnabled;
38
+ private vectorOffsets;
39
+ private vectorBuffer;
40
+ private vectorsLoaded;
41
+ private queryNormBuffer;
42
+ private neighborSets;
43
+ private constructionMode;
44
+ constructor(dimension: number, metric?: DistanceMetric, M?: number, efConstruction?: number, distanceBackend?: DistanceBackend);
45
+ /**
46
+ * Ensure node array and flat vector storage have enough capacity
47
+ */
48
+ private ensureCapacity;
49
+ /**
50
+ * Get vector from flat storage by node ID
51
+ * Returns a subarray view (no copy) for efficiency
52
+ */
53
+ private getFlatVector;
54
+ /**
55
+ * Set vector in flat storage
56
+ */
57
+ private setFlatVector;
58
+ /**
59
+ * Get node by ID (O(1) array access)
60
+ */
61
+ private getNode;
62
+ /**
63
+ * Set node by ID
64
+ */
65
+ private setNode;
66
+ private batchNeighborIds;
67
+ private batchDistances;
68
+ /**
69
+ * OPTIMIZATION: Batch distance calculation for better cache locality
70
+ * Computes distances from query to multiple neighbors at once
71
+ * Uses flat vector storage for contiguous memory access
72
+ */
73
+ private calculateDistancesBatch;
74
+ /**
75
+ * Check if a node has been visited in the current search.
76
+ * Uses generation counting to avoid clearing the array.
77
+ */
78
+ private isVisited;
79
+ /**
80
+ * Mark a node as visited in the current search.
81
+ * Grows the array if needed.
82
+ */
83
+ private markVisited;
84
+ /**
85
+ * Clear all visited markers by incrementing the generation.
86
+ * Much faster than filling the array with zeros.
87
+ */
88
+ private clearVisited;
89
+ private normalizeVector;
90
+ private selectLevel;
91
+ /**
92
+ * Calculate distance between two vectors using the configured metric.
93
+ * Uses cached function pointer to avoid switch overhead.
94
+ */
95
+ calculateDistance(a: Float32Array, b: Float32Array): number;
96
+ /**
97
+ * Get a node's vector, loading it if necessary (for lazy loading support)
98
+ */
99
+ private getNodeVector;
100
+ private getLayerMaxConnections;
101
+ private selectNeighbors;
102
+ private addBidirectionalConnection;
103
+ /**
104
+ * Ensure heap capacity is sufficient for the given ef value.
105
+ * Resizes heaps if needed.
106
+ */
107
+ private ensureHeapCapacity;
108
+ /**
109
+ * Search a layer using the standard two-heap HNSW algorithm.
110
+ *
111
+ * Uses two heaps:
112
+ * - candidatesHeap (min-heap): Tracks nodes to explore, prioritizing closest
113
+ * - resultsHeap (max-heap): Tracks top-ef results, allowing O(log n) eviction of furthest
114
+ *
115
+ * Termination: Stops when closest unvisited candidate is farther than furthest result.
116
+ */
117
+ private searchLayer;
118
+ private greedySearch;
119
+ /**
120
+ * Add a point to the index (async wrapper for API compatibility)
121
+ * For bulk operations, use addPointsBulk() which uses the faster sync version internally
122
+ */
123
+ addPoint(id: number, vector: number[] | Float32Array, options?: {
124
+ skipNormalization?: boolean;
125
+ }): Promise<void>;
126
+ /**
127
+ * Synchronous version of addPoint - avoids async/await microtask overhead
128
+ * 10-15x faster for bulk insertions where async is not needed
129
+ * @param skipNormalization - Set true if vectors are already unit-normalized (e.g., Cohere embeddings)
130
+ */
131
+ addPointSync(id: number, vector: number[] | Float32Array, options?: {
132
+ skipNormalization?: boolean;
133
+ }): void;
134
+ searchKNN(query: Float32Array, k: number, efSearch?: number): Array<{
135
+ id: number;
136
+ distance: number;
137
+ }>;
138
+ /**
139
+ * Batch search for multiple query vectors.
140
+ * More efficient than calling searchKNN multiple times as it reuses internal buffers.
141
+ *
142
+ * @param queries Array of query vectors
143
+ * @param k Number of nearest neighbors to return per query
144
+ * @param efSearch Search effort parameter (higher = better recall, slower)
145
+ * @returns Array of results, one per query
146
+ */
147
+ searchKNNBatch(queries: Float32Array[], k: number, efSearch?: number): Array<Array<{
148
+ id: number;
149
+ distance: number;
150
+ }>>;
151
+ /**
152
+ * Optimized batch search that returns results in a flat structure for better performance.
153
+ * Useful when you need to process many queries quickly.
154
+ *
155
+ * @param queries Flat Float32Array containing all queries concatenated
156
+ * @param numQueries Number of queries in the array
157
+ * @param k Number of nearest neighbors to return per query
158
+ * @param efSearch Search effort parameter
159
+ * @returns Object with flat arrays for ids and distances
160
+ */
161
+ searchKNNBatchFlat(queries: Float32Array, numQueries: number, k: number, efSearch?: number): {
162
+ ids: Uint32Array;
163
+ distances: Float32Array;
164
+ };
165
+ /**
166
+ * Add a single vector with auto-generated ID.
167
+ * Returns the assigned ID.
168
+ *
169
+ * @param vector Vector to add
170
+ * @returns The auto-generated ID
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * const id = await index.add([0.1, 0.2, 0.3]);
175
+ * console.log(`Added vector with ID: ${id}`);
176
+ * ```
177
+ */
178
+ add(vector: number[] | Float32Array): Promise<number>;
179
+ /**
180
+ * Simple query interface - find k nearest neighbors.
181
+ *
182
+ * @param vector Query vector
183
+ * @param k Number of results (default: 10)
184
+ * @returns Array of {id, distance} results
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const results = index.query([0.1, 0.2, 0.3], 5);
189
+ * results.forEach(r => console.log(`ID: ${r.id}, Distance: ${r.distance}`));
190
+ * ```
191
+ */
192
+ query(vector: number[] | Float32Array, k?: number): Array<{
193
+ id: number;
194
+ distance: number;
195
+ }>;
196
+ /**
197
+ * Add multiple vectors with auto-generated IDs.
198
+ * Returns the assigned IDs.
199
+ *
200
+ * @param vectors Array of vectors to add
201
+ * @returns Array of auto-generated IDs
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const ids = await index.addAll([[0.1, 0.2], [0.3, 0.4]]);
206
+ * ```
207
+ */
208
+ addAll(vectors: Array<number[] | Float32Array>): Promise<number[]>;
209
+ /**
210
+ * Bulk add multiple points with optimized O(1) neighbor lookups.
211
+ * Significantly faster than sequential addPoint() calls for large batches.
212
+ * Uses Set-based membership testing during construction, then releases memory.
213
+ *
214
+ * @param points Array of {id, vector} to add
215
+ * @example
216
+ * ```typescript
217
+ * await index.addPointsBulk([
218
+ * { id: 0, vector: new Float32Array([0.1, 0.2, ...]) },
219
+ * { id: 1, vector: new Float32Array([0.3, 0.4, ...]) },
220
+ * ]);
221
+ * ```
222
+ */
223
+ addPointsBulk(points: Array<{
224
+ id: number;
225
+ vector: Float32Array;
226
+ }>, options?: {
227
+ skipNormalization?: boolean;
228
+ }): Promise<void>;
229
+ /**
230
+ * Synchronous bulk insertion - 10-15x faster than async version
231
+ * Uses addPointSync() internally to avoid microtask queue overhead
232
+ * @param skipNormalization - Set true if vectors are already unit-normalized
233
+ */
234
+ addPointsBulkSync(points: Array<{
235
+ id: number;
236
+ vector: Float32Array;
237
+ }>, options?: {
238
+ skipNormalization?: boolean;
239
+ }): void;
240
+ /**
241
+ * Clear construction-time data structures to free memory.
242
+ * Called automatically after addPointsBulk(), but can be called
243
+ * manually if needed.
244
+ */
245
+ clearConstructionCache(): void;
246
+ private static readonly MAGIC;
247
+ private static readonly FORMAT_VERSION;
248
+ private static readonly HEADER_SIZE;
249
+ /**
250
+ * Get all nodes as an array (filters out undefined slots)
251
+ */
252
+ private getNodesArray;
253
+ serialize(): ArrayBuffer;
254
+ /**
255
+ * Deserialize an HNSW index from a buffer.
256
+ *
257
+ * @param buffer The serialized index buffer
258
+ * @param options Optional loading options
259
+ * - lazyLoadVectors: If true, don't load vectors immediately (v3+ only)
260
+ */
261
+ static deserialize(buffer: ArrayBuffer, options?: {
262
+ lazyLoadVectors?: boolean;
263
+ }): HNSWIndex;
264
+ /**
265
+ * Load a specific vector on demand (for lazy-loaded indices).
266
+ * Returns the vector if lazy loading is enabled, otherwise returns the already-loaded vector.
267
+ */
268
+ loadVector(nodeId: number): Float32Array | null;
269
+ /**
270
+ * Preload vectors for specific node IDs.
271
+ * Useful for warming up cache before searches.
272
+ */
273
+ preloadVectors(nodeIds: number[]): void;
274
+ /**
275
+ * Check if lazy loading is enabled
276
+ */
277
+ isLazyLoadEnabled(): boolean;
278
+ /**
279
+ * Get lazy loading statistics
280
+ */
281
+ getLazyLoadStats(): {
282
+ enabled: boolean;
283
+ totalNodes: number;
284
+ loadedVectors: number;
285
+ memoryReduction: string;
286
+ };
287
+ saveToFile(filePath: string): Promise<void>;
288
+ static loadFromFile(filePath: string): Promise<HNSWIndex>;
289
+ destroy(): void;
290
+ /**
291
+ * Get memory usage statistics
292
+ */
293
+ getMemoryUsage(): number;
294
+ /**
295
+ * Get all vectors for brute-force search
296
+ */
297
+ getAllVectors(): Map<number, Float32Array>;
298
+ /**
299
+ * Enable Int8 quantization for faster search with automatic rescoring.
300
+ * Trains the quantizer on existing vectors and quantizes them.
301
+ *
302
+ * Performance:
303
+ * - 4x memory reduction
304
+ * - 3-4x faster distance calculations
305
+ * - 99%+ recall with automatic rescoring
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * // After adding vectors
310
+ * index.enableQuantization();
311
+ *
312
+ * // Now use quantized search (automatically rescores for high recall)
313
+ * const results = index.searchKNNQuantized(query, 10);
314
+ * ```
315
+ */
316
+ enableQuantization(): void;
317
+ /**
318
+ * Check if quantization is enabled
319
+ */
320
+ isQuantizationEnabled(): boolean;
321
+ /**
322
+ * Fast quantized search with automatic rescoring.
323
+ *
324
+ * Uses Int8 quantized vectors for initial candidate retrieval (3-4x faster),
325
+ * then rescores top candidates with float32 for accurate ranking.
326
+ *
327
+ * @param query Query vector
328
+ * @param k Number of results to return
329
+ * @param candidateMultiplier How many extra candidates to retrieve for rescoring (default: 3)
330
+ * @param efSearch Search effort parameter
331
+ * @returns Array of {id, distance} results (same format as searchKNN)
332
+ *
333
+ * Performance:
334
+ * - 3-4x faster than float32 for distance calculations
335
+ * - 99%+ recall with candidateMultiplier=3 (automatic rescoring)
336
+ * - 4x memory reduction
337
+ */
338
+ searchKNNQuantized(query: Float32Array, k: number, candidateMultiplier?: number, efSearch?: number): Array<{
339
+ id: number;
340
+ distance: number;
341
+ }>;
342
+ /**
343
+ * Search layer using Int8 quantized distances for speed.
344
+ * Same algorithm as searchLayer but uses faster Int8 distance calculations.
345
+ */
346
+ private searchLayerQuantized;
347
+ /**
348
+ * Get quantization statistics
349
+ */
350
+ getQuantizationStats(): {
351
+ enabled: boolean;
352
+ vectorCount: number;
353
+ memoryReduction: string;
354
+ expectedSpeedup: string;
355
+ };
356
+ }
357
+ //# sourceMappingURL=HNSWIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HNSWIndex.d.ts","sourceRoot":"","sources":["../src/HNSWIndex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAMlE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAC;AAEpE,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC;CACvB;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAkB;IAIzC,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,mBAAmB,CAAa;IAGxC,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,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B;CAsBF"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * MaxBinaryHeap - A max-heap implementation for HNSW result tracking.
3
+ *
4
+ * In HNSW search, we need to track the top-k closest results efficiently.
5
+ * A max-heap keeps the FURTHEST element at the top, allowing O(log n) eviction
6
+ * of the worst result when a better one is found.
7
+ *
8
+ * This complements BinaryHeap (min-heap) which is used for candidate exploration.
9
+ */
10
+ export declare class MaxBinaryHeap {
11
+ private ids;
12
+ private dists;
13
+ private _size;
14
+ private capacity;
15
+ constructor(capacity: number);
16
+ /**
17
+ * Push an element onto the heap.
18
+ * When at capacity, replaces the max element if the new one is closer.
19
+ */
20
+ push(id: number, dist: number): void;
21
+ /**
22
+ * Remove and return the ID of the maximum element (furthest distance).
23
+ * Returns -1 if heap is empty.
24
+ */
25
+ pop(): number;
26
+ /**
27
+ * Peek at the ID of the maximum element without removing it.
28
+ * Returns -1 if heap is empty.
29
+ */
30
+ peek(): number;
31
+ /**
32
+ * Peek at the distance of the maximum element (furthest from query).
33
+ * Returns -Infinity if heap is empty.
34
+ */
35
+ peekValue(): number;
36
+ /**
37
+ * Get the current number of elements in the heap.
38
+ */
39
+ size(): number;
40
+ /**
41
+ * Check if the heap is empty.
42
+ */
43
+ isEmpty(): boolean;
44
+ /**
45
+ * Clear all elements from the heap.
46
+ */
47
+ clear(): void;
48
+ /**
49
+ * Get the capacity of the heap.
50
+ */
51
+ getCapacity(): number;
52
+ /**
53
+ * Heapify up: restore max-heap property after insertion.
54
+ * Parent should be LARGER than children in a max-heap.
55
+ */
56
+ private heapifyUp;
57
+ /**
58
+ * Heapify down: restore max-heap property after removal.
59
+ * Find largest among node and children, swap if needed.
60
+ */
61
+ private heapifyDown;
62
+ }
63
+ //# sourceMappingURL=MaxBinaryHeap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MaxBinaryHeap.d.ts","sourceRoot":"","sources":["../src/MaxBinaryHeap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAS;gBAEb,QAAQ,EAAE,MAAM;IAO5B;;;OAGG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAmBpC;;;OAGG;IACH,GAAG,IAAI,MAAM;IAeb;;;OAGG;IACH,IAAI,IAAI,MAAM;IAId;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,WAAW,IAAI,MAAM;IAIrB;;;OAGG;IACH,OAAO,CAAC,SAAS;IAwBjB;;;OAGG;IACH,OAAO,CAAC,WAAW;CAkCpB"}
@@ -0,0 +1,54 @@
1
+ export declare class MetadataStorage {
2
+ private metadataMap;
3
+ private idList;
4
+ constructor();
5
+ private ensureInitialized;
6
+ set(id: string, metadata: any): void;
7
+ get(id: string): any | undefined;
8
+ has(id: string): boolean;
9
+ delete(id: string): boolean;
10
+ getAllIds(): string[];
11
+ entries(): [string, any][];
12
+ clear(): void;
13
+ destroy(): void;
14
+ size(): number;
15
+ saveToDisk(filePath: string): Promise<void>;
16
+ private createBinaryBuffer;
17
+ loadFromDisk(filePath: string): Promise<void>;
18
+ private loadFromBinaryBuffer;
19
+ }
20
+ export declare class VectorStorage {
21
+ private dimension;
22
+ private vectors;
23
+ private vectorCount;
24
+ private capacity;
25
+ private filePath;
26
+ private fileHandle;
27
+ constructor(dimension: number, initialCapacity?: number);
28
+ initializeForMemoryMapping(filePath: string): Promise<void>;
29
+ addVector(vector: number[]): number;
30
+ getVector(index: number): number[];
31
+ getVectorAsTypedArray(index: number): Float32Array;
32
+ getVectorCount(): number;
33
+ getDimension(): number;
34
+ private expandCapacity;
35
+ saveToDisk(filePath: string): Promise<void>;
36
+ loadFromDisk(filePath: string): Promise<void>;
37
+ destroy(): void;
38
+ }
39
+ export declare class MemoryMappedVectorStorage {
40
+ private dimension;
41
+ private vectorCount;
42
+ private filePath;
43
+ private mappedBuffer;
44
+ private mappedView;
45
+ constructor(dimension: number);
46
+ initializeMemoryMapping(filePath: string): Promise<void>;
47
+ getVector(index: number): number[];
48
+ getVectorAsTypedArray(index: number): Float32Array;
49
+ getVectorCount(): number;
50
+ getDimension(): number;
51
+ appendVector(vector: number[]): Promise<void>;
52
+ destroy(): void;
53
+ }
54
+ //# sourceMappingURL=Storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"AAKA,qBAAa,eAAe;IAC1B,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,MAAM,CAAkB;;IAOhC,OAAO,CAAC,iBAAiB;IAMzB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAUpC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAKhC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAKxB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAU3B,SAAS,IAAI,MAAM,EAAE;IAKrB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;IAK1B,KAAK,IAAI,IAAI;IAMb,OAAO,IAAI,IAAI;IAMf,IAAI,IAAI,MAAM;IAKR,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD,OAAO,CAAC,kBAAkB;IAoCpB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAanD,OAAO,CAAC,oBAAoB;CA6B7B;AAGD,qBAAa,aAAa;IACxB,OAAO,CAA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AI;CAMhB"}
@@ -0,0 +1,44 @@
1
+ import { Collection } from './Collection';
2
+ import type { StorageBackend } from './storage/StorageBackend';
3
+ export type DistanceMetric = 'cosine' | 'euclidean' | 'dot_product';
4
+ export interface VectorDBConfig {
5
+ /**
6
+ * Path for storing collections on disk. Default: './vectordb_data'
7
+ * Ignored if a custom storageBackend is provided.
8
+ */
9
+ storagePath?: string;
10
+ /**
11
+ * Custom storage backend for platform-specific storage (e.g., OPFS for browsers).
12
+ * If not provided, defaults to BunStorageBackend with storagePath.
13
+ */
14
+ storageBackend?: StorageBackend;
15
+ }
16
+ export interface CollectionConfig {
17
+ dimension: number;
18
+ metric?: DistanceMetric;
19
+ M?: number;
20
+ efConstruction?: number;
21
+ }
22
+ export declare class VectorDB {
23
+ private collections;
24
+ private storagePath;
25
+ private storageBackend;
26
+ private initialized;
27
+ constructor(config?: VectorDBConfig);
28
+ /**
29
+ * Get the storage backend used by this VectorDB instance.
30
+ * Useful for custom storage operations or debugging.
31
+ */
32
+ getStorageBackend(): StorageBackend;
33
+ /**
34
+ * Initialize the VectorDB - creates storage directory if needed.
35
+ * Called automatically on first operation if not called explicitly.
36
+ */
37
+ init(): Promise<void>;
38
+ createCollection(name: string, config: CollectionConfig): Promise<Collection>;
39
+ getCollection(name: string): Collection | undefined;
40
+ listCollections(): Promise<string[]>;
41
+ deleteCollection(name: string): Promise<void>;
42
+ close(): Promise<void>;
43
+ }
44
+ //# sourceMappingURL=VectorDB.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorDB.d.ts","sourceRoot":"","sources":["../src/VectorDB.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAC;AAEpE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,WAAW,CAAkB;gBAEzB,MAAM,CAAC,EAAE,cAAc;IAOnC;;;OAGG;IACH,iBAAiB,IAAI,cAAc;IAInC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IASrB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAmBnF,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI7C,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIpC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
@@ -0,0 +1,5 @@
1
+ export interface DistanceBackend {
2
+ batchL2(base: Float32Array, dim: number, ids: Uint32Array, query: Float32Array, out: Float32Array): void;
3
+ batchDot(base: Float32Array, dim: number, ids: Uint32Array, query: Float32Array, out: Float32Array): void;
4
+ }
5
+ //# sourceMappingURL=DistanceBackend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DistanceBackend.d.ts","sourceRoot":"","sources":["../../src/backends/DistanceBackend.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,CACL,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,YAAY,EACnB,GAAG,EAAE,YAAY,GAChB,IAAI,CAAC;IAER,QAAQ,CACN,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,YAAY,EACnB,GAAG,EAAE,YAAY,GAChB,IAAI,CAAC;CACT"}
@@ -0,0 +1,37 @@
1
+ import { DistanceBackend } from './DistanceBackend';
2
+ /**
3
+ * Optimized JavaScript distance backend with SIMD-style 4-wide unrolling.
4
+ * This provides ~1.5-2x speedup over naive loops by reducing loop overhead
5
+ * and enabling better CPU pipelining.
6
+ */
7
+ export declare class JsDistanceBackend implements DistanceBackend {
8
+ batchL2(base: Float32Array, dim: number, ids: Uint32Array, query: Float32Array, out: Float32Array): void;
9
+ batchDot(base: Float32Array, dim: number, ids: Uint32Array, query: Float32Array, out: Float32Array): void;
10
+ /**
11
+ * Compute dot product with 4-wide manual unrolling for better performance.
12
+ * Uses separate accumulators to enable instruction-level parallelism.
13
+ */
14
+ private dotProductUnrolled;
15
+ /**
16
+ * Compute L2 squared distance with 4-wide manual unrolling.
17
+ */
18
+ private l2SquaredUnrolled;
19
+ }
20
+ /**
21
+ * Fast inline distance functions for single-vector comparisons.
22
+ * These avoid the batch interface overhead for point-to-point distance calculations.
23
+ */
24
+ export declare function dotProductFast(a: Float32Array, b: Float32Array): number;
25
+ export declare function l2SquaredFast(a: Float32Array, b: Float32Array): number;
26
+ /**
27
+ * Normalize a vector in place.
28
+ * Uses 8-wide unrolling for better ILP.
29
+ */
30
+ export declare function normalizeInPlace(v: Float32Array): number;
31
+ /**
32
+ * Compute cosine distance between two vectors.
33
+ * For pre-normalized vectors, this is simply 1 - dot(a, b).
34
+ * Uses 8-wide unrolling for norm computation.
35
+ */
36
+ export declare function cosineDistanceFast(a: Float32Array, b: Float32Array, aIsNormalized?: boolean, bIsNormalized?: boolean): number;
37
+ //# sourceMappingURL=JsDistanceBackend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsDistanceBackend.d.ts","sourceRoot":"","sources":["../../src/backends/JsDistanceBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,eAAe;IACvD,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI;IAQxG,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI;IAQzG;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAyB1B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CA0BvE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAmCtE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,CA6BxD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,aAAa,UAAQ,EAAE,aAAa,UAAQ,GAAG,MAAM,CAsCzH"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Delta Encoding with Varint for Neighbor Lists
3
+ *
4
+ * Implements delta-encoded neighbor lists as used by Qdrant for ~38% storage reduction.
5
+ * Neighbor IDs are sorted, then stored as deltas with variable-length encoding.
6
+ *
7
+ * Format:
8
+ * - First ID stored as full uint32
9
+ * - Subsequent IDs stored as varint deltas from previous ID
10
+ *
11
+ * Varint encoding (like Protocol Buffers):
12
+ * - Values 0-127: 1 byte
13
+ * - Values 128-16383: 2 bytes
14
+ * - Values 16384-2097151: 3 bytes
15
+ * - Values 2097152-268435455: 4 bytes
16
+ * - Larger: 5 bytes
17
+ */
18
+ /**
19
+ * Encode an unsigned integer as a varint
20
+ * Returns the number of bytes written
21
+ */
22
+ export declare function encodeVarint(value: number, buffer: Uint8Array, offset: number): number;
23
+ /**
24
+ * Decode a varint from buffer
25
+ * Returns [value, bytesRead]
26
+ */
27
+ export declare function decodeVarint(buffer: Uint8Array, offset: number): [number, number];
28
+ /**
29
+ * Calculate the number of bytes needed to encode a varint
30
+ */
31
+ export declare function varintSize(value: number): number;
32
+ /**
33
+ * Delta-encode a sorted array of neighbor IDs
34
+ * Returns the encoded buffer
35
+ */
36
+ export declare function deltaEncodeNeighbors(neighbors: number[]): Uint8Array;
37
+ /**
38
+ * Decode a delta-encoded neighbor list
39
+ * Returns the original neighbor IDs (sorted)
40
+ */
41
+ export declare function deltaDecodeNeighbors(buffer: Uint8Array, count: number): number[];
42
+ /**
43
+ * Calculate the encoded size for a neighbor list without actually encoding
44
+ * Useful for calculating total buffer size before serialization
45
+ */
46
+ export declare function deltaEncodedSize(neighbors: number[]): number;
47
+ /**
48
+ * Batch encode multiple neighbor lists efficiently
49
+ * Returns a single buffer with all encoded lists concatenated
50
+ * Also returns offsets for each list
51
+ */
52
+ export declare function deltaEncodeBatch(neighborLists: number[][]): {
53
+ buffer: Uint8Array;
54
+ offsets: number[];
55
+ sizes: number[];
56
+ };
57
+ /**
58
+ * Decode a batch of neighbor lists from a single buffer
59
+ */
60
+ export declare function deltaDecodeBatch(buffer: Uint8Array, offsets: number[], sizes: number[], counts: number[]): number[][];
61
+ //# sourceMappingURL=DeltaEncoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeltaEncoder.d.ts","sourceRoot":"","sources":["../../src/encoding/DeltaEncoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAWtF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBjF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQhD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,UAAU,CAkCpE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAoBhF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,CAgB5D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,GAAG;IAC3D,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAqBA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,EAAE,GACf,MAAM,EAAE,EAAE,CAaZ"}