ruvector 0.1.21 → 0.1.23

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/dist/index.d.mts DELETED
@@ -1,95 +0,0 @@
1
- /**
2
- * Vector database types compatible with both NAPI and WASM backends
3
- */
4
-
5
- interface Vector {
6
- id: string;
7
- values: number[];
8
- metadata?: Record<string, any>;
9
- }
10
-
11
- interface SearchResult {
12
- id: string;
13
- score: number;
14
- metadata?: Record<string, any>;
15
- }
16
-
17
- interface IndexStats {
18
- vectorCount: number;
19
- dimension: number;
20
- indexType: string;
21
- memoryUsage?: number;
22
- }
23
-
24
- interface CreateIndexOptions {
25
- dimension: number;
26
- metric?: 'cosine' | 'euclidean' | 'dot';
27
- indexType?: 'flat' | 'hnsw';
28
- hnswConfig?: {
29
- m?: number;
30
- efConstruction?: number;
31
- };
32
- }
33
-
34
- interface SearchOptions {
35
- k?: number;
36
- ef?: number;
37
- filter?: Record<string, any>;
38
- }
39
-
40
- interface BatchInsertOptions {
41
- batchSize?: number;
42
- progressCallback?: (progress: number) => void;
43
- }
44
-
45
- /**
46
- * Backend information
47
- */
48
- interface BackendInfo {
49
- type: 'native' | 'wasm';
50
- version: string;
51
- features: string[];
52
- }
53
-
54
- /**
55
- * rUvector - High-performance vector database
56
- *
57
- * Smart loader that tries native bindings first, falls back to WASM
58
- */
59
-
60
- /**
61
- * VectorIndex class that wraps the backend
62
- */
63
- declare class VectorIndex {
64
- private index;
65
- constructor(options: CreateIndexOptions);
66
- insert(vector: Vector): Promise<void>;
67
- insertBatch(vectors: Vector[], options?: BatchInsertOptions): Promise<void>;
68
- search(query: number[], options?: SearchOptions): Promise<SearchResult[]>;
69
- get(id: string): Promise<Vector | null>;
70
- delete(id: string): Promise<boolean>;
71
- stats(): Promise<IndexStats>;
72
- save(path: string): Promise<void>;
73
- static load(path: string): Promise<VectorIndex>;
74
- clear(): Promise<void>;
75
- optimize(): Promise<void>;
76
- }
77
- /**
78
- * Utility functions
79
- */
80
- declare const Utils: {
81
- cosineSimilarity(a: number[], b: number[]): number;
82
- euclideanDistance(a: number[], b: number[]): number;
83
- normalize(vector: number[]): number[];
84
- randomVector(dimension: number): number[];
85
- };
86
- /**
87
- * Get backend information
88
- */
89
- declare function getBackendInfo(): BackendInfo;
90
- /**
91
- * Check if native bindings are available
92
- */
93
- declare function isNativeAvailable(): boolean;
94
-
95
- export { type BackendInfo, type BatchInsertOptions, type CreateIndexOptions, type IndexStats, type SearchOptions, type SearchResult, Utils, type Vector, VectorIndex, VectorIndex as default, getBackendInfo, isNativeAvailable };
package/dist/index.mjs DELETED
@@ -1,306 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
- var __commonJS = (cb, mod) => function __require2() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
-
12
- // ../node_modules/@ruvector/core/dist/index.cjs
13
- var require_dist = __commonJS({
14
- "../node_modules/@ruvector/core/dist/index.cjs"(exports, module) {
15
- "use strict";
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DistanceMetric = void 0;
18
- var node_os_1 = __require("os");
19
- var DistanceMetric;
20
- (function(DistanceMetric2) {
21
- DistanceMetric2["Euclidean"] = "euclidean";
22
- DistanceMetric2["Cosine"] = "cosine";
23
- DistanceMetric2["DotProduct"] = "dot";
24
- })(DistanceMetric || (exports.DistanceMetric = DistanceMetric = {}));
25
- function getPlatformPackage() {
26
- const plat = (0, node_os_1.platform)();
27
- const architecture = (0, node_os_1.arch)();
28
- const packageMap = {
29
- "linux-x64": "ruvector-core-linux-x64-gnu",
30
- "linux-arm64": "ruvector-core-linux-arm64-gnu",
31
- "darwin-x64": "ruvector-core-darwin-x64",
32
- "darwin-arm64": "ruvector-core-darwin-arm64",
33
- "win32-x64": "ruvector-core-win32-x64-msvc"
34
- };
35
- const key = `${plat}-${architecture}`;
36
- const packageName = packageMap[key];
37
- if (!packageName) {
38
- throw new Error(`Unsupported platform: ${plat}-${architecture}. Supported platforms: ${Object.keys(packageMap).join(", ")}`);
39
- }
40
- return packageName;
41
- }
42
- function loadNativeBinding() {
43
- const packageName = getPlatformPackage();
44
- try {
45
- return __require(packageName);
46
- } catch (error) {
47
- try {
48
- const plat = (0, node_os_1.platform)();
49
- const architecture = (0, node_os_1.arch)();
50
- const platformKey = `${plat}-${architecture}`;
51
- const platformMap = {
52
- "linux-x64": "linux-x64-gnu",
53
- "linux-arm64": "linux-arm64-gnu",
54
- "darwin-x64": "darwin-x64",
55
- "darwin-arm64": "darwin-arm64",
56
- "win32-x64": "win32-x64-msvc"
57
- };
58
- const localPath = `../platforms/${platformMap[platformKey]}/ruvector.node`;
59
- return __require(localPath);
60
- } catch (fallbackError) {
61
- throw new Error(`Failed to load native binding: ${error.message}
62
- Fallback also failed: ${fallbackError.message}
63
- Platform: ${(0, node_os_1.platform)()}-${(0, node_os_1.arch)()}
64
- Expected package: ${packageName}`);
65
- }
66
- }
67
- }
68
- var nativeBinding = loadNativeBinding();
69
- module.exports = nativeBinding;
70
- module.exports.default = nativeBinding;
71
- module.exports.DistanceMetric = DistanceMetric;
72
- }
73
- });
74
-
75
- // package.json
76
- var require_package = __commonJS({
77
- "package.json"(exports, module) {
78
- module.exports = {
79
- name: "ruvector",
80
- version: "0.1.21",
81
- description: "All-in-one vector database: HNSW search, Cypher queries, GNN layers, compression. Pinecone + Neo4j + PyTorch in one package.",
82
- main: "./dist/index.js",
83
- types: "./dist/index.d.ts",
84
- bin: {
85
- ruvector: "./bin/ruvector.js"
86
- },
87
- exports: {
88
- ".": {
89
- types: "./dist/index.d.ts",
90
- require: "./dist/index.js",
91
- import: "./dist/index.mjs"
92
- }
93
- },
94
- files: [
95
- "dist",
96
- "bin",
97
- "README.md"
98
- ],
99
- scripts: {
100
- build: "tsup src/index.ts --format cjs,esm --dts --clean",
101
- dev: "tsup src/index.ts --format cjs,esm --dts --watch",
102
- typecheck: "tsc --noEmit",
103
- prepublishOnly: "npm run build"
104
- },
105
- keywords: [
106
- "vector",
107
- "database",
108
- "embeddings",
109
- "similarity-search",
110
- "machine-learning",
111
- "ai",
112
- "rust",
113
- "napi",
114
- "wasm",
115
- "graph",
116
- "cypher",
117
- "neo4j",
118
- "gnn",
119
- "neural-network",
120
- "compression",
121
- "hnsw",
122
- "rag"
123
- ],
124
- author: "rUv",
125
- license: "MIT",
126
- repository: {
127
- type: "git",
128
- url: "https://github.com/ruvnet/ruvector.git",
129
- directory: "npm/ruvector"
130
- },
131
- dependencies: {
132
- commander: "^11.1.0",
133
- chalk: "^4.1.2",
134
- ora: "^5.4.1",
135
- "cli-table3": "^0.6.3",
136
- inquirer: "^8.2.6"
137
- },
138
- optionalDependencies: {
139
- "@ruvector/core": "^0.1.1",
140
- "@ruvector/graph-node": "^0.1.0",
141
- "@ruvector/graph-wasm": "^0.1.0",
142
- "@ruvector/gnn-node": "^0.1.0",
143
- "@ruvector/gnn-wasm": "^0.1.0"
144
- },
145
- devDependencies: {
146
- "@types/node": "^20.10.0",
147
- "@types/inquirer": "^8.2.10",
148
- typescript: "^5.3.3",
149
- tsup: "^8.0.0"
150
- },
151
- engines: {
152
- node: ">=16.0.0"
153
- }
154
- };
155
- }
156
- });
157
-
158
- // src/index.ts
159
- var backend;
160
- var backendType = "wasm";
161
- function loadBackend() {
162
- if (backend) {
163
- return backend;
164
- }
165
- try {
166
- backend = require_dist();
167
- backendType = "native";
168
- console.log("\u2713 Loaded native rUvector bindings");
169
- return backend;
170
- } catch (e) {
171
- try {
172
- backend = __require("@ruvector/wasm");
173
- backendType = "wasm";
174
- console.warn("\u26A0 Native bindings not available, using WASM fallback");
175
- console.warn(" For better performance, install @ruvector/core");
176
- return backend;
177
- } catch (wasmError) {
178
- throw new Error(
179
- `Failed to load rUvector backend. Please ensure either @ruvector/core or @ruvector/wasm is installed.
180
- Native error: ${e}
181
- WASM error: ${wasmError}`
182
- );
183
- }
184
- }
185
- }
186
- var VectorIndex = class _VectorIndex {
187
- constructor(options) {
188
- const backend2 = loadBackend();
189
- this.index = new backend2.VectorIndex(options);
190
- }
191
- async insert(vector) {
192
- return this.index.insert(vector);
193
- }
194
- async insertBatch(vectors, options) {
195
- if (this.index.insertBatch) {
196
- return this.index.insertBatch(vectors, options);
197
- }
198
- const batchSize = options?.batchSize || 1e3;
199
- const total = vectors.length;
200
- for (let i = 0; i < total; i += batchSize) {
201
- const batch = vectors.slice(i, Math.min(i + batchSize, total));
202
- await Promise.all(batch.map((v) => this.insert(v)));
203
- if (options?.progressCallback) {
204
- options.progressCallback(Math.min(i + batchSize, total) / total);
205
- }
206
- }
207
- }
208
- async search(query, options) {
209
- return this.index.search(query, options);
210
- }
211
- async get(id) {
212
- return this.index.get(id);
213
- }
214
- async delete(id) {
215
- return this.index.delete(id);
216
- }
217
- async stats() {
218
- return this.index.stats();
219
- }
220
- async save(path) {
221
- return this.index.save(path);
222
- }
223
- static async load(path) {
224
- const backend2 = loadBackend();
225
- const index = await backend2.VectorIndex.load(path);
226
- const wrapper = Object.create(_VectorIndex.prototype);
227
- wrapper.index = index;
228
- return wrapper;
229
- }
230
- async clear() {
231
- return this.index.clear();
232
- }
233
- async optimize() {
234
- if (this.index.optimize) {
235
- return this.index.optimize();
236
- }
237
- }
238
- };
239
- var Utils = {
240
- cosineSimilarity(a, b) {
241
- if (a.length !== b.length) {
242
- throw new Error("Vectors must have the same dimension");
243
- }
244
- let dotProduct = 0;
245
- let normA = 0;
246
- let normB = 0;
247
- for (let i = 0; i < a.length; i++) {
248
- dotProduct += a[i] * b[i];
249
- normA += a[i] * a[i];
250
- normB += b[i] * b[i];
251
- }
252
- return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
253
- },
254
- euclideanDistance(a, b) {
255
- if (a.length !== b.length) {
256
- throw new Error("Vectors must have the same dimension");
257
- }
258
- let sum = 0;
259
- for (let i = 0; i < a.length; i++) {
260
- const diff = a[i] - b[i];
261
- sum += diff * diff;
262
- }
263
- return Math.sqrt(sum);
264
- },
265
- normalize(vector) {
266
- const norm = Math.sqrt(vector.reduce((sum, val) => sum + val * val, 0));
267
- return vector.map((val) => val / norm);
268
- },
269
- randomVector(dimension) {
270
- const vector = new Array(dimension);
271
- for (let i = 0; i < dimension; i++) {
272
- vector[i] = Math.random() * 2 - 1;
273
- }
274
- return this.normalize(vector);
275
- }
276
- };
277
- function getBackendInfo() {
278
- loadBackend();
279
- const features = [];
280
- if (backendType === "native") {
281
- features.push("SIMD", "Multi-threading", "Memory-mapped I/O");
282
- } else {
283
- features.push("Browser-compatible", "No native dependencies");
284
- }
285
- return {
286
- type: backendType,
287
- version: require_package().version,
288
- features
289
- };
290
- }
291
- function isNativeAvailable() {
292
- try {
293
- __require.resolve("@ruvector/core");
294
- return true;
295
- } catch {
296
- return false;
297
- }
298
- }
299
- var index_default = VectorIndex;
300
- export {
301
- Utils,
302
- VectorIndex,
303
- index_default as default,
304
- getBackendInfo,
305
- isNativeAvailable
306
- };