ruvector 0.1.20 → 0.1.21

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