verso-db 0.1.5 → 0.2.0
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.
- package/CHANGELOG.md +13 -0
- package/README.md +13 -7
- package/dist/BinaryHeap.d.ts +11 -1
- package/dist/BinaryHeap.d.ts.map +1 -1
- package/dist/BinaryHeap.js +138 -0
- package/dist/BinaryHeap.js.map +1 -0
- package/dist/Collection.d.ts +30 -4
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +1186 -0
- package/dist/Collection.js.map +1 -0
- package/dist/HNSWIndex.d.ts +59 -0
- package/dist/HNSWIndex.d.ts.map +1 -1
- package/dist/HNSWIndex.js +2818 -0
- package/dist/HNSWIndex.js.map +1 -0
- package/dist/MaxBinaryHeap.d.ts +2 -64
- package/dist/MaxBinaryHeap.d.ts.map +1 -1
- package/dist/MaxBinaryHeap.js +5 -0
- package/dist/MaxBinaryHeap.js.map +1 -0
- package/dist/SearchWorker.d.ts +57 -4
- package/dist/SearchWorker.d.ts.map +1 -1
- package/dist/SearchWorker.js +573 -0
- package/dist/SearchWorker.js.map +1 -0
- package/dist/VectorDB.d.ts.map +1 -1
- package/dist/VectorDB.js +246 -0
- package/dist/VectorDB.js.map +1 -0
- package/dist/WorkerPool.d.ts +32 -2
- package/dist/WorkerPool.d.ts.map +1 -1
- package/dist/WorkerPool.js +266 -0
- package/dist/WorkerPool.js.map +1 -0
- package/dist/backends/JsDistanceBackend.d.ts.map +1 -1
- package/dist/backends/JsDistanceBackend.js +163 -0
- package/dist/backends/JsDistanceBackend.js.map +1 -0
- package/dist/encoding/DeltaEncoder.d.ts +2 -2
- package/dist/encoding/DeltaEncoder.d.ts.map +1 -1
- package/dist/encoding/DeltaEncoder.js +199 -0
- package/dist/encoding/DeltaEncoder.js.map +1 -0
- package/dist/errors.js +97 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -42
- package/dist/index.js.map +1 -9
- package/dist/presets.js +205 -0
- package/dist/presets.js.map +1 -0
- package/dist/quantization/ScalarQuantizer.d.ts +0 -34
- package/dist/quantization/ScalarQuantizer.d.ts.map +1 -1
- package/dist/quantization/ScalarQuantizer.js +346 -0
- package/dist/quantization/ScalarQuantizer.js.map +1 -0
- package/dist/storage/BatchWriter.js +351 -0
- package/dist/storage/BatchWriter.js.map +1 -0
- package/dist/storage/BunStorageBackend.d.ts +7 -3
- package/dist/storage/BunStorageBackend.d.ts.map +1 -1
- package/dist/storage/BunStorageBackend.js +182 -0
- package/dist/storage/BunStorageBackend.js.map +1 -0
- package/dist/storage/MemoryBackend.js +109 -0
- package/dist/storage/MemoryBackend.js.map +1 -0
- package/dist/storage/OPFSBackend.d.ts.map +1 -1
- package/dist/storage/OPFSBackend.js +325 -0
- package/dist/storage/OPFSBackend.js.map +1 -0
- package/dist/storage/StorageBackend.js +12 -0
- package/dist/storage/StorageBackend.js.map +1 -0
- package/dist/storage/WriteAheadLog.js +321 -0
- package/dist/storage/WriteAheadLog.js.map +1 -0
- package/dist/storage/createStorageBackend.d.ts +4 -0
- package/dist/storage/createStorageBackend.d.ts.map +1 -1
- package/dist/storage/createStorageBackend.js +119 -0
- package/dist/storage/createStorageBackend.js.map +1 -0
- package/{src/storage/index.ts → dist/storage/index.js} +7 -27
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/nodeFsRuntime.d.ts +14 -0
- package/dist/storage/nodeFsRuntime.d.ts.map +1 -0
- package/dist/storage/nodeFsRuntime.js +105 -0
- package/dist/storage/nodeFsRuntime.js.map +1 -0
- package/package.json +9 -7
- package/src/BinaryHeap.ts +0 -136
- package/src/Collection.ts +0 -1262
- package/src/HNSWIndex.ts +0 -2894
- package/src/MaxBinaryHeap.ts +0 -181
- package/src/SearchWorker.ts +0 -264
- package/src/VectorDB.ts +0 -319
- package/src/WorkerPool.ts +0 -222
- package/src/backends/JsDistanceBackend.ts +0 -171
- package/src/encoding/DeltaEncoder.ts +0 -236
- package/src/errors.ts +0 -110
- package/src/index.ts +0 -106
- package/src/presets.ts +0 -229
- package/src/quantization/ScalarQuantizer.ts +0 -487
- package/src/storage/BatchWriter.ts +0 -420
- package/src/storage/BunStorageBackend.ts +0 -199
- package/src/storage/MemoryBackend.ts +0 -122
- package/src/storage/OPFSBackend.ts +0 -348
- package/src/storage/StorageBackend.ts +0 -74
- package/src/storage/WriteAheadLog.ts +0 -379
- package/src/storage/createStorageBackend.ts +0 -137
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "verso-db",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "High-performance vector search with HNSW indexing for Bun and Browser. 100% recall, 4x memory reduction with Int8 quantization.",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "High-performance vector search with HNSW indexing for Bun, Node.js, and Browser. 100% recall, 4x memory reduction with Int8 quantization.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"bun": "./
|
|
12
|
+
"bun": "./dist/index.js",
|
|
13
13
|
"import": "./dist/index.js",
|
|
14
14
|
"default": "./dist/index.js"
|
|
15
15
|
},
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
20
|
"dist/*.map",
|
|
21
|
-
"src",
|
|
22
21
|
"README.md",
|
|
23
22
|
"LICENSE",
|
|
24
23
|
"CHANGELOG.md"
|
|
@@ -27,13 +26,15 @@
|
|
|
27
26
|
"access": "public"
|
|
28
27
|
},
|
|
29
28
|
"scripts": {
|
|
30
|
-
"build": "
|
|
29
|
+
"build": "bun run build:js && bun run build:types",
|
|
30
|
+
"build:js": "bun run ./scripts/build-dist.ts",
|
|
31
31
|
"build:types": "tsc --emitDeclarationOnly --declaration --outDir ./dist",
|
|
32
32
|
"test": "bun test ./test",
|
|
33
33
|
"test:browser": "vitest --config vitest.browser.config.ts run",
|
|
34
34
|
"test:browser:watch": "vitest --config vitest.browser.config.ts",
|
|
35
35
|
"test:browser:ui": "vitest --config vitest.browser.config.ts --ui",
|
|
36
|
-
"
|
|
36
|
+
"verify:dist": "bun run ./scripts/verify-dist.ts",
|
|
37
|
+
"prepublishOnly": "bun run build && bun run verify:dist",
|
|
37
38
|
"bench": "bun run benchmarks/hnsw.bench.ts",
|
|
38
39
|
"benchmark:recall": "bun run benchmarks/baseline_recall.ts",
|
|
39
40
|
"benchmark:storage": "bun run benchmarks/storage.bench.ts",
|
|
@@ -75,7 +76,8 @@
|
|
|
75
76
|
"homepage": "https://github.com/briansunter/verso#readme",
|
|
76
77
|
"sideEffects": false,
|
|
77
78
|
"engines": {
|
|
78
|
-
"bun": ">=1.0.0"
|
|
79
|
+
"bun": ">=1.0.0",
|
|
80
|
+
"node": ">=20.0.0"
|
|
79
81
|
},
|
|
80
82
|
"peerDependencies": {
|
|
81
83
|
"typescript": "^5"
|
package/src/BinaryHeap.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
export class BinaryHeap {
|
|
2
|
-
private ids: Uint32Array;
|
|
3
|
-
private dists: Float32Array;
|
|
4
|
-
private _size: number;
|
|
5
|
-
private capacity: number;
|
|
6
|
-
|
|
7
|
-
constructor(capacity: number) {
|
|
8
|
-
this.capacity = capacity;
|
|
9
|
-
this.ids = new Uint32Array(capacity);
|
|
10
|
-
this.dists = new Float32Array(capacity);
|
|
11
|
-
this._size = 0;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Push an element onto the heap.
|
|
16
|
-
* Auto-grows when at capacity to avoid silently dropping elements.
|
|
17
|
-
*/
|
|
18
|
-
push(id: number, dist: number): void {
|
|
19
|
-
if (this._size >= this.capacity) {
|
|
20
|
-
this.grow();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.ids[this._size] = id;
|
|
24
|
-
this.dists[this._size] = dist;
|
|
25
|
-
this._size++;
|
|
26
|
-
this.heapifyUp(this._size - 1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Double the heap capacity when full.
|
|
31
|
-
*/
|
|
32
|
-
private grow(): void {
|
|
33
|
-
const newCapacity = Math.max(this.capacity * 2, 16);
|
|
34
|
-
const newIds = new Uint32Array(newCapacity);
|
|
35
|
-
const newDists = new Float32Array(newCapacity);
|
|
36
|
-
newIds.set(this.ids);
|
|
37
|
-
newDists.set(this.dists);
|
|
38
|
-
this.ids = newIds;
|
|
39
|
-
this.dists = newDists;
|
|
40
|
-
this.capacity = newCapacity;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
pop(): number {
|
|
44
|
-
if (this._size === 0) return -1;
|
|
45
|
-
|
|
46
|
-
const result = this.ids[0];
|
|
47
|
-
this._size--;
|
|
48
|
-
if (this._size > 0) {
|
|
49
|
-
this.ids[0] = this.ids[this._size];
|
|
50
|
-
this.dists[0] = this.dists[this._size];
|
|
51
|
-
this.heapifyDown(0);
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
peek(): number {
|
|
57
|
-
return this._size > 0 ? this.ids[0] : -1;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
peekValue(): number {
|
|
61
|
-
return this._size > 0 ? this.dists[0] : Infinity;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
size(): number {
|
|
65
|
-
return this._size;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
clear(): void {
|
|
69
|
-
this._size = 0;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
isEmpty(): boolean {
|
|
73
|
-
return this._size === 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getCapacity(): number {
|
|
77
|
-
return this.capacity;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private heapifyUp(index: number): void {
|
|
81
|
-
// Cache array references to avoid repeated property lookups
|
|
82
|
-
const ids = this.ids;
|
|
83
|
-
const dists = this.dists;
|
|
84
|
-
|
|
85
|
-
while (index > 0) {
|
|
86
|
-
// Use bitwise shift for faster integer division
|
|
87
|
-
const parentIndex = (index - 1) >> 1;
|
|
88
|
-
if (dists[parentIndex] <= dists[index]) break;
|
|
89
|
-
|
|
90
|
-
// Inline swap for performance
|
|
91
|
-
const tmpId = ids[index];
|
|
92
|
-
ids[index] = ids[parentIndex];
|
|
93
|
-
ids[parentIndex] = tmpId;
|
|
94
|
-
|
|
95
|
-
const tmpDist = dists[index];
|
|
96
|
-
dists[index] = dists[parentIndex];
|
|
97
|
-
dists[parentIndex] = tmpDist;
|
|
98
|
-
|
|
99
|
-
index = parentIndex;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private heapifyDown(index: number): void {
|
|
104
|
-
// Cache array references to avoid repeated property lookups
|
|
105
|
-
const ids = this.ids;
|
|
106
|
-
const dists = this.dists;
|
|
107
|
-
const size = this._size;
|
|
108
|
-
|
|
109
|
-
while (true) {
|
|
110
|
-
const leftChild = (index << 1) + 1; // 2 * index + 1
|
|
111
|
-
const rightChild = leftChild + 1; // 2 * index + 2
|
|
112
|
-
let smallest = index;
|
|
113
|
-
|
|
114
|
-
if (leftChild < size && dists[leftChild] < dists[smallest]) {
|
|
115
|
-
smallest = leftChild;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (rightChild < size && dists[rightChild] < dists[smallest]) {
|
|
119
|
-
smallest = rightChild;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (smallest === index) break;
|
|
123
|
-
|
|
124
|
-
// Inline swap for performance
|
|
125
|
-
const tmpId = ids[index];
|
|
126
|
-
ids[index] = ids[smallest];
|
|
127
|
-
ids[smallest] = tmpId;
|
|
128
|
-
|
|
129
|
-
const tmpDist = dists[index];
|
|
130
|
-
dists[index] = dists[smallest];
|
|
131
|
-
dists[smallest] = tmpDist;
|
|
132
|
-
|
|
133
|
-
index = smallest;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|