@omendb/omendb 0.0.9 → 0.0.11
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/index.d.ts +249 -126
- package/package.json +5 -5
package/index.d.ts
CHANGED
|
@@ -1,103 +1,200 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export declare class VectorDatabase {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
* @returns Array of {id, distance, metadata}
|
|
18
|
+
*/
|
|
19
|
+
search(
|
|
20
|
+
query: Array<number> | Float32Array,
|
|
21
|
+
k: number,
|
|
22
|
+
ef?: number | undefined | null,
|
|
23
|
+
filter?: Record<string, unknown> | undefined,
|
|
24
|
+
): Array<SearchResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Batch search with parallel execution (async).
|
|
27
|
+
*
|
|
28
|
+
* Runs searches in parallel using rayon, returns Promise.
|
|
29
|
+
*/
|
|
30
|
+
searchBatch(
|
|
31
|
+
queries: Array<Array<number> | Float32Array>,
|
|
32
|
+
k: number,
|
|
33
|
+
ef?: number | undefined | null,
|
|
34
|
+
): Promise<Array<Array<SearchResult>>>;
|
|
35
|
+
/** Get a vector by ID. */
|
|
36
|
+
get(id: string): GetResult | null;
|
|
37
|
+
/**
|
|
38
|
+
* Delete vectors by ID.
|
|
39
|
+
*
|
|
40
|
+
* @returns Number of vectors deleted
|
|
41
|
+
*/
|
|
42
|
+
delete(ids: Array<string>): number;
|
|
43
|
+
/**
|
|
44
|
+
* Delete vectors matching a metadata filter.
|
|
45
|
+
*
|
|
46
|
+
* Evaluates the filter against all vectors and deletes those that match.
|
|
47
|
+
* Uses the same MongoDB-style filter syntax as search().
|
|
48
|
+
*
|
|
49
|
+
* @param filter - MongoDB-style metadata filter
|
|
50
|
+
* @returns Number of vectors deleted
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```javascript
|
|
54
|
+
* // Delete by equality
|
|
55
|
+
* db.deleteWhere({ status: "archived" });
|
|
56
|
+
*
|
|
57
|
+
* // Delete with comparison
|
|
58
|
+
* db.deleteWhere({ score: { $lt: 0.5 } });
|
|
59
|
+
*
|
|
60
|
+
* // Complex filter
|
|
61
|
+
* db.deleteWhere({ $and: [{ type: "draft" }, { age: { $gt: 30 } }] });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
deleteWhere(filter: Record<string, unknown>): number;
|
|
65
|
+
/**
|
|
66
|
+
* Count vectors, optionally filtered by metadata.
|
|
67
|
+
*
|
|
68
|
+
* Without a filter, returns total count (same as db.length).
|
|
69
|
+
* With a filter, returns count of vectors matching the filter.
|
|
70
|
+
*
|
|
71
|
+
* @param filter - Optional MongoDB-style metadata filter
|
|
72
|
+
* @returns Number of vectors (matching filter if provided)
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```javascript
|
|
76
|
+
* // Total count
|
|
77
|
+
* const total = db.count();
|
|
78
|
+
*
|
|
79
|
+
* // Filtered count
|
|
80
|
+
* const active = db.count({ status: "active" });
|
|
81
|
+
*
|
|
82
|
+
* // With comparison operators
|
|
83
|
+
* const highScore = db.count({ score: { $gte: 0.8 } });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
count(filter?: Record<string, unknown> | undefined): number;
|
|
87
|
+
/** Update a vector's data and/or metadata. */
|
|
88
|
+
update(
|
|
89
|
+
id: string,
|
|
90
|
+
vector: Array<number> | Float32Array,
|
|
91
|
+
metadata?: Record<string, unknown> | undefined,
|
|
92
|
+
): void;
|
|
93
|
+
/** Get number of vectors in database. */
|
|
94
|
+
get length(): number;
|
|
95
|
+
/** Get current ef_search value. */
|
|
96
|
+
get efSearch(): number;
|
|
97
|
+
/** Set ef_search value. */
|
|
98
|
+
set efSearch(efSearch: number);
|
|
99
|
+
/**
|
|
100
|
+
* Get or create a named collection.
|
|
101
|
+
*
|
|
102
|
+
* Collection handles share state - changes made through one handle
|
|
103
|
+
* are immediately visible through another (no flush required).
|
|
104
|
+
*/
|
|
105
|
+
collection(name: string): VectorDatabase;
|
|
106
|
+
/** List all collections. */
|
|
107
|
+
collections(): Array<string>;
|
|
108
|
+
/** Delete a collection. */
|
|
109
|
+
deleteCollection(name: string): void;
|
|
110
|
+
/**
|
|
111
|
+
* Enable text search for hybrid (vector + text) search.
|
|
112
|
+
*
|
|
113
|
+
* Must be called before using setWithText() or hybridSearch().
|
|
114
|
+
*/
|
|
115
|
+
enableTextSearch(): void;
|
|
116
|
+
/** Check if text search is enabled. */
|
|
117
|
+
get hasTextSearch(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Set vectors with associated text for hybrid search.
|
|
120
|
+
*
|
|
121
|
+
* @param items - Array of {id, vector, text, metadata?}
|
|
122
|
+
* @returns Array of internal indices
|
|
123
|
+
*/
|
|
124
|
+
setWithText(items: Array<VectorItemWithText>): Array<number>;
|
|
125
|
+
/**
|
|
126
|
+
* Search using text only (BM25 scoring).
|
|
127
|
+
*
|
|
128
|
+
* @param query - Text query
|
|
129
|
+
* @param k - Number of results
|
|
130
|
+
* @returns Array of {id, score, metadata}
|
|
131
|
+
*/
|
|
132
|
+
textSearch(query: string, k: number): Array<TextSearchResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Hybrid search combining vector similarity and text relevance.
|
|
135
|
+
*
|
|
136
|
+
* Uses Reciprocal Rank Fusion (RRF) to combine HNSW and BM25 results.
|
|
137
|
+
*
|
|
138
|
+
* @param queryVector - Query embedding
|
|
139
|
+
* @param queryText - Text query for BM25
|
|
140
|
+
* @param k - Number of results
|
|
141
|
+
* @param filter - Optional metadata filter
|
|
142
|
+
* @param alpha - Weight for vector vs text (0.0=text only, 1.0=vector only, default=0.5)
|
|
143
|
+
* @param rrfK - RRF constant (default=60, higher reduces rank influence)
|
|
144
|
+
* @returns Array of {id, score, metadata}
|
|
145
|
+
*/
|
|
146
|
+
hybridSearch(
|
|
147
|
+
queryVector: Array<number> | Float32Array,
|
|
148
|
+
queryText: string,
|
|
149
|
+
k: number,
|
|
150
|
+
filter?: Record<string, unknown> | undefined,
|
|
151
|
+
alpha?: number | undefined | null,
|
|
152
|
+
rrfK?: number | undefined | null,
|
|
153
|
+
): Array<TextSearchResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Flush pending changes to disk.
|
|
156
|
+
*
|
|
157
|
+
* For hybrid search, this commits text index changes.
|
|
158
|
+
*/
|
|
159
|
+
flush(): void;
|
|
160
|
+
/** Merge another database into this one. */
|
|
161
|
+
mergeFrom(other: VectorDatabase): number;
|
|
162
|
+
/**
|
|
163
|
+
* List all vector IDs (without loading vector data).
|
|
164
|
+
*
|
|
165
|
+
* Efficient way to get all IDs for iteration, export, or debugging.
|
|
166
|
+
* @returns Array of all vector IDs in the database
|
|
167
|
+
*/
|
|
168
|
+
ids(): Array<string>;
|
|
169
|
+
/**
|
|
170
|
+
* Get all items as array of {id, vector, metadata}.
|
|
171
|
+
*
|
|
172
|
+
* Returns all vectors with their IDs and metadata.
|
|
173
|
+
* For large datasets, consider using ids() and get() in batches.
|
|
174
|
+
*/
|
|
175
|
+
items(): Array<GetResult>;
|
|
176
|
+
/**
|
|
177
|
+
* Check if an ID exists in the database.
|
|
178
|
+
*
|
|
179
|
+
* @param id - Vector ID to check
|
|
180
|
+
* @returns true if ID exists and is not deleted
|
|
181
|
+
*/
|
|
182
|
+
exists(id: string): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Get multiple vectors by ID.
|
|
185
|
+
*
|
|
186
|
+
* Batch version of get(). More efficient than calling get() in a loop.
|
|
187
|
+
*
|
|
188
|
+
* @param ids - Array of vector IDs to retrieve
|
|
189
|
+
* @returns Array of results in same order as input, null for missing IDs
|
|
190
|
+
*/
|
|
191
|
+
getMany(ids: Array<string>): Array<GetResult | undefined | null>;
|
|
95
192
|
}
|
|
96
193
|
|
|
97
194
|
export interface GetResult {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
195
|
+
id: string;
|
|
196
|
+
vector: Array<number>;
|
|
197
|
+
metadata: Record<string, unknown>;
|
|
101
198
|
}
|
|
102
199
|
|
|
103
200
|
/**
|
|
@@ -125,9 +222,20 @@ export interface GetResult {
|
|
|
125
222
|
* dimensions: 128,
|
|
126
223
|
* quantization: 4 // 4-bit quantization
|
|
127
224
|
* });
|
|
225
|
+
*
|
|
226
|
+
* // Quantization with custom rescore settings
|
|
227
|
+
* const db = omendb.open("./mydb", {
|
|
228
|
+
* dimensions: 128,
|
|
229
|
+
* quantization: 4,
|
|
230
|
+
* rescore: false, // Disable rescore for max speed
|
|
231
|
+
* oversample: 5.0 // Or increase oversample for better recall
|
|
232
|
+
* });
|
|
128
233
|
* ```
|
|
129
234
|
*/
|
|
130
|
-
export declare function open(
|
|
235
|
+
export declare function open(
|
|
236
|
+
path: string,
|
|
237
|
+
options?: OpenOptions | undefined | null,
|
|
238
|
+
): VectorDatabase;
|
|
131
239
|
|
|
132
240
|
/**
|
|
133
241
|
* Configuration options for opening a vector database.
|
|
@@ -138,49 +246,64 @@ export declare function open(path: string, options?: OpenOptions | undefined | n
|
|
|
138
246
|
* - efConstruction: 100 (build quality, higher = better graph, slower build)
|
|
139
247
|
* - efSearch: 100 (search quality, higher = better recall, slower search)
|
|
140
248
|
* - quantization: null (RaBitQ bit width: 2, 4, or 8 for compression)
|
|
249
|
+
* - rescore: true when quantization enabled (rerank candidates with exact distance)
|
|
250
|
+
* - oversample: 3.0 (fetch k*oversample candidates when rescoring)
|
|
251
|
+
* - metric: "l2" (distance metric: "l2", "euclidean", "cosine", "dot", "ip")
|
|
141
252
|
*/
|
|
142
253
|
export interface OpenOptions {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
254
|
+
/** Vector dimensions (default: 128, auto-detected on first insert) */
|
|
255
|
+
dimensions?: number;
|
|
256
|
+
/** HNSW M parameter: neighbors per node (default: 16, range: 4-64) */
|
|
257
|
+
m?: number;
|
|
258
|
+
/** HNSW ef_construction: build quality (default: 100, must be >= m) */
|
|
259
|
+
efConstruction?: number;
|
|
260
|
+
/** HNSW ef_search: search quality/speed tradeoff (default: 100) */
|
|
261
|
+
efSearch?: number;
|
|
262
|
+
/**
|
|
263
|
+
* RaBitQ quantization bits: 2, 4, or 8 (default: null = no quantization)
|
|
264
|
+
* Enables 4-16x memory compression with ~1-2% recall loss
|
|
265
|
+
*/
|
|
266
|
+
quantization?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Rescore candidates with exact distance (default: true when quantization enabled)
|
|
269
|
+
* Set to false for maximum speed at the cost of ~20% recall
|
|
270
|
+
*/
|
|
271
|
+
rescore?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Oversampling factor for rescoring (default: 3.0)
|
|
274
|
+
* Fetches k*oversample candidates then reranks to return top k
|
|
275
|
+
*/
|
|
276
|
+
oversample?: number;
|
|
277
|
+
/** Distance metric: "l2"/"euclidean" (default), "cosine", "dot"/"ip" */
|
|
278
|
+
metric?: string;
|
|
156
279
|
}
|
|
157
280
|
|
|
158
281
|
export interface SearchResult {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
282
|
+
id: string;
|
|
283
|
+
distance: number;
|
|
284
|
+
/** Metadata as JSON (using serde-json feature) */
|
|
285
|
+
metadata: Record<string, unknown>;
|
|
163
286
|
}
|
|
164
287
|
|
|
165
288
|
export interface TextSearchResult {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
289
|
+
id: string;
|
|
290
|
+
score: number;
|
|
291
|
+
metadata: Record<string, unknown>;
|
|
169
292
|
}
|
|
170
293
|
|
|
171
294
|
export interface VectorItem {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
295
|
+
id: string;
|
|
296
|
+
/** Vector data as array of numbers */
|
|
297
|
+
vector: Array<number>;
|
|
298
|
+
/** Optional metadata */
|
|
299
|
+
metadata?: Record<string, unknown> | undefined;
|
|
300
|
+
/** Optional document text (stored in metadata.document) */
|
|
301
|
+
document?: string;
|
|
179
302
|
}
|
|
180
303
|
|
|
181
304
|
export interface VectorItemWithText {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
305
|
+
id: string;
|
|
306
|
+
vector: Array<number>;
|
|
307
|
+
text: string;
|
|
308
|
+
metadata?: Record<string, unknown> | undefined;
|
|
186
309
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omendb/omendb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Fast embedded vector database with HNSW indexing",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"omendb.node"
|
|
50
50
|
],
|
|
51
51
|
"optionalDependencies": {
|
|
52
|
-
"@omendb/omendb-darwin-x64": "0.0.
|
|
53
|
-
"@omendb/omendb-darwin-arm64": "0.0.
|
|
54
|
-
"@omendb/omendb-linux-x64-gnu": "0.0.
|
|
55
|
-
"@omendb/omendb-linux-arm64-gnu": "0.0.
|
|
52
|
+
"@omendb/omendb-darwin-x64": "0.0.11",
|
|
53
|
+
"@omendb/omendb-darwin-arm64": "0.0.11",
|
|
54
|
+
"@omendb/omendb-linux-x64-gnu": "0.0.11",
|
|
55
|
+
"@omendb/omendb-linux-arm64-gnu": "0.0.11"
|
|
56
56
|
}
|
|
57
57
|
}
|