| | "use strict"; |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
| | if (k2 === undefined) k2 = k; |
| | var desc = Object.getOwnPropertyDescriptor(m, k); |
| | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
| | desc = { enumerable: true, get: function() { return m[k]; } }; |
| | } |
| | Object.defineProperty(o, k2, desc); |
| | }) : (function(o, m, k, k2) { |
| | if (k2 === undefined) k2 = k; |
| | o[k2] = m[k]; |
| | })); |
| | var __exportStar = (this && this.__exportStar) || function(m, exports) { |
| | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); |
| | }; |
| | Object.defineProperty(exports, "__esModule", { value: true }); |
| | exports.NativeVectorDb = exports.VectorDB = exports.VectorDb = void 0; |
| | exports.getImplementationType = getImplementationType; |
| | exports.isNative = isNative; |
| | exports.isRvf = isRvf; |
| | exports.isWasm = isWasm; |
| | exports.getVersion = getVersion; |
| | __exportStar(require("./types"), exports); |
| | |
| | __exportStar(require("./core"), exports); |
| | __exportStar(require("./services"), exports); |
| | let implementation; |
| | let implementationType = 'wasm'; |
| | |
| | const rvfRequested = process.env.RUVECTOR_BACKEND === 'rvf' || |
| | process.argv.includes('--backend') && process.argv[process.argv.indexOf('--backend') + 1] === 'rvf'; |
| | if (rvfRequested) { |
| | |
| | try { |
| | implementation = require('@ruvector/rvf'); |
| | implementationType = 'rvf'; |
| | } |
| | catch (e) { |
| | throw new Error('@ruvector/rvf is not installed.\n' + |
| | ' Run: npm install @ruvector/rvf\n' + |
| | ' The --backend rvf flag requires this package.'); |
| | } |
| | } |
| | else { |
| | try { |
| | |
| | implementation = require('@ruvector/core'); |
| | implementationType = 'native'; |
| | |
| | if (typeof implementation.VectorDb !== 'function') { |
| | throw new Error('Native module loaded but VectorDb class not found'); |
| | } |
| | } |
| | catch (e) { |
| | |
| | try { |
| | implementation = require('@ruvector/rvf'); |
| | implementationType = 'rvf'; |
| | } |
| | catch (rvfErr) { |
| | |
| | console.warn('[RuVector] Native module not available:', e.message); |
| | console.warn('[RuVector] RVF module not available:', rvfErr.message); |
| | console.warn('[RuVector] Vector operations will be limited. Install @ruvector/core or @ruvector/rvf for full functionality.'); |
| | |
| | implementation = { |
| | VectorDb: class StubVectorDb { |
| | constructor() { |
| | console.warn('[RuVector] Using stub VectorDb - install @ruvector/core for native performance'); |
| | } |
| | async insert() { return 'stub-id-' + Date.now(); } |
| | async insertBatch(entries) { return entries.map(() => 'stub-id-' + Date.now()); } |
| | async search() { return []; } |
| | async delete() { return true; } |
| | async get() { return null; } |
| | async len() { return 0; } |
| | async isEmpty() { return true; } |
| | } |
| | }; |
| | implementationType = 'wasm'; |
| | } |
| | } |
| | } |
| | |
| | |
| | |
| | function getImplementationType() { |
| | return implementationType; |
| | } |
| | |
| | |
| | |
| | function isNative() { |
| | return implementationType === 'native'; |
| | } |
| | |
| | |
| | |
| | function isRvf() { |
| | return implementationType === 'rvf'; |
| | } |
| | |
| | |
| | |
| | function isWasm() { |
| | return implementationType === 'wasm'; |
| | } |
| | |
| | |
| | |
| | function getVersion() { |
| | const pkg = require('../package.json'); |
| | return { |
| | version: pkg.version, |
| | implementation: implementationType |
| | }; |
| | } |
| | |
| | |
| | |
| | class VectorDBWrapper { |
| | constructor(options) { |
| | |
| | if (options && options.dimension && !options.dimensions) { |
| | options = { ...options, dimensions: options.dimension }; |
| | delete options.dimension; |
| | } |
| | this.db = new implementation.VectorDb(options); |
| | } |
| | |
| | |
| | |
| | async insert(entryOrVector, metadata) { |
| | |
| | let entry; |
| | if (entryOrVector instanceof Float32Array || Array.isArray(entryOrVector)) { |
| | entry = { vector: entryOrVector, metadata: metadata }; |
| | } else { |
| | entry = entryOrVector; |
| | } |
| | const nativeEntry = { |
| | id: entry.id, |
| | vector: entry.vector instanceof Float32Array ? entry.vector : new Float32Array(entry.vector), |
| | }; |
| | |
| | if (entry.metadata) { |
| | nativeEntry.metadata = JSON.stringify(entry.metadata); |
| | } |
| | return this.db.insert(nativeEntry); |
| | } |
| | |
| | |
| | |
| | async insertBatch(entries) { |
| | const nativeEntries = entries.map(entry => ({ |
| | id: entry.id, |
| | vector: entry.vector instanceof Float32Array ? entry.vector : new Float32Array(entry.vector), |
| | metadata: entry.metadata ? JSON.stringify(entry.metadata) : undefined, |
| | })); |
| | return this.db.insertBatch(nativeEntries); |
| | } |
| | |
| | |
| | |
| | async search(queryOrVector, k, efSearch) { |
| | |
| | let query; |
| | if (queryOrVector instanceof Float32Array || Array.isArray(queryOrVector)) { |
| | query = { vector: queryOrVector, k: k || 10, efSearch: efSearch }; |
| | } else { |
| | query = queryOrVector; |
| | } |
| | const nativeQuery = { |
| | vector: query.vector instanceof Float32Array ? query.vector : new Float32Array(query.vector), |
| | k: query.k, |
| | efSearch: query.efSearch, |
| | }; |
| | |
| | if (query.filter) { |
| | nativeQuery.filter = JSON.stringify(query.filter); |
| | } |
| | const results = await this.db.search(nativeQuery); |
| | |
| | return results.map((r) => ({ |
| | id: r.id, |
| | score: r.score, |
| | vector: r.vector, |
| | metadata: r.metadata ? JSON.parse(r.metadata) : undefined, |
| | })); |
| | } |
| | |
| | |
| | |
| | async get(id) { |
| | const entry = await this.db.get(id); |
| | if (!entry) |
| | return null; |
| | return { |
| | id: entry.id, |
| | vector: entry.vector, |
| | metadata: entry.metadata ? JSON.parse(entry.metadata) : undefined, |
| | }; |
| | } |
| | |
| | |
| | |
| | async delete(id) { |
| | return this.db.delete(id); |
| | } |
| | |
| | |
| | |
| | async len() { |
| | return this.db.len(); |
| | } |
| | |
| | |
| | |
| | async isEmpty() { |
| | return this.db.isEmpty(); |
| | } |
| | } |
| | |
| | exports.VectorDb = VectorDBWrapper; |
| | exports.VectorDB = VectorDBWrapper; |
| | |
| | exports.NativeVectorDb = implementation.VectorDb; |
| | |
| | exports.default = implementation; |
| |
|