@dreamlake/dreamdb 0.2.1 → 0.3.1
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/dreamdb.d.ts +73 -0
- package/dreamdb.js +1 -1
- package/dreamdb_bg.js +121 -1
- package/dreamdb_bg.wasm +0 -0
- package/package.json +1 -1
package/dreamdb.d.ts
CHANGED
|
@@ -41,6 +41,63 @@ export class Space {
|
|
|
41
41
|
* `{ manifestHash, ts, writer, tracks: [{modality, address}] }`.
|
|
42
42
|
*/
|
|
43
43
|
history(max_depth?: number | null): Promise<Array<any>>;
|
|
44
|
+
/**
|
|
45
|
+
* Hybrid search fusing a lexical (BM25) sub-query and a dense (vector)
|
|
46
|
+
* sub-query per spec/0015 §5/§6. Returns the fused `[{ anchor, score }]`
|
|
47
|
+
* list sorted by fused score descending — the same scored shape as
|
|
48
|
+
* `queryVector`.
|
|
49
|
+
*
|
|
50
|
+
* `vector` is the dense sub-query embedding (a `Float32Array`). `opts` is a
|
|
51
|
+
* plain JS object:
|
|
52
|
+
* ```js
|
|
53
|
+
* {
|
|
54
|
+
* textField, textQuery, // BM25 sub-query (required)
|
|
55
|
+
* vectorField, // dense field the `vector` targets (required)
|
|
56
|
+
* topK = 10, // fused results to return
|
|
57
|
+
* fusion = 'rrf', // 'rrf' | 'linear' | 'max' | 'pareto'
|
|
58
|
+
* rrfK = 60, // RRF rank constant (fusion='rrf')
|
|
59
|
+
* textWeight = 1, vectorWeight = 1, // Linear weights (fusion='linear')
|
|
60
|
+
* textK = topK, vectorK = topK, // per-sub-query candidate depths
|
|
61
|
+
* textRequired = false, vectorRequired = false, // §5.3 boolean-AND gates
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* Delegates to the real (tested) `dreamdb-dataset::Dataset::query_hybrid`.
|
|
66
|
+
* (v0 does not expose the optional scalar pre/post-filter; it runs with no
|
|
67
|
+
* scalar gate.)
|
|
68
|
+
*/
|
|
69
|
+
queryHybrid(vector: Float32Array, opts: any): Promise<Array<any>>;
|
|
70
|
+
/**
|
|
71
|
+
* Scalar-index lookup: every anchor whose `field` satisfies `op value`
|
|
72
|
+
* (spec/0011). Returns a `BigUint64Array`-style `Array` of anchors,
|
|
73
|
+
* tombstone-suppressed, sorted ascending and deduped.
|
|
74
|
+
*
|
|
75
|
+
* This is the expansion half of a compact lexical index. A BM25 index
|
|
76
|
+
* built over a scalar field's DISTINCT values returns one representative
|
|
77
|
+
* anchor per matched value; resolving that value back to *every* record
|
|
78
|
+
* carrying it is a scalar-index lookup, not a text-index concern. Keeping
|
|
79
|
+
* the split this way is what lets the text index stay small enough to
|
|
80
|
+
* load in a browser — indexing one document per record instead produced a
|
|
81
|
+
* 406 MB object for ~1,700 distinct strings.
|
|
82
|
+
*
|
|
83
|
+
* `op` is one of `==`, `!=`, `<`, `<=`, `>`, `>=`. `value` may be a
|
|
84
|
+
* string, number, or boolean; strings match both `String` and
|
|
85
|
+
* `Categorical` scalar fields.
|
|
86
|
+
*/
|
|
87
|
+
queryScalar(field: string, op: string, value: any): Promise<Array<any>>;
|
|
88
|
+
/**
|
|
89
|
+
* Lexical BM25 text search over a text `field` (spec/0015 §3.6).
|
|
90
|
+
*
|
|
91
|
+
* Tokenizes `query` with the built-in `dreamdb.utf8-words` tokenizer
|
|
92
|
+
* (lowercase + split on non-alphanumeric — pure Rust, compiled into the
|
|
93
|
+
* wasm; no external model needed even though the field's embeddings were
|
|
94
|
+
* produced elsewhere), scores docs with BM25, and suppresses tombstoned
|
|
95
|
+
* anchors. Returns `[{ anchor, score }]` sorted by score descending — the
|
|
96
|
+
* same scored shape as `queryVector`.
|
|
97
|
+
*
|
|
98
|
+
* Delegates to the real (tested) `dreamdb-dataset::Dataset::query_text`.
|
|
99
|
+
*/
|
|
100
|
+
queryText(field: string, query: string, top_k: number): Promise<Array<any>>;
|
|
44
101
|
/**
|
|
45
102
|
* Top-K cosine vector search over an embedding `field`. `opts` may be a
|
|
46
103
|
* number (topK) or `{ topK?, probeCount? }`. Returns `[{ anchor, score }]`
|
|
@@ -85,6 +142,22 @@ export class Space {
|
|
|
85
142
|
readonly manifestHash: string;
|
|
86
143
|
}
|
|
87
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Install a panic hook that logs the panic message AND its `file:line:col`
|
|
147
|
+
* to the console before the wasm trap surfaces to JS.
|
|
148
|
+
*
|
|
149
|
+
* Without this, every Rust panic reaches JavaScript as a bare
|
|
150
|
+
* `RuntimeError: unreachable` with nothing but wasm frame offsets — and it is
|
|
151
|
+
* indistinguishable from an allocation failure, since Rust's alloc-error
|
|
152
|
+
* handler also aborts. That ambiguity cost real debugging time: a browser
|
|
153
|
+
* `unreachable` from exhausting wasm32's 32-bit address space on an oversized
|
|
154
|
+
* index was initially read as an integer-overflow panic.
|
|
155
|
+
*
|
|
156
|
+
* Zero new deps — uses the already-enabled `web-sys` `console` feature.
|
|
157
|
+
* Runs once at module init.
|
|
158
|
+
*/
|
|
159
|
+
export function __wasm_init(): void;
|
|
160
|
+
|
|
88
161
|
/**
|
|
89
162
|
* Encode arbitrary bytes as lowercase RFC-4648 base32 (no padding).
|
|
90
163
|
*
|
package/dreamdb.js
CHANGED
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./dreamdb_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
S3Backend, Space, bytesToBase32, decodeCbor, version, zeroSpatialKey
|
|
8
|
+
S3Backend, Space, __wasm_init, bytesToBase32, decodeCbor, version, zeroSpatialKey
|
|
9
9
|
} from "./dreamdb_bg.js";
|
package/dreamdb_bg.js
CHANGED
|
@@ -129,6 +129,93 @@ export class Space {
|
|
|
129
129
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Hybrid search fusing a lexical (BM25) sub-query and a dense (vector)
|
|
134
|
+
* sub-query per spec/0015 §5/§6. Returns the fused `[{ anchor, score }]`
|
|
135
|
+
* list sorted by fused score descending — the same scored shape as
|
|
136
|
+
* `queryVector`.
|
|
137
|
+
*
|
|
138
|
+
* `vector` is the dense sub-query embedding (a `Float32Array`). `opts` is a
|
|
139
|
+
* plain JS object:
|
|
140
|
+
* ```js
|
|
141
|
+
* {
|
|
142
|
+
* textField, textQuery, // BM25 sub-query (required)
|
|
143
|
+
* vectorField, // dense field the `vector` targets (required)
|
|
144
|
+
* topK = 10, // fused results to return
|
|
145
|
+
* fusion = 'rrf', // 'rrf' | 'linear' | 'max' | 'pareto'
|
|
146
|
+
* rrfK = 60, // RRF rank constant (fusion='rrf')
|
|
147
|
+
* textWeight = 1, vectorWeight = 1, // Linear weights (fusion='linear')
|
|
148
|
+
* textK = topK, vectorK = topK, // per-sub-query candidate depths
|
|
149
|
+
* textRequired = false, vectorRequired = false, // §5.3 boolean-AND gates
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* Delegates to the real (tested) `dreamdb-dataset::Dataset::query_hybrid`.
|
|
154
|
+
* (v0 does not expose the optional scalar pre/post-filter; it runs with no
|
|
155
|
+
* scalar gate.)
|
|
156
|
+
* @param {Float32Array} vector
|
|
157
|
+
* @param {any} opts
|
|
158
|
+
* @returns {Promise<Array<any>>}
|
|
159
|
+
*/
|
|
160
|
+
queryHybrid(vector, opts) {
|
|
161
|
+
const ptr0 = passArrayF32ToWasm0(vector, wasm.__wbindgen_malloc);
|
|
162
|
+
const len0 = WASM_VECTOR_LEN;
|
|
163
|
+
const ret = wasm.space_queryHybrid(this.__wbg_ptr, ptr0, len0, opts);
|
|
164
|
+
return ret;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Scalar-index lookup: every anchor whose `field` satisfies `op value`
|
|
168
|
+
* (spec/0011). Returns a `BigUint64Array`-style `Array` of anchors,
|
|
169
|
+
* tombstone-suppressed, sorted ascending and deduped.
|
|
170
|
+
*
|
|
171
|
+
* This is the expansion half of a compact lexical index. A BM25 index
|
|
172
|
+
* built over a scalar field's DISTINCT values returns one representative
|
|
173
|
+
* anchor per matched value; resolving that value back to *every* record
|
|
174
|
+
* carrying it is a scalar-index lookup, not a text-index concern. Keeping
|
|
175
|
+
* the split this way is what lets the text index stay small enough to
|
|
176
|
+
* load in a browser — indexing one document per record instead produced a
|
|
177
|
+
* 406 MB object for ~1,700 distinct strings.
|
|
178
|
+
*
|
|
179
|
+
* `op` is one of `==`, `!=`, `<`, `<=`, `>`, `>=`. `value` may be a
|
|
180
|
+
* string, number, or boolean; strings match both `String` and
|
|
181
|
+
* `Categorical` scalar fields.
|
|
182
|
+
* @param {string} field
|
|
183
|
+
* @param {string} op
|
|
184
|
+
* @param {any} value
|
|
185
|
+
* @returns {Promise<Array<any>>}
|
|
186
|
+
*/
|
|
187
|
+
queryScalar(field, op, value) {
|
|
188
|
+
const ptr0 = passStringToWasm0(field, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
189
|
+
const len0 = WASM_VECTOR_LEN;
|
|
190
|
+
const ptr1 = passStringToWasm0(op, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
191
|
+
const len1 = WASM_VECTOR_LEN;
|
|
192
|
+
const ret = wasm.space_queryScalar(this.__wbg_ptr, ptr0, len0, ptr1, len1, value);
|
|
193
|
+
return ret;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Lexical BM25 text search over a text `field` (spec/0015 §3.6).
|
|
197
|
+
*
|
|
198
|
+
* Tokenizes `query` with the built-in `dreamdb.utf8-words` tokenizer
|
|
199
|
+
* (lowercase + split on non-alphanumeric — pure Rust, compiled into the
|
|
200
|
+
* wasm; no external model needed even though the field's embeddings were
|
|
201
|
+
* produced elsewhere), scores docs with BM25, and suppresses tombstoned
|
|
202
|
+
* anchors. Returns `[{ anchor, score }]` sorted by score descending — the
|
|
203
|
+
* same scored shape as `queryVector`.
|
|
204
|
+
*
|
|
205
|
+
* Delegates to the real (tested) `dreamdb-dataset::Dataset::query_text`.
|
|
206
|
+
* @param {string} field
|
|
207
|
+
* @param {string} query
|
|
208
|
+
* @param {number} top_k
|
|
209
|
+
* @returns {Promise<Array<any>>}
|
|
210
|
+
*/
|
|
211
|
+
queryText(field, query, top_k) {
|
|
212
|
+
const ptr0 = passStringToWasm0(field, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
213
|
+
const len0 = WASM_VECTOR_LEN;
|
|
214
|
+
const ptr1 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
215
|
+
const len1 = WASM_VECTOR_LEN;
|
|
216
|
+
const ret = wasm.space_queryText(this.__wbg_ptr, ptr0, len0, ptr1, len1, top_k);
|
|
217
|
+
return ret;
|
|
218
|
+
}
|
|
132
219
|
/**
|
|
133
220
|
* Top-K cosine vector search over an embedding `field`. `opts` may be a
|
|
134
221
|
* number (topK) or `{ topK?, probeCount? }`. Returns `[{ anchor, score }]`
|
|
@@ -216,6 +303,24 @@ export class Space {
|
|
|
216
303
|
}
|
|
217
304
|
if (Symbol.dispose) Space.prototype[Symbol.dispose] = Space.prototype.free;
|
|
218
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Install a panic hook that logs the panic message AND its `file:line:col`
|
|
308
|
+
* to the console before the wasm trap surfaces to JS.
|
|
309
|
+
*
|
|
310
|
+
* Without this, every Rust panic reaches JavaScript as a bare
|
|
311
|
+
* `RuntimeError: unreachable` with nothing but wasm frame offsets — and it is
|
|
312
|
+
* indistinguishable from an allocation failure, since Rust's alloc-error
|
|
313
|
+
* handler also aborts. That ambiguity cost real debugging time: a browser
|
|
314
|
+
* `unreachable` from exhausting wasm32's 32-bit address space on an oversized
|
|
315
|
+
* index was initially read as an integer-overflow panic.
|
|
316
|
+
*
|
|
317
|
+
* Zero new deps — uses the already-enabled `web-sys` `console` feature.
|
|
318
|
+
* Runs once at module init.
|
|
319
|
+
*/
|
|
320
|
+
export function __wasm_init() {
|
|
321
|
+
wasm.__wasm_init();
|
|
322
|
+
}
|
|
323
|
+
|
|
219
324
|
/**
|
|
220
325
|
* Encode arbitrary bytes as lowercase RFC-4648 base32 (no padding).
|
|
221
326
|
*
|
|
@@ -293,6 +398,11 @@ export function __wbg_Error_bce6d499ff0a4aff(arg0, arg1) {
|
|
|
293
398
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
294
399
|
return ret;
|
|
295
400
|
}
|
|
401
|
+
export function __wbg___wbindgen_boolean_get_2304fb8c853028c8(arg0) {
|
|
402
|
+
const v = arg0;
|
|
403
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
404
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
405
|
+
}
|
|
296
406
|
export function __wbg___wbindgen_debug_string_edece8177ad01481(arg0, arg1) {
|
|
297
407
|
const ret = debugString(arg1);
|
|
298
408
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -340,6 +450,9 @@ export function __wbg_call_dfde26266607c996() { return handleError(function (arg
|
|
|
340
450
|
const ret = arg0.call(arg1, arg2);
|
|
341
451
|
return ret;
|
|
342
452
|
}, arguments); }
|
|
453
|
+
export function __wbg_error_f085d7e62279b703(arg0) {
|
|
454
|
+
console.error(arg0);
|
|
455
|
+
}
|
|
343
456
|
export function __wbg_get_dcf82ab8aad1a593() { return handleError(function (arg0, arg1) {
|
|
344
457
|
const ret = Reflect.get(arg0, arg1);
|
|
345
458
|
return ret;
|
|
@@ -348,6 +461,10 @@ export function __wbg_get_unchecked_1dfe6d05ad91d9b7(arg0, arg1) {
|
|
|
348
461
|
const ret = arg0[arg1 >>> 0];
|
|
349
462
|
return ret;
|
|
350
463
|
}
|
|
464
|
+
export function __wbg_headers_4cfb0c75793d7a8d(arg0) {
|
|
465
|
+
const ret = arg0.headers;
|
|
466
|
+
return ret;
|
|
467
|
+
}
|
|
351
468
|
export function __wbg_instanceof_Promise_09012cfa9708520a(arg0) {
|
|
352
469
|
let result;
|
|
353
470
|
try {
|
|
@@ -458,6 +575,9 @@ export function __wbg_set_a0e911be3da02782() { return handleError(function (arg0
|
|
|
458
575
|
const ret = Reflect.set(arg0, arg1, arg2);
|
|
459
576
|
return ret;
|
|
460
577
|
}, arguments); }
|
|
578
|
+
export function __wbg_set_d57e5106f0271787() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
|
|
579
|
+
arg0.set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
|
|
580
|
+
}, arguments); }
|
|
461
581
|
export function __wbg_set_facb7a5914e0fa39(arg0, arg1, arg2) {
|
|
462
582
|
const ret = arg0.set(arg1, arg2);
|
|
463
583
|
return ret;
|
|
@@ -495,7 +615,7 @@ export function __wbg_then_bd927500e8905df2(arg0, arg1, arg2) {
|
|
|
495
615
|
return ret;
|
|
496
616
|
}
|
|
497
617
|
export function __wbindgen_cast_0000000000000001(arg0, arg1) {
|
|
498
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
618
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 392, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
499
619
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_f7c54996eb9137d9___convert__closures_____invoke___wasm_bindgen_f7c54996eb9137d9___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_f7c54996eb9137d9___JsError___true_);
|
|
500
620
|
return ret;
|
|
501
621
|
}
|
package/dreamdb_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@dreamlake/dreamdb",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "WebAssembly binding of dreamdb-dataset — the browser DreamDB SDK (@dreamlake/dreamdb)",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.1",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dreamdb_bg.wasm",
|