@omendb/omendb 0.0.26 → 0.0.28
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/README.md +13 -10
- package/index.d.ts +175 -155
- package/index.js +36 -30
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Fast embedded vector database with HNSW indexing for Node.js and Bun.
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install omendb
|
|
8
|
+
npm install @omendb/omendb
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
@@ -191,28 +191,31 @@ db.setWithText([
|
|
|
191
191
|
]);
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
#### `db.
|
|
194
|
+
#### `db.searchText(query, k)`
|
|
195
195
|
|
|
196
196
|
BM25 text-only search.
|
|
197
197
|
|
|
198
198
|
```typescript
|
|
199
|
-
const results = db.
|
|
199
|
+
const results = db.searchText("machine learning", 10);
|
|
200
200
|
// [{ id, score, metadata }, ...]
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
#### `db.
|
|
203
|
+
#### `db.searchHybrid(queryVector, queryText, k, options?)`
|
|
204
204
|
|
|
205
|
-
Combined vector + text search.
|
|
205
|
+
Combined vector + text search using Reciprocal Rank Fusion.
|
|
206
206
|
|
|
207
207
|
```typescript
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
// Basic
|
|
209
|
+
const results = db.searchHybrid(queryVector, "machine learning", 10);
|
|
210
|
+
|
|
211
|
+
// With options
|
|
212
|
+
const results = db.searchHybrid(queryVector, "machine learning", 10, {
|
|
212
213
|
alpha: 0.7, // 0=text only, 1=vector only (default: 0.5)
|
|
214
|
+
rrfK: 60, // RRF constant (default: 60)
|
|
215
|
+
filter: { category: "ml" },
|
|
213
216
|
subscores: true, // Include separate scores
|
|
214
217
|
});
|
|
215
|
-
// [{ id, score, metadata,
|
|
218
|
+
// [{ id, score, metadata, keywordScore?, semanticScore? }, ...]
|
|
216
219
|
```
|
|
217
220
|
|
|
218
221
|
### Collections
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export declare class VectorDatabase {
|
|
4
|
+
/**
|
|
5
|
+
* Get or create a named collection.
|
|
6
|
+
*
|
|
7
|
+
* Collection handles share state - changes made through one handle
|
|
8
|
+
* are immediately visible through another (no flush required).
|
|
9
|
+
*/
|
|
10
|
+
collection(name: string, embeddingFn?: ((texts: string[]) => Float32Array[]) | undefined): VectorDatabase
|
|
11
|
+
/** List all collections. */
|
|
12
|
+
collections(): Array<string>
|
|
13
|
+
/** Delete a collection. */
|
|
14
|
+
deleteCollection(name: string): void
|
|
4
15
|
/**
|
|
5
16
|
* Insert or update vectors.
|
|
6
17
|
*
|
|
@@ -14,45 +25,7 @@ export declare class VectorDatabase {
|
|
|
14
25
|
* @param items - Array of {id, vector, metadata?, text?} or {id, vectors, metadata?}
|
|
15
26
|
* @returns Number of vectors inserted/updated
|
|
16
27
|
*/
|
|
17
|
-
set(items: Array<SetItem>): number
|
|
18
|
-
/**
|
|
19
|
-
* Search for k nearest neighbors.
|
|
20
|
-
*
|
|
21
|
-
* @param query - Query vector (number[] or Float32Array)
|
|
22
|
-
* @param k - Number of results to return
|
|
23
|
-
* @param options - Optional search options: {filter?, ef?, maxDistance?}
|
|
24
|
-
* @returns Array of {id, distance, score, metadata}
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```javascript
|
|
28
|
-
* // Basic search
|
|
29
|
-
* db.search([1, 0, 0, 0], 10);
|
|
30
|
-
*
|
|
31
|
-
* // With options
|
|
32
|
-
* db.search([1, 0, 0, 0], 10, { filter: { category: "A" }, ef: 200 });
|
|
33
|
-
* db.search([1, 0, 0, 0], 10, { maxDistance: 0.5 });
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
search(query: Array<number> | Float32Array, k: number, options?: { filter?: Record<string, unknown>; ef?: number; maxDistance?: number } | undefined): Array<SearchResult>
|
|
37
|
-
/**
|
|
38
|
-
* Search multi-vector store with query tokens.
|
|
39
|
-
*
|
|
40
|
-
* Internal method used by unified search() for multi-vector stores.
|
|
41
|
-
*
|
|
42
|
-
* @param query - Query tokens (number[][] or Float32Array[])
|
|
43
|
-
* @param k - Number of results to return
|
|
44
|
-
* @param rerank - Enable MaxSim reranking for better quality (default: true)
|
|
45
|
-
* @param rerankFactor - Fetch k*rerankFactor candidates before reranking (default: 32)
|
|
46
|
-
* @returns Array of {id, distance, metadata}
|
|
47
|
-
*/
|
|
48
|
-
searchMulti(query: Array<Array<number>> | Array<Float32Array>, k: number, rerank?: boolean | undefined | null, rerankFactor?: number | undefined | null): Array<SearchResult>
|
|
49
|
-
/**
|
|
50
|
-
* Batch search with parallel execution (async).
|
|
51
|
-
*
|
|
52
|
-
* Runs searches in parallel using rayon on a blocking thread pool,
|
|
53
|
-
* keeping the Node.js event loop free.
|
|
54
|
-
*/
|
|
55
|
-
searchBatch(queries: Array<Array<number> | Float32Array>, k: number, ef?: number | undefined | null): Promise<Array<Array<SearchResult>>>
|
|
28
|
+
set(items: Array<SetItem>): Promise<number>
|
|
56
29
|
/** Get a vector by ID. */
|
|
57
30
|
get(id: string): GetResult | null
|
|
58
31
|
/**
|
|
@@ -145,6 +118,8 @@ export declare class VectorDatabase {
|
|
|
145
118
|
get dimensions(): number
|
|
146
119
|
/** Check if this is a multi-vector store. */
|
|
147
120
|
get isMultiVector(): boolean
|
|
121
|
+
/** Check if an embedding function is configured. */
|
|
122
|
+
get hasEmbeddingFn(): boolean
|
|
148
123
|
/** Check if database is empty. */
|
|
149
124
|
isEmpty(): boolean
|
|
150
125
|
/** Get database statistics. */
|
|
@@ -154,16 +129,81 @@ export declare class VectorDatabase {
|
|
|
154
129
|
/** Set ef_search value. */
|
|
155
130
|
set efSearch(efSearch: number)
|
|
156
131
|
/**
|
|
157
|
-
*
|
|
132
|
+
* Compact the database by removing deleted records and reclaiming space.
|
|
158
133
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
134
|
+
* This operation removes tombstoned records, reassigns indices to be
|
|
135
|
+
* contiguous, and rebuilds the search index. Call after bulk deletes
|
|
136
|
+
* to reclaim memory and improve search performance.
|
|
137
|
+
*
|
|
138
|
+
* @returns Number of deleted records that were removed
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // After bulk delete
|
|
143
|
+
* db.delete(staleIds);
|
|
144
|
+
* const removed = db.compact();
|
|
145
|
+
* console.log(`Removed ${removed} deleted records`);
|
|
146
|
+
* ```
|
|
161
147
|
*/
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
148
|
+
compact(): number
|
|
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
|
+
/**
|
|
170
|
+
* Merge another database into this one.
|
|
171
|
+
*
|
|
172
|
+
* @param other - Source database to merge from
|
|
173
|
+
* @param keyPrefix - Optional prefix for all source IDs (e.g., "subdir/")
|
|
174
|
+
* @returns Number of vectors merged
|
|
175
|
+
*/
|
|
176
|
+
mergeFrom(other: VectorDatabase, keyPrefix?: string | undefined | null): number
|
|
177
|
+
/**
|
|
178
|
+
* List all vector IDs (without loading vector data).
|
|
179
|
+
*
|
|
180
|
+
* Efficient way to get all IDs for iteration, export, or debugging.
|
|
181
|
+
* @returns Array of all vector IDs in the database
|
|
182
|
+
*/
|
|
183
|
+
ids(): Array<string>
|
|
184
|
+
/**
|
|
185
|
+
* Get all items as array of {id, vector, metadata}.
|
|
186
|
+
*
|
|
187
|
+
* Returns all vectors with their IDs and metadata.
|
|
188
|
+
* For large datasets, consider using ids() and get() in batches.
|
|
189
|
+
*/
|
|
190
|
+
items(): Array<GetResult>
|
|
191
|
+
/**
|
|
192
|
+
* Check if an ID exists in the database.
|
|
193
|
+
*
|
|
194
|
+
* @param id - Vector ID to check
|
|
195
|
+
* @returns true if ID exists and is not deleted
|
|
196
|
+
*/
|
|
197
|
+
exists(id: string): boolean
|
|
198
|
+
/**
|
|
199
|
+
* Get multiple vectors by ID.
|
|
200
|
+
*
|
|
201
|
+
* Batch version of get(). More efficient than calling get() in a loop.
|
|
202
|
+
*
|
|
203
|
+
* @param ids - Array of vector IDs to retrieve
|
|
204
|
+
* @returns Array of results in same order as input, null for missing IDs
|
|
205
|
+
*/
|
|
206
|
+
getBatch(ids: Array<string>): Array<GetResult | undefined | null>
|
|
167
207
|
/**
|
|
168
208
|
* Check if text search is enabled.
|
|
169
209
|
*
|
|
@@ -203,7 +243,7 @@ export declare class VectorDatabase {
|
|
|
203
243
|
* });
|
|
204
244
|
* ```
|
|
205
245
|
*/
|
|
206
|
-
searchHybrid(queryVector: Array<number> | Float32Array, queryText: string, k: number, options?: { filter?: Record<string, unknown>; alpha?: number; rrfK?: number; subscores?: boolean } | undefined): Array<HybridSearchResult
|
|
246
|
+
searchHybrid(queryVector: Array<number> | Float32Array | string, queryText: string | undefined | null, k: number, options?: { filter?: Record<string, unknown>; alpha?: number; rrfK?: number; subscores?: boolean } | undefined): Promise<Array<HybridSearchResult>>
|
|
207
247
|
/**
|
|
208
248
|
* Flush pending changes to disk.
|
|
209
249
|
*
|
|
@@ -211,100 +251,110 @@ export declare class VectorDatabase {
|
|
|
211
251
|
*/
|
|
212
252
|
flush(): void
|
|
213
253
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* This operation removes tombstoned records, reassigns indices to be
|
|
217
|
-
* contiguous, and rebuilds the search index. Call after bulk deletes
|
|
218
|
-
* to reclaim memory and improve search performance.
|
|
254
|
+
* Search for k nearest neighbors.
|
|
219
255
|
*
|
|
220
|
-
* @
|
|
256
|
+
* @param query - Query vector (number[] or Float32Array)
|
|
257
|
+
* @param k - Number of results to return
|
|
258
|
+
* @param options - Optional search options: {filter?, ef?, maxDistance?}
|
|
259
|
+
* @returns Array of {id, distance, score, metadata}
|
|
221
260
|
*
|
|
222
261
|
* @example
|
|
223
|
-
* ```
|
|
224
|
-
* //
|
|
225
|
-
* db.
|
|
226
|
-
*
|
|
227
|
-
*
|
|
262
|
+
* ```javascript
|
|
263
|
+
* // Basic search
|
|
264
|
+
* db.search([1, 0, 0, 0], 10);
|
|
265
|
+
*
|
|
266
|
+
* // With options
|
|
267
|
+
* db.search([1, 0, 0, 0], 10, { filter: { category: "A" }, ef: 200 });
|
|
268
|
+
* db.search([1, 0, 0, 0], 10, { maxDistance: 0.5 });
|
|
228
269
|
* ```
|
|
229
270
|
*/
|
|
230
|
-
|
|
271
|
+
search(query: Array<number> | Float32Array | string, k: number, options?: { filter?: Record<string, unknown>; ef?: number; maxDistance?: number } | undefined): Promise<Array<SearchResult>>
|
|
231
272
|
/**
|
|
232
|
-
*
|
|
273
|
+
* Search multi-vector store with query tokens.
|
|
233
274
|
*
|
|
234
|
-
*
|
|
235
|
-
* Any subsequent operations will fail or return empty results.
|
|
275
|
+
* Internal method used by unified search() for multi-vector stores.
|
|
236
276
|
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
277
|
+
* @param query - Query tokens (number[][] or Float32Array[])
|
|
278
|
+
* @param k - Number of results to return
|
|
279
|
+
* @param rerank - Enable MaxSim reranking for better quality (default: true)
|
|
280
|
+
* @param rerankFactor - Fetch k*rerankFactor candidates before reranking (default: 32)
|
|
281
|
+
* @returns Array of {id, distance, metadata}
|
|
240
282
|
*/
|
|
241
|
-
|
|
283
|
+
searchMulti(query: Array<Array<number>> | Array<Float32Array>, k: number, rerank?: boolean | undefined | null, rerankFactor?: number | undefined | null): Array<SearchResult>
|
|
242
284
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* Reorders nodes for better memory locality, improving search performance by 6-40%.
|
|
246
|
-
* Call after inserting a large batch of vectors.
|
|
285
|
+
* Batch search with parallel execution (async).
|
|
247
286
|
*
|
|
248
|
-
*
|
|
287
|
+
* Runs searches in parallel using rayon on a blocking thread pool,
|
|
288
|
+
* keeping the Node.js event loop free.
|
|
249
289
|
*/
|
|
250
|
-
|
|
251
|
-
/** Merge another database into this one. */
|
|
252
|
-
mergeFrom(other: VectorDatabase): number
|
|
290
|
+
searchBatch(queries: Array<Array<number> | Float32Array>, k: number, ef?: number | undefined | null): Promise<Array<Array<SearchResult>>>
|
|
253
291
|
/**
|
|
254
|
-
*
|
|
292
|
+
* Enable sparse vector indexing for SPLADE-style retrieval.
|
|
255
293
|
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
294
|
+
* Called automatically by setSparse() and setHybridSparse().
|
|
295
|
+
* Call explicitly before sparseSearch() on an empty index.
|
|
258
296
|
*/
|
|
259
|
-
|
|
297
|
+
enableSparse(): void
|
|
298
|
+
/** Check if sparse indexing is enabled. */
|
|
299
|
+
get hasSparse(): boolean
|
|
260
300
|
/**
|
|
261
|
-
*
|
|
301
|
+
* Insert or update a sparse vector.
|
|
262
302
|
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
|
|
266
|
-
items(): Array<GetResult>
|
|
267
|
-
/**
|
|
268
|
-
* Check if an ID exists in the database.
|
|
303
|
+
* @param id - Unique identifier
|
|
304
|
+
* @param sparse - Sparse vector as {indices: number[], values: number[]} or {dim: weight}
|
|
305
|
+
* @param metadata - Optional metadata
|
|
269
306
|
*
|
|
270
|
-
* @
|
|
271
|
-
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```javascript
|
|
309
|
+
* db.setSparse("doc1", {indices: [10, 42], values: [0.5, 1.2]}, {title: "Hello"});
|
|
310
|
+
* db.setSparse("doc2", {"10": 0.5, "42": 1.2}, {title: "World"});
|
|
311
|
+
* ```
|
|
272
312
|
*/
|
|
273
|
-
|
|
313
|
+
setSparse(id: string, sparse: { indices: number[]; values: number[] } | Record<string, number>, metadata?: Record<string, unknown> | undefined): void
|
|
274
314
|
/**
|
|
275
|
-
*
|
|
315
|
+
* Insert or update both dense and sparse vectors together.
|
|
276
316
|
*
|
|
277
|
-
* @param id -
|
|
278
|
-
* @
|
|
317
|
+
* @param id - Unique identifier
|
|
318
|
+
* @param vector - Dense vector
|
|
319
|
+
* @param sparse - Sparse vector
|
|
320
|
+
* @param metadata - Optional metadata
|
|
279
321
|
*/
|
|
280
|
-
|
|
322
|
+
setHybridSparse(id: string, vector: Array<number> | Float32Array, sparse: { indices: number[]; values: number[] } | Record<string, number>, metadata?: Record<string, unknown> | undefined): void
|
|
281
323
|
/**
|
|
282
|
-
* Search
|
|
283
|
-
*
|
|
284
|
-
* Convenience method that returns the top result or null if no matches.
|
|
324
|
+
* Search sparse vectors by dot product similarity.
|
|
285
325
|
*
|
|
286
|
-
* @param query -
|
|
287
|
-
* @param
|
|
288
|
-
* @
|
|
326
|
+
* @param query - Sparse query vector
|
|
327
|
+
* @param k - Number of results
|
|
328
|
+
* @param options - Optional: {filter?}
|
|
329
|
+
* @returns Array of {id, score, metadata} sorted by score descending
|
|
289
330
|
*
|
|
290
331
|
* @example
|
|
291
332
|
* ```javascript
|
|
292
|
-
* const
|
|
293
|
-
*
|
|
294
|
-
* console.log(`Found: ${nearest.id} at distance ${nearest.distance}`);
|
|
295
|
-
* }
|
|
333
|
+
* const results = db.sparseSearch({indices: [10, 42], values: [1.0, 0.5]}, 5);
|
|
334
|
+
* const results = db.sparseSearch({"10": 1.0, "42": 0.5}, 5);
|
|
296
335
|
* ```
|
|
297
336
|
*/
|
|
298
|
-
|
|
337
|
+
sparseSearch(query: { indices: number[]; values: number[] } | Record<string, number>, k: number, options?: { filter?: Record<string, unknown> } | undefined): Array<SparseSearchResult>
|
|
299
338
|
/**
|
|
300
|
-
*
|
|
339
|
+
* Hybrid dense + sparse search with Reciprocal Rank Fusion (RRF).
|
|
301
340
|
*
|
|
302
|
-
*
|
|
341
|
+
* @param queryVector - Dense query vector
|
|
342
|
+
* @param sparseQuery - Sparse query vector
|
|
343
|
+
* @param k - Number of results
|
|
344
|
+
* @param options - Optional: {alpha?, filter?}
|
|
345
|
+
* @returns Array of {id, score, metadata}
|
|
303
346
|
*
|
|
304
|
-
* @
|
|
305
|
-
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```javascript
|
|
349
|
+
* const results = db.hybridSparseSearch(
|
|
350
|
+
* [1, 0, 0],
|
|
351
|
+
* {indices: [10, 42], values: [1.0, 0.5]},
|
|
352
|
+
* 10,
|
|
353
|
+
* { alpha: 0.5 }
|
|
354
|
+
* );
|
|
355
|
+
* ```
|
|
306
356
|
*/
|
|
307
|
-
|
|
357
|
+
hybridSparseSearch(queryVector: Array<number> | Float32Array, sparseQuery: { indices: number[]; values: number[] } | Record<string, number>, k: number, options?: { alpha?: number; filter?: Record<string, unknown> } | undefined): Array<SparseSearchResult>
|
|
308
358
|
}
|
|
309
359
|
|
|
310
360
|
export interface GetResult {
|
|
@@ -323,14 +373,6 @@ export interface HybridSearchResult {
|
|
|
323
373
|
semanticScore?: number
|
|
324
374
|
}
|
|
325
375
|
|
|
326
|
-
export interface MultiVectorItem {
|
|
327
|
-
id: string
|
|
328
|
-
/** Multi-vector data as array of Float32Arrays */
|
|
329
|
-
vectors: Float32Array[]
|
|
330
|
-
/** Optional metadata */
|
|
331
|
-
metadata?: Record<string, unknown> | undefined
|
|
332
|
-
}
|
|
333
|
-
|
|
334
376
|
/**
|
|
335
377
|
* Open or create a vector database.
|
|
336
378
|
*
|
|
@@ -357,16 +399,9 @@ export interface MultiVectorItem {
|
|
|
357
399
|
* quantization: true // or "sq8"
|
|
358
400
|
* });
|
|
359
401
|
*
|
|
360
|
-
* // Quantization with custom rescore settings
|
|
361
|
-
* const db = omendb.open("./mydb", {
|
|
362
|
-
* dimensions: 128,
|
|
363
|
-
* quantization: true,
|
|
364
|
-
* rescore: false, // Disable rescore for max speed
|
|
365
|
-
* oversample: 5.0 // Or increase oversample for better recall
|
|
366
|
-
* });
|
|
367
402
|
* ```
|
|
368
403
|
*/
|
|
369
|
-
export declare function open(path: string, options?: OpenOptions | undefined | null): VectorDatabase
|
|
404
|
+
export declare function open(path: string, options?: OpenOptions | undefined | null, embeddingFn?: ((texts: string[]) => Float32Array[]) | undefined): VectorDatabase
|
|
370
405
|
|
|
371
406
|
/**
|
|
372
407
|
* Configuration options for opening a vector database.
|
|
@@ -376,9 +411,7 @@ export declare function open(path: string, options?: OpenOptions | undefined | n
|
|
|
376
411
|
* - m: 16 (HNSW neighbors per node, higher = better recall, more memory)
|
|
377
412
|
* - efConstruction: 100 (build quality, higher = better graph, slower build)
|
|
378
413
|
* - efSearch: 100 (search quality, higher = better recall, slower search)
|
|
379
|
-
* - quantization: null (true/"sq8" for 4x compression
|
|
380
|
-
* - rescore: true when quantization enabled (rerank candidates with exact distance)
|
|
381
|
-
* - oversample: 3.0 (fetch k*oversample candidates when rescoring)
|
|
414
|
+
* - quantization: null (true/"sq8" for 4x compression)
|
|
382
415
|
* - metric: "l2" (distance metric: "l2", "euclidean", "cosine", "dot", "ip")
|
|
383
416
|
*/
|
|
384
417
|
export interface OpenOptions {
|
|
@@ -396,16 +429,6 @@ export interface OpenOptions {
|
|
|
396
429
|
* - false/null: Full precision (no quantization)
|
|
397
430
|
*/
|
|
398
431
|
quantization?: boolean | string | number | null | undefined
|
|
399
|
-
/**
|
|
400
|
-
* Rescore candidates with exact distance (default: true when quantization enabled)
|
|
401
|
-
* Set to false for maximum speed at the cost of ~20% recall
|
|
402
|
-
*/
|
|
403
|
-
rescore?: boolean
|
|
404
|
-
/**
|
|
405
|
-
* Oversampling factor for rescoring (default: 3.0)
|
|
406
|
-
* Fetches k*oversample candidates then reranks to return top k
|
|
407
|
-
*/
|
|
408
|
-
oversample?: number
|
|
409
432
|
/** Distance metric: "l2"/"euclidean" (default), "cosine", "dot"/"ip" */
|
|
410
433
|
metric?: string
|
|
411
434
|
/**
|
|
@@ -416,6 +439,10 @@ export interface OpenOptions {
|
|
|
416
439
|
* - false/null: Disabled (default, single-vector mode)
|
|
417
440
|
*/
|
|
418
441
|
multiVector?: boolean | { repetitions?: number; partitionBits?: number; seed?: number; dProj?: number | null } | null | undefined
|
|
442
|
+
/** SQ8 refiner: rescore with full precision (default: true when quantized) */
|
|
443
|
+
rescore?: boolean
|
|
444
|
+
/** Candidate multiplier for rescoring (default: 3.0) */
|
|
445
|
+
oversample?: number
|
|
419
446
|
}
|
|
420
447
|
|
|
421
448
|
export interface SearchResult {
|
|
@@ -437,6 +464,16 @@ export interface SetItem {
|
|
|
437
464
|
metadata?: Record<string, unknown> | undefined
|
|
438
465
|
/** Optional text for hybrid search (auto-enables text search, stored in metadata.text) */
|
|
439
466
|
text?: string
|
|
467
|
+
/** Optional document for auto-embedding via embeddingFn */
|
|
468
|
+
document?: string
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Sparse search result returned from sparseSearch / hybridSparseSearch. */
|
|
472
|
+
export interface SparseSearchResult {
|
|
473
|
+
id: string
|
|
474
|
+
/** Dot product score (higher = more similar) */
|
|
475
|
+
score: number
|
|
476
|
+
metadata: Record<string, unknown>
|
|
440
477
|
}
|
|
441
478
|
|
|
442
479
|
export interface StatsResult {
|
|
@@ -450,20 +487,3 @@ export interface TextSearchResult {
|
|
|
450
487
|
score: number
|
|
451
488
|
metadata: Record<string, unknown>
|
|
452
489
|
}
|
|
453
|
-
|
|
454
|
-
export interface VectorItem {
|
|
455
|
-
id: string
|
|
456
|
-
/** Vector data as Float32Array */
|
|
457
|
-
vector: Float32Array
|
|
458
|
-
/** Optional metadata */
|
|
459
|
-
metadata?: Record<string, unknown> | undefined
|
|
460
|
-
/** Optional document text (stored in metadata.document) */
|
|
461
|
-
document?: string
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
export interface VectorItemWithText {
|
|
465
|
-
id: string
|
|
466
|
-
vector: Float32Array
|
|
467
|
-
text: string
|
|
468
|
-
metadata?: Record<string, unknown> | undefined
|
|
469
|
-
}
|
package/index.js
CHANGED
|
@@ -111,6 +111,10 @@ function toFloat32Array(arr) {
|
|
|
111
111
|
|
|
112
112
|
// Convert VectorItem to use Float32Array
|
|
113
113
|
function convertVectorItem(item) {
|
|
114
|
+
// Items with document field are handled by native embedding
|
|
115
|
+
if (item.document !== undefined && item.document !== null) {
|
|
116
|
+
return item;
|
|
117
|
+
}
|
|
114
118
|
if (item.vector === undefined || item.vector === null) {
|
|
115
119
|
if (Array.isArray(item.vectors)) {
|
|
116
120
|
throw new Error(
|
|
@@ -141,11 +145,6 @@ function convertMultiVectorItem(item) {
|
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
|
|
144
|
-
// Check if items contain multi-vector data (vectors field must be an array)
|
|
145
|
-
function isMultiVectorItem(item) {
|
|
146
|
-
return Array.isArray(item.vectors);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
148
|
// Wrap VectorDatabase to handle array conversion
|
|
150
149
|
const NativeVectorDatabase = nativeBinding.VectorDatabase;
|
|
151
150
|
|
|
@@ -201,17 +200,6 @@ class VectorDatabase {
|
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
|
|
204
|
-
/**
|
|
205
|
-
* Search for the single nearest neighbor.
|
|
206
|
-
*
|
|
207
|
-
* @param {number[]|Float32Array} query - Query vector
|
|
208
|
-
* @param {object} [options] - Search options: {filter?, ef?, maxDistance?}
|
|
209
|
-
* @returns {{id: string, distance: number, score: number, metadata: object}|null}
|
|
210
|
-
*/
|
|
211
|
-
searchOne(query, options) {
|
|
212
|
-
return this._native.searchOne(query, options);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
203
|
searchBatch(queries, k, ef) {
|
|
216
204
|
return this._native.searchBatch(queries, k, ef);
|
|
217
205
|
}
|
|
@@ -254,6 +242,10 @@ class VectorDatabase {
|
|
|
254
242
|
return this._native.isMultiVector;
|
|
255
243
|
}
|
|
256
244
|
|
|
245
|
+
get hasEmbeddingFn() {
|
|
246
|
+
return this._native.hasEmbeddingFn;
|
|
247
|
+
}
|
|
248
|
+
|
|
257
249
|
isEmpty() {
|
|
258
250
|
return this._native.isEmpty();
|
|
259
251
|
}
|
|
@@ -270,8 +262,8 @@ class VectorDatabase {
|
|
|
270
262
|
this._native.efSearch = value;
|
|
271
263
|
}
|
|
272
264
|
|
|
273
|
-
collection(name) {
|
|
274
|
-
return new VectorDatabase(this._native.collection(name));
|
|
265
|
+
collection(name, embeddingFn) {
|
|
266
|
+
return new VectorDatabase(this._native.collection(name, embeddingFn));
|
|
275
267
|
}
|
|
276
268
|
|
|
277
269
|
collections() {
|
|
@@ -338,16 +330,6 @@ class VectorDatabase {
|
|
|
338
330
|
return this._native.exists(id);
|
|
339
331
|
}
|
|
340
332
|
|
|
341
|
-
/**
|
|
342
|
-
* Alias for exists() - check if an ID exists in the database.
|
|
343
|
-
*
|
|
344
|
-
* @param {string} id - Vector ID to check
|
|
345
|
-
* @returns {boolean}
|
|
346
|
-
*/
|
|
347
|
-
has(id) {
|
|
348
|
-
return this._native.has(id);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
333
|
getBatch(ids) {
|
|
352
334
|
return this._native.getBatch(ids);
|
|
353
335
|
}
|
|
@@ -355,10 +337,34 @@ class VectorDatabase {
|
|
|
355
337
|
compact() {
|
|
356
338
|
return this._native.compact();
|
|
357
339
|
}
|
|
340
|
+
|
|
341
|
+
enableSparse() {
|
|
342
|
+
return this._native.enableSparse();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
get hasSparse() {
|
|
346
|
+
return this._native.hasSparse;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
setSparse(id, sparse, metadata) {
|
|
350
|
+
return this._native.setSparse(id, sparse, metadata);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
setHybridSparse(id, vector, sparse, metadata) {
|
|
354
|
+
return this._native.setHybridSparse(id, vector, sparse, metadata);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
sparseSearch(query, k, options) {
|
|
358
|
+
return this._native.sparseSearch(query, k, options);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
hybridSparseSearch(queryVector, sparseQuery, k, options) {
|
|
362
|
+
return this._native.hybridSparseSearch(queryVector, sparseQuery, k, options);
|
|
363
|
+
}
|
|
358
364
|
}
|
|
359
365
|
|
|
360
|
-
function open(path, options) {
|
|
361
|
-
return new VectorDatabase(nativeBinding.open(path, options));
|
|
366
|
+
function open(path, options, embeddingFn) {
|
|
367
|
+
return new VectorDatabase(nativeBinding.open(path, options, embeddingFn));
|
|
362
368
|
}
|
|
363
369
|
|
|
364
370
|
module.exports.VectorDatabase = VectorDatabase;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omendb/omendb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
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.
|
|
54
|
-
"@omendb/omendb-darwin-arm64": "0.0.
|
|
55
|
-
"@omendb/omendb-linux-x64-gnu": "0.0.
|
|
56
|
-
"@omendb/omendb-linux-arm64-gnu": "0.0.
|
|
57
|
-
"@omendb/omendb-win32-x64-msvc": "0.0.
|
|
53
|
+
"@omendb/omendb-darwin-x64": "0.0.28",
|
|
54
|
+
"@omendb/omendb-darwin-arm64": "0.0.28",
|
|
55
|
+
"@omendb/omendb-linux-x64-gnu": "0.0.28",
|
|
56
|
+
"@omendb/omendb-linux-arm64-gnu": "0.0.28",
|
|
57
|
+
"@omendb/omendb-win32-x64-msvc": "0.0.28"
|
|
58
58
|
}
|
|
59
59
|
}
|