@omendb/omendb 0.0.20 → 0.0.22

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.
Files changed (3) hide show
  1. package/index.d.ts +257 -271
  2. package/index.js +8 -4
  3. package/package.json +6 -6
package/index.d.ts CHANGED
@@ -1,229 +1,219 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
3
  export declare class VectorDatabase {
4
- /**
5
- * Insert or update vectors.
6
- *
7
- * Accepts an array of items with id, vector, and optional metadata.
8
- */
9
- set(items: Array<VectorItem>): Array<number>;
10
- /**
11
- * Search for k nearest neighbors.
12
- *
13
- * @param query - Query vector (number[] or Float32Array)
14
- * @param k - Number of results to return
15
- * @param ef - Optional search width override
16
- * @param filter - Optional metadata filter (e.g., {category: "foo"} or {price: {$gt: 10}})
17
- * @param maxDistance - Optional max distance threshold (filter out distant results)
18
- * @returns Array of {id, distance, metadata}
19
- */
20
- search(
21
- query: Array<number> | Float32Array,
22
- k: number,
23
- ef?: number | undefined | null,
24
- filter?: Record<string, unknown> | undefined,
25
- maxDistance?: number | undefined | null,
26
- ): Array<SearchResult>;
27
- /**
28
- * Batch search with parallel execution (async).
29
- *
30
- * Runs searches in parallel using rayon, returns Promise.
31
- */
32
- searchBatch(
33
- queries: Array<Array<number> | Float32Array>,
34
- k: number,
35
- ef?: number | undefined | null,
36
- ): Promise<Array<Array<SearchResult>>>;
37
- /** Get a vector by ID. */
38
- get(id: string): GetResult | null;
39
- /**
40
- * Delete vectors by ID.
41
- *
42
- * @returns Number of vectors deleted
43
- */
44
- delete(ids: Array<string>): number;
45
- /**
46
- * Delete vectors matching a metadata filter.
47
- *
48
- * Evaluates the filter against all vectors and deletes those that match.
49
- * Uses the same MongoDB-style filter syntax as search().
50
- *
51
- * @param filter - MongoDB-style metadata filter
52
- * @returns Number of vectors deleted
53
- *
54
- * @example
55
- * ```javascript
56
- * // Delete by equality
57
- * db.deleteWhere({ status: "archived" });
58
- *
59
- * // Delete with comparison
60
- * db.deleteWhere({ score: { $lt: 0.5 } });
61
- *
62
- * // Complex filter
63
- * db.deleteWhere({ $and: [{ type: "draft" }, { age: { $gt: 30 } }] });
64
- * ```
65
- */
66
- deleteWhere(filter: Record<string, unknown>): number;
67
- /**
68
- * Count vectors, optionally filtered by metadata.
69
- *
70
- * Without a filter, returns total count (same as db.length).
71
- * With a filter, returns count of vectors matching the filter.
72
- *
73
- * @param filter - Optional MongoDB-style metadata filter
74
- * @returns Number of vectors (matching filter if provided)
75
- *
76
- * @example
77
- * ```javascript
78
- * // Total count
79
- * const total = db.count();
80
- *
81
- * // Filtered count
82
- * const active = db.count({ status: "active" });
83
- *
84
- * // With comparison operators
85
- * const highScore = db.count({ score: { $gte: 0.8 } });
86
- * ```
87
- */
88
- count(filter?: Record<string, unknown> | undefined): number;
89
- /** Update a vector's data and/or metadata. */
90
- update(
91
- id: string,
92
- vector: Array<number> | Float32Array,
93
- metadata?: Record<string, unknown> | undefined,
94
- ): void;
95
- /** Get number of vectors in database. */
96
- get length(): number;
97
- /** Get vector dimensions of this database. */
98
- get dimensions(): number;
99
- /** Check if database is empty. */
100
- isEmpty(): boolean;
101
- /** Get database statistics. */
102
- stats(): StatsResult;
103
- /** Get current ef_search value. */
104
- get efSearch(): number;
105
- /** Set ef_search value. */
106
- set efSearch(efSearch: number);
107
- /**
108
- * Get or create a named collection.
109
- *
110
- * Collection handles share state - changes made through one handle
111
- * are immediately visible through another (no flush required).
112
- */
113
- collection(name: string): VectorDatabase;
114
- /** List all collections. */
115
- collections(): Array<string>;
116
- /** Delete a collection. */
117
- deleteCollection(name: string): void;
118
- /**
119
- * Enable text search for hybrid (vector + text) search.
120
- *
121
- * Must be called before using setWithText() or hybridSearch().
122
- */
123
- enableTextSearch(): void;
124
- /** Check if text search is enabled. */
125
- get hasTextSearch(): boolean;
126
- /**
127
- * Set vectors with associated text for hybrid search.
128
- *
129
- * @param items - Array of {id, vector, text, metadata?}
130
- * @returns Array of internal indices
131
- */
132
- setWithText(items: Array<VectorItemWithText>): Array<number>;
133
- /**
134
- * Search using text only (BM25 scoring).
135
- *
136
- * @param query - Text query
137
- * @param k - Number of results
138
- * @returns Array of {id, score, metadata}
139
- */
140
- textSearch(query: string, k: number): Array<TextSearchResult>;
141
- /**
142
- * Hybrid search combining vector similarity and text relevance.
143
- *
144
- * Uses Reciprocal Rank Fusion (RRF) to combine HNSW and BM25 results.
145
- *
146
- * @param queryVector - Query embedding
147
- * @param queryText - Text query for BM25
148
- * @param k - Number of results
149
- * @param filter - Optional metadata filter
150
- * @param alpha - Weight for vector vs text (0.0=text only, 1.0=vector only, default=0.5)
151
- * @param rrfK - RRF constant (default=60, higher reduces rank influence)
152
- * @param subscores - Return separate keyword_score and semantic_score (default: false)
153
- * @returns Array of {id, score, metadata, keyword_score?, semantic_score?}
154
- */
155
- hybridSearch(
156
- queryVector: Array<number> | Float32Array,
157
- queryText: string,
158
- k: number,
159
- filter?: Record<string, unknown> | undefined,
160
- alpha?: number | undefined | null,
161
- rrfK?: number | undefined | null,
162
- subscores?: boolean | undefined | null,
163
- ): Array<HybridSearchResult>;
164
- /**
165
- * Flush pending changes to disk.
166
- *
167
- * For hybrid search, this commits text index changes.
168
- */
169
- flush(): void;
170
- /**
171
- * Optimize index for cache-efficient search.
172
- *
173
- * Reorders nodes for better memory locality, improving search performance by 6-40%.
174
- * Call after inserting a large batch of vectors.
175
- *
176
- * @returns Number of nodes reordered
177
- */
178
- optimize(): number;
179
- /** Merge another database into this one. */
180
- mergeFrom(other: VectorDatabase): number;
181
- /**
182
- * List all vector IDs (without loading vector data).
183
- *
184
- * Efficient way to get all IDs for iteration, export, or debugging.
185
- * @returns Array of all vector IDs in the database
186
- */
187
- ids(): Array<string>;
188
- /**
189
- * Get all items as array of {id, vector, metadata}.
190
- *
191
- * Returns all vectors with their IDs and metadata.
192
- * For large datasets, consider using ids() and get() in batches.
193
- */
194
- items(): Array<GetResult>;
195
- /**
196
- * Check if an ID exists in the database.
197
- *
198
- * @param id - Vector ID to check
199
- * @returns true if ID exists and is not deleted
200
- */
201
- exists(id: string): boolean;
202
- /**
203
- * Get multiple vectors by ID.
204
- *
205
- * Batch version of get(). More efficient than calling get() in a loop.
206
- *
207
- * @param ids - Array of vector IDs to retrieve
208
- * @returns Array of results in same order as input, null for missing IDs
209
- */
210
- getMany(ids: Array<string>): Array<GetResult | undefined | null>;
4
+ /**
5
+ * Insert or update vectors.
6
+ *
7
+ * Accepts an array of items with id, vector, and optional metadata.
8
+ */
9
+ set(items: Array<VectorItem>): Array<number>
10
+ /**
11
+ * Search for k nearest neighbors.
12
+ *
13
+ * @param query - Query vector (number[] or Float32Array)
14
+ * @param k - Number of results to return
15
+ * @param ef - Optional search width override
16
+ * @param filter - Optional metadata filter (e.g., {category: "foo"} or {price: {$gt: 10}})
17
+ * @param maxDistance - Optional max distance threshold (filter out distant results)
18
+ * @returns Array of {id, distance, metadata}
19
+ */
20
+ search(query: Array<number> | Float32Array, k: number, ef?: number | undefined | null, filter?: Record<string, unknown> | undefined, maxDistance?: number | undefined | null): Array<SearchResult>
21
+ /**
22
+ * Batch search with parallel execution (async).
23
+ *
24
+ * Runs searches in parallel using rayon on a blocking thread pool,
25
+ * keeping the Node.js event loop free.
26
+ */
27
+ searchBatch(queries: Array<Array<number> | Float32Array>, k: number, ef?: number | undefined | null): Promise<Array<Array<SearchResult>>>
28
+ /** Get a vector by ID. */
29
+ get(id: string): GetResult | null
30
+ /**
31
+ * Delete vectors by ID.
32
+ *
33
+ * @returns Number of vectors deleted
34
+ */
35
+ delete(ids: Array<string>): number
36
+ /**
37
+ * Delete vectors matching a metadata filter.
38
+ *
39
+ * Evaluates the filter against all vectors and deletes those that match.
40
+ * Uses the same MongoDB-style filter syntax as search().
41
+ *
42
+ * @param filter - MongoDB-style metadata filter
43
+ * @returns Number of vectors deleted
44
+ *
45
+ * @example
46
+ * ```javascript
47
+ * // Delete by equality
48
+ * db.deleteByFilter({ status: "archived" });
49
+ *
50
+ * // Delete with comparison
51
+ * db.deleteByFilter({ score: { $lt: 0.5 } });
52
+ *
53
+ * // Complex filter
54
+ * db.deleteByFilter({ $and: [{ type: "draft" }, { age: { $gt: 30 } }] });
55
+ * ```
56
+ */
57
+ deleteByFilter(filter: Record<string, unknown>): number
58
+ /**
59
+ * Count vectors, optionally filtered by metadata.
60
+ *
61
+ * Without a filter, returns total count (same as db.length).
62
+ * With a filter, returns count of vectors matching the filter.
63
+ *
64
+ * @param filter - Optional MongoDB-style metadata filter
65
+ * @returns Number of vectors (matching filter if provided)
66
+ *
67
+ * @example
68
+ * ```javascript
69
+ * // Total count
70
+ * const total = db.count();
71
+ *
72
+ * // Filtered count
73
+ * const active = db.count({ status: "active" });
74
+ *
75
+ * // With comparison operators
76
+ * const highScore = db.count({ score: { $gte: 0.8 } });
77
+ * ```
78
+ */
79
+ count(filter?: Record<string, unknown> | undefined): number
80
+ /** Update a vector's data and/or metadata. */
81
+ update(id: string, vector: Array<number> | Float32Array, metadata?: Record<string, unknown> | undefined): void
82
+ /** Get number of vectors in database. */
83
+ get length(): number
84
+ /** Get vector dimensions of this database. */
85
+ get dimensions(): number
86
+ /** Check if database is empty. */
87
+ isEmpty(): boolean
88
+ /** Get database statistics. */
89
+ stats(): StatsResult
90
+ /** Get current ef_search value. */
91
+ get efSearch(): number
92
+ /** Set ef_search value. */
93
+ set efSearch(efSearch: number)
94
+ /**
95
+ * Get or create a named collection.
96
+ *
97
+ * Collection handles share state - changes made through one handle
98
+ * are immediately visible through another (no flush required).
99
+ */
100
+ collection(name: string): VectorDatabase
101
+ /** List all collections. */
102
+ collections(): Array<string>
103
+ /** Delete a collection. */
104
+ deleteCollection(name: string): void
105
+ /**
106
+ * Enable text search for hybrid (vector + text) search.
107
+ *
108
+ * Must be called before using setWithText() or hybridSearch().
109
+ */
110
+ enableTextSearch(): void
111
+ /** Check if text search is enabled. */
112
+ get hasTextSearch(): boolean
113
+ /**
114
+ * Set vectors with associated text for hybrid search.
115
+ *
116
+ * @param items - Array of {id, vector, text, metadata?}
117
+ * @returns Array of internal indices
118
+ */
119
+ setWithText(items: Array<VectorItemWithText>): Array<number>
120
+ /**
121
+ * Search using text only (BM25 scoring).
122
+ *
123
+ * @param query - Text query
124
+ * @param k - Number of results
125
+ * @returns Array of {id, score, metadata}
126
+ */
127
+ textSearch(query: string, k: number): Array<TextSearchResult>
128
+ /**
129
+ * Hybrid search combining vector similarity and text relevance.
130
+ *
131
+ * Uses Reciprocal Rank Fusion (RRF) to combine HNSW and BM25 results.
132
+ *
133
+ * @param queryVector - Query embedding
134
+ * @param queryText - Text query for BM25
135
+ * @param k - Number of results
136
+ * @param filter - Optional metadata filter
137
+ * @param alpha - Weight for vector vs text (0.0=text only, 1.0=vector only, default=0.5)
138
+ * @param rrfK - RRF constant (default=60, higher reduces rank influence)
139
+ * @param subscores - Return separate keyword_score and semantic_score (default: false)
140
+ * @returns Array of {id, score, metadata, keyword_score?, semantic_score?}
141
+ */
142
+ hybridSearch(queryVector: Array<number> | Float32Array, queryText: string, k: number, filter?: Record<string, unknown> | undefined, alpha?: number | undefined | null, rrfK?: number | undefined | null, subscores?: boolean | undefined | null): Array<HybridSearchResult>
143
+ /**
144
+ * Flush pending changes to disk.
145
+ *
146
+ * For hybrid search, this commits text index changes.
147
+ */
148
+ flush(): void
149
+ /**
150
+ * Close the database and release file locks.
151
+ *
152
+ * After calling close(), the database is no longer usable.
153
+ * Any subsequent operations will fail or return empty results.
154
+ *
155
+ * This is useful when you need to reopen the same database path
156
+ * in the same process, since JavaScript doesn't have deterministic
157
+ * object destruction like Python's `del`.
158
+ */
159
+ close(): void
160
+ /**
161
+ * Optimize index for cache-efficient search.
162
+ *
163
+ * Reorders nodes for better memory locality, improving search performance by 6-40%.
164
+ * Call after inserting a large batch of vectors.
165
+ *
166
+ * @returns Number of nodes reordered
167
+ */
168
+ optimize(): number
169
+ /** Merge another database into this one. */
170
+ mergeFrom(other: VectorDatabase): number
171
+ /**
172
+ * List all vector IDs (without loading vector data).
173
+ *
174
+ * Efficient way to get all IDs for iteration, export, or debugging.
175
+ * @returns Array of all vector IDs in the database
176
+ */
177
+ ids(): Array<string>
178
+ /**
179
+ * Get all items as array of {id, vector, metadata}.
180
+ *
181
+ * Returns all vectors with their IDs and metadata.
182
+ * For large datasets, consider using ids() and get() in batches.
183
+ */
184
+ items(): Array<GetResult>
185
+ /**
186
+ * Check if an ID exists in the database.
187
+ *
188
+ * @param id - Vector ID to check
189
+ * @returns true if ID exists and is not deleted
190
+ */
191
+ exists(id: string): boolean
192
+ /**
193
+ * Get multiple vectors by ID.
194
+ *
195
+ * Batch version of get(). More efficient than calling get() in a loop.
196
+ *
197
+ * @param ids - Array of vector IDs to retrieve
198
+ * @returns Array of results in same order as input, null for missing IDs
199
+ */
200
+ getBatch(ids: Array<string>): Array<GetResult | undefined | null>
211
201
  }
212
202
 
213
203
  export interface GetResult {
214
- id: string;
215
- vector: Float32Array;
216
- metadata: Record<string, unknown>;
204
+ id: string
205
+ vector: Float32Array
206
+ metadata: Record<string, unknown>
217
207
  }
218
208
 
219
209
  export interface HybridSearchResult {
220
- id: string;
221
- score: number;
222
- metadata: Record<string, unknown>;
223
- /** BM25 keyword matching score (null if document only matched vector search) */
224
- keywordScore?: number;
225
- /** Vector similarity score (null if document only matched text search) */
226
- semanticScore?: number;
210
+ id: string
211
+ score: number
212
+ metadata: Record<string, unknown>
213
+ /** BM25 keyword matching score (null if document only matched vector search) */
214
+ keywordScore?: number
215
+ /** Vector similarity score (null if document only matched text search) */
216
+ semanticScore?: number
227
217
  }
228
218
 
229
219
  /**
@@ -261,10 +251,7 @@ export interface HybridSearchResult {
261
251
  * });
262
252
  * ```
263
253
  */
264
- export declare function open(
265
- path: string,
266
- options?: OpenOptions | undefined | null,
267
- ): VectorDatabase;
254
+ export declare function open(path: string, options?: OpenOptions | undefined | null): VectorDatabase
268
255
 
269
256
  /**
270
257
  * Configuration options for opening a vector database.
@@ -280,69 +267,68 @@ export declare function open(
280
267
  * - metric: "l2" (distance metric: "l2", "euclidean", "cosine", "dot", "ip")
281
268
  */
282
269
  export interface OpenOptions {
283
- /** Vector dimensions (default: 128, auto-detected on first insert) */
284
- dimensions?: number;
285
- /** HNSW M parameter: neighbors per node (default: 16, range: 4-64) */
286
- m?: number;
287
- /** HNSW ef_construction: build quality (default: 100, must be >= m) */
288
- efConstruction?: number;
289
- /** HNSW ef_search: search quality/speed tradeoff (default: 100) */
290
- efSearch?: number;
291
- /**
292
- * Quantization mode (default: null = no quantization)
293
- * - true or "sq8": SQ8 4x compression, ~99% recall (RECOMMENDED)
294
- * - "rabitq": RaBitQ 8x compression, ~98% recall
295
- * - "binary": Binary 32x compression, ~95% recall
296
- * - 2, 4, 8: RaBitQ with specific bits (legacy)
297
- */
298
- quantization?: boolean | string | number | null | undefined;
299
- /**
300
- * Rescore candidates with exact distance (default: true when quantization enabled)
301
- * Set to false for maximum speed at the cost of ~20% recall
302
- */
303
- rescore?: boolean;
304
- /**
305
- * Oversampling factor for rescoring (default: 3.0)
306
- * Fetches k*oversample candidates then reranks to return top k
307
- */
308
- oversample?: number;
309
- /** Distance metric: "l2"/"euclidean" (default), "cosine", "dot"/"ip" */
310
- metric?: string;
270
+ /** Vector dimensions (default: 128, auto-detected on first insert) */
271
+ dimensions?: number
272
+ /** HNSW M parameter: neighbors per node (default: 16, range: 4-64) */
273
+ m?: number
274
+ /** HNSW ef_construction: build quality (default: 100, must be >= m) */
275
+ efConstruction?: number
276
+ /** HNSW ef_search: search quality/speed tradeoff (default: 100) */
277
+ efSearch?: number
278
+ /**
279
+ * Quantization mode (default: null = no quantization)
280
+ * - true or "sq8": SQ8 4x compression, ~99% recall (RECOMMENDED)
281
+ * - "rabitq": RaBitQ 8x compression, ~98% recall
282
+ * - "binary": Binary 32x compression, ~95% recall
283
+ * - 2, 4, 8: RaBitQ with specific bits (legacy)
284
+ */
285
+ quantization?: boolean | string | number | null | undefined
286
+ /**
287
+ * Rescore candidates with exact distance (default: true when quantization enabled)
288
+ * Set to false for maximum speed at the cost of ~20% recall
289
+ */
290
+ rescore?: boolean
291
+ /**
292
+ * Oversampling factor for rescoring (default: 3.0)
293
+ * Fetches k*oversample candidates then reranks to return top k
294
+ */
295
+ oversample?: number
296
+ /** Distance metric: "l2"/"euclidean" (default), "cosine", "dot"/"ip" */
297
+ metric?: string
311
298
  }
312
299
 
313
300
  export interface SearchResult {
314
- id: string;
315
- distance: number;
316
- /** Metadata as JSON (using serde-json feature) */
317
- metadata: Record<string, unknown>;
301
+ id: string
302
+ distance: number
303
+ /** Metadata as JSON (using serde-json feature) */
304
+ metadata: Record<string, unknown>
318
305
  }
319
306
 
320
307
  export interface StatsResult {
321
- dimensions: number;
322
- count: number;
323
- path: string;
308
+ dimensions: number
309
+ count: number
310
+ path: string
324
311
  }
325
312
 
326
313
  export interface TextSearchResult {
327
- id: string;
328
- score: number;
329
- metadata: Record<string, unknown>;
314
+ id: string
315
+ score: number
316
+ metadata: Record<string, unknown>
330
317
  }
331
318
 
332
319
  export interface VectorItem {
333
- id: string;
334
- /** Vector data as number[] or Float32Array (Float32Array is more efficient) */
335
- vector: number[] | Float32Array;
336
- /** Optional metadata */
337
- metadata?: Record<string, unknown> | undefined;
338
- /** Optional document text (stored in metadata.document) */
339
- document?: string;
320
+ id: string
321
+ /** Vector data as Float32Array */
322
+ vector: Float32Array
323
+ /** Optional metadata */
324
+ metadata?: Record<string, unknown> | undefined
325
+ /** Optional document text (stored in metadata.document) */
326
+ document?: string
340
327
  }
341
328
 
342
329
  export interface VectorItemWithText {
343
- id: string;
344
- /** Vector data as number[] or Float32Array (Float32Array is more efficient) */
345
- vector: number[] | Float32Array;
346
- text: string;
347
- metadata?: Record<string, unknown> | undefined;
330
+ id: string
331
+ vector: Float32Array
332
+ text: string
333
+ metadata?: Record<string, unknown> | undefined
348
334
  }
package/index.js CHANGED
@@ -145,8 +145,8 @@ class VectorDatabase {
145
145
  return this._native.delete(ids);
146
146
  }
147
147
 
148
- deleteWhere(filter) {
149
- return this._native.deleteWhere(filter);
148
+ deleteByFilter(filter) {
149
+ return this._native.deleteByFilter(filter);
150
150
  }
151
151
 
152
152
  count(filter) {
@@ -225,6 +225,10 @@ class VectorDatabase {
225
225
  return this._native.flush();
226
226
  }
227
227
 
228
+ close() {
229
+ return this._native.close();
230
+ }
231
+
228
232
  optimize() {
229
233
  return this._native.optimize();
230
234
  }
@@ -245,8 +249,8 @@ class VectorDatabase {
245
249
  return this._native.exists(id);
246
250
  }
247
251
 
248
- getMany(ids) {
249
- return this._native.getMany(ids);
252
+ getBatch(ids) {
253
+ return this._native.getBatch(ids);
250
254
  }
251
255
  }
252
256
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omendb/omendb",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "Fast embedded vector database with HNSW + ACORN-1 filtered search",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -50,10 +50,10 @@
50
50
  "omendb.node"
51
51
  ],
52
52
  "optionalDependencies": {
53
- "@omendb/omendb-darwin-x64": "0.0.20",
54
- "@omendb/omendb-darwin-arm64": "0.0.20",
55
- "@omendb/omendb-linux-x64-gnu": "0.0.20",
56
- "@omendb/omendb-linux-arm64-gnu": "0.0.20",
57
- "@omendb/omendb-win32-x64-msvc": "0.0.20"
53
+ "@omendb/omendb-darwin-x64": "0.0.22",
54
+ "@omendb/omendb-darwin-arm64": "0.0.22",
55
+ "@omendb/omendb-linux-x64-gnu": "0.0.22",
56
+ "@omendb/omendb-linux-arm64-gnu": "0.0.22",
57
+ "@omendb/omendb-win32-x64-msvc": "0.0.22"
58
58
  }
59
59
  }