ruvector 0.2.13 → 0.2.15

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,144 @@
1
+ /**
2
+ * Vector entry representing a document with its embedding
3
+ */
4
+ export interface VectorEntry {
5
+ /** Unique identifier for the vector */
6
+ id: string;
7
+ /** Vector embedding (array of floats) */
8
+ vector: number[];
9
+ /** Optional metadata associated with the vector */
10
+ metadata?: Record<string, any>;
11
+ }
12
+ /**
13
+ * Search query parameters
14
+ */
15
+ export interface SearchQuery {
16
+ /** Query vector to search for */
17
+ vector: number[];
18
+ /** Number of results to return */
19
+ k?: number;
20
+ /** Optional metadata filters */
21
+ filter?: Record<string, any>;
22
+ /** Minimum similarity threshold (0-1) */
23
+ threshold?: number;
24
+ }
25
+ /**
26
+ * Search result containing matched vector and similarity score
27
+ */
28
+ export interface SearchResult {
29
+ /** ID of the matched vector */
30
+ id: string;
31
+ /** Similarity score (0-1, higher is better) */
32
+ score: number;
33
+ /** Vector data */
34
+ vector: number[];
35
+ /** Associated metadata */
36
+ metadata?: Record<string, any>;
37
+ }
38
+ /**
39
+ * Database configuration options
40
+ */
41
+ export interface DbOptions {
42
+ /** Vector dimension size */
43
+ dimension: number;
44
+ /** Distance metric to use */
45
+ metric?: 'cosine' | 'euclidean' | 'dot';
46
+ /** Path to persist database */
47
+ path?: string;
48
+ /** Enable auto-persistence */
49
+ autoPersist?: boolean;
50
+ /** HNSW index parameters */
51
+ hnsw?: {
52
+ /** Maximum number of connections per layer */
53
+ m?: number;
54
+ /** Size of the dynamic candidate list */
55
+ efConstruction?: number;
56
+ /** Size of the dynamic candidate list for search */
57
+ efSearch?: number;
58
+ };
59
+ }
60
+ /**
61
+ * Database statistics
62
+ */
63
+ export interface DbStats {
64
+ /** Total number of vectors */
65
+ count: number;
66
+ /** Vector dimension */
67
+ dimension: number;
68
+ /** Distance metric */
69
+ metric: string;
70
+ /** Memory usage in bytes */
71
+ memoryUsage?: number;
72
+ /** Index type */
73
+ indexType?: string;
74
+ }
75
+ /**
76
+ * Main VectorDB class interface
77
+ */
78
+ export interface VectorDB {
79
+ /**
80
+ * Create a new vector database
81
+ * @param options Database configuration
82
+ */
83
+ new (options: DbOptions): VectorDB;
84
+ /**
85
+ * Insert a single vector
86
+ * @param entry Vector entry to insert
87
+ */
88
+ insert(entry: VectorEntry): void;
89
+ /**
90
+ * Insert multiple vectors in batch
91
+ * @param entries Array of vector entries
92
+ */
93
+ insertBatch(entries: VectorEntry[]): void;
94
+ /**
95
+ * Search for similar vectors
96
+ * @param query Search query parameters
97
+ * @returns Array of search results
98
+ */
99
+ search(query: SearchQuery): SearchResult[];
100
+ /**
101
+ * Get vector by ID
102
+ * @param id Vector ID
103
+ * @returns Vector entry or null
104
+ */
105
+ get(id: string): VectorEntry | null;
106
+ /**
107
+ * Delete vector by ID
108
+ * @param id Vector ID
109
+ * @returns true if deleted, false if not found
110
+ */
111
+ delete(id: string): boolean;
112
+ /**
113
+ * Update vector metadata
114
+ * @param id Vector ID
115
+ * @param metadata New metadata
116
+ */
117
+ updateMetadata(id: string, metadata: Record<string, any>): void;
118
+ /**
119
+ * Get database statistics
120
+ */
121
+ stats(): DbStats;
122
+ /**
123
+ * Save database to disk
124
+ * @param path Optional path (uses configured path if not provided)
125
+ */
126
+ save(path?: string): void;
127
+ /**
128
+ * Load database from disk
129
+ * @param path Path to database file
130
+ */
131
+ load(path: string): void;
132
+ /**
133
+ * Clear all vectors from database
134
+ */
135
+ clear(): void;
136
+ /**
137
+ * Build HNSW index for faster search
138
+ */
139
+ buildIndex(): void;
140
+ /**
141
+ * Optimize database (rebuild indices, compact storage)
142
+ */
143
+ optimize(): void;
144
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"native-worker.d.ts","sourceRoot":"","sources":["../../src/workers/native-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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hC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB3B;;OAEG;IACG,GAAG,CAAC,UAAU,GAAE,MAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAiD1D;;OAEG;YACW,YAAY;IAmC1B;;OAEG;YACW,kBAAkB;IAsBhC;;OAEG;YACW,sBAAsB;IAoCpC;;OAEG;YACW,wBAAwB;IAgDtC;;OAEG;YACW,kBAAkB;IA8BhC;;OAEG;YACW,qBAAqB;IAoBnC;;OAEG;YACW,iBAAiB;IAuB/B;;OAEG;YACW,uBAAuB;IA0BrC;;OAEG;YACW,kBAAkB;IAqBhC;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAsB3B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,SAAqB,GAAG,YAAY,CAW5E;AAED,wBAAgB,oBAAoB,CAAC,IAAI,SAAkB,GAAG,YAAY,CAczE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,SAAoB,GAAG,YAAY,CAa3E"}
@@ -49,7 +49,49 @@ exports.createAnalysisWorker = createAnalysisWorker;
49
49
  exports.createLearningWorker = createLearningWorker;
50
50
  const fs = __importStar(require("fs"));
51
51
  const path = __importStar(require("path"));
52
- const glob_1 = require("glob");
52
+ let cachedGlob = null;
53
+ // Fallback glob implementation using fs
54
+ function createFallbackGlob() {
55
+ return async (pattern, options) => {
56
+ const cwd = options?.cwd || process.cwd();
57
+ const results = [];
58
+ const walk = (dir) => {
59
+ try {
60
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
61
+ for (const entry of entries) {
62
+ const fullPath = path.join(dir, entry.name);
63
+ if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
64
+ walk(fullPath);
65
+ }
66
+ else if (entry.isFile()) {
67
+ results.push(path.relative(cwd, fullPath));
68
+ }
69
+ }
70
+ }
71
+ catch { /* ignore permission errors */ }
72
+ };
73
+ walk(cwd);
74
+ // Simple pattern matching for *.ext patterns
75
+ const ext = pattern.match(/\*\.(\w+)$/)?.[1];
76
+ return ext ? results.filter(f => f.endsWith('.' + ext)) : results;
77
+ };
78
+ }
79
+ async function getGlob() {
80
+ if (cachedGlob)
81
+ return cachedGlob;
82
+ try {
83
+ // Dynamic import - may fail if glob not installed
84
+ const mod = await Function('return import("glob")')();
85
+ if (mod && typeof mod.glob === 'function') {
86
+ cachedGlob = mod.glob;
87
+ return cachedGlob;
88
+ }
89
+ }
90
+ catch { /* glob not available */ }
91
+ // Fallback to simple implementation
92
+ cachedGlob = createFallbackGlob();
93
+ return cachedGlob;
94
+ }
53
95
  const onnx_embedder_1 = require("../core/onnx-embedder");
54
96
  const security_1 = require("../analysis/security");
55
97
  const complexity_1 = require("../analysis/complexity");
@@ -184,13 +226,14 @@ class NativeWorker {
184
226
  const patterns = config?.patterns || ['**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx'];
185
227
  const exclude = config?.exclude || ['**/node_modules/**', '**/dist/**', '**/.git/**'];
186
228
  const files = [];
229
+ const glob = await getGlob();
187
230
  for (const pattern of patterns) {
188
- const matches = await (0, glob_1.glob)(pattern, {
231
+ const matches = await glob(pattern, {
189
232
  cwd: context.targetPath,
190
233
  ignore: exclude,
191
234
  nodir: true,
192
235
  });
193
- files.push(...matches.map(f => path.join(context.targetPath, f)));
236
+ files.push(...matches.map((f) => path.join(context.targetPath, f)));
194
237
  }
195
238
  this.stats.filesAnalyzed = files.length;
196
239
  return { ...context, files };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ruvector",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "High-performance vector database for Node.js with automatic native/WASM fallback",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "ruvector": "./bin/cli.js"
9
9
  },
10
10
  "scripts": {
11
- "build": "tsc && cp src/core/onnx/pkg/package.json dist/core/onnx/pkg/",
11
+ "build": "tsc && cp -r src/core/onnx dist/core/",
12
12
  "prepublishOnly": "npm run build",
13
13
  "test": "node test/integration.js && node test/cli-commands.js"
14
14
  },
@@ -70,12 +70,14 @@
70
70
  "@ruvector/sona": "^0.1.4",
71
71
  "chalk": "^4.1.2",
72
72
  "commander": "^11.1.0",
73
+ "glob": "^10.3.10",
73
74
  "ora": "^5.4.1"
74
75
  },
75
76
  "optionalDependencies": {
76
77
  "@ruvector/rvf": "^0.1.0"
77
78
  },
78
79
  "devDependencies": {
80
+ "@types/glob": "^8.1.0",
79
81
  "@types/node": "^20.10.5",
80
82
  "typescript": "^5.3.3"
81
83
  },