sensemaking 0.25.1 → 0.27.0
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 +48 -12
- package/dist/cjs/cli/index.d.cts +3 -3
- package/dist/cjs/cli/index.d.ts +3 -3
- package/dist/cjs/cli/index.js +3 -3
- package/dist/cjs/cli/index.js.map +1 -1
- package/dist/cjs/cli/path.js +5 -29
- package/dist/cjs/cli/path.js.map +1 -1
- package/dist/cjs/cli/peek.js +43 -2
- package/dist/cjs/cli/peek.js.map +1 -1
- package/dist/cjs/cli/related.js +4 -3
- package/dist/cjs/cli/related.js.map +1 -1
- package/dist/cjs/cli/search.js +38 -6
- package/dist/cjs/cli/search.js.map +1 -1
- package/dist/cjs/commands/index.d.cts +6 -3
- package/dist/cjs/commands/index.d.ts +6 -3
- package/dist/cjs/commands/index.js +4 -0
- package/dist/cjs/commands/index.js.map +1 -1
- package/dist/cjs/commands/map.d.cts +14 -5
- package/dist/cjs/commands/map.d.ts +14 -5
- package/dist/cjs/commands/map.js +42 -35
- package/dist/cjs/commands/map.js.map +1 -1
- package/dist/cjs/commands/path.d.cts +14 -0
- package/dist/cjs/commands/path.d.ts +14 -0
- package/dist/cjs/commands/path.js +209 -0
- package/dist/cjs/commands/path.js.map +1 -0
- package/dist/cjs/commands/peek.d.cts +25 -2
- package/dist/cjs/commands/peek.d.ts +25 -2
- package/dist/cjs/commands/peek.js +131 -50
- package/dist/cjs/commands/peek.js.map +1 -1
- package/dist/cjs/commands/related.d.cts +16 -3
- package/dist/cjs/commands/related.d.ts +16 -3
- package/dist/cjs/commands/related.js +131 -98
- package/dist/cjs/commands/related.js.map +1 -1
- package/dist/cjs/commands/scope.d.cts +1 -0
- package/dist/cjs/commands/scope.d.ts +1 -0
- package/dist/cjs/commands/scope.js +149 -0
- package/dist/cjs/commands/scope.js.map +1 -1
- package/dist/cjs/commands/search.d.cts +30 -3
- package/dist/cjs/commands/search.d.ts +30 -3
- package/dist/cjs/commands/search.js +240 -73
- package/dist/cjs/commands/search.js.map +1 -1
- package/dist/cjs/commands/signals.d.cts +22 -7
- package/dist/cjs/commands/signals.d.ts +22 -7
- package/dist/cjs/commands/signals.js +77 -15
- package/dist/cjs/commands/signals.js.map +1 -1
- package/dist/cjs/commands/snapshot.d.cts +3 -0
- package/dist/cjs/commands/snapshot.d.ts +3 -0
- package/dist/cjs/commands/snapshot.js +180 -0
- package/dist/cjs/commands/snapshot.js.map +1 -0
- package/dist/cjs/config/load.js +6 -0
- package/dist/cjs/config/load.js.map +1 -1
- package/dist/cjs/embed/cohere.js +41 -16
- package/dist/cjs/embed/cohere.js.map +1 -1
- package/dist/cjs/embed/endpoint.d.cts +2 -0
- package/dist/cjs/embed/endpoint.d.ts +2 -0
- package/dist/cjs/embed/endpoint.js +30 -0
- package/dist/cjs/embed/endpoint.js.map +1 -0
- package/dist/cjs/embed/handoff.d.cts +7 -2
- package/dist/cjs/embed/handoff.d.ts +7 -2
- package/dist/cjs/embed/handoff.js +10 -0
- package/dist/cjs/embed/handoff.js.map +1 -1
- package/dist/cjs/embed/http.d.cts +18 -1
- package/dist/cjs/embed/http.d.ts +18 -1
- package/dist/cjs/embed/http.js +239 -40
- package/dist/cjs/embed/http.js.map +1 -1
- package/dist/cjs/embed/openai.js +39 -17
- package/dist/cjs/embed/openai.js.map +1 -1
- package/dist/cjs/embed/query.d.cts +9 -3
- package/dist/cjs/embed/query.d.ts +9 -3
- package/dist/cjs/embed/query.js +257 -90
- package/dist/cjs/embed/query.js.map +1 -1
- package/dist/cjs/embed/registry.d.cts +2 -2
- package/dist/cjs/embed/registry.d.ts +2 -2
- package/dist/cjs/embed/registry.js +36 -4
- package/dist/cjs/embed/registry.js.map +1 -1
- package/dist/cjs/embed/static.js +6 -2
- package/dist/cjs/embed/static.js.map +1 -1
- package/dist/cjs/embed/store.js +42 -77
- package/dist/cjs/embed/store.js.map +1 -1
- package/dist/cjs/embed/types.d.cts +5 -2
- package/dist/cjs/embed/types.d.ts +5 -2
- package/dist/cjs/embed/types.js.map +1 -1
- package/dist/cjs/features/embed.js +290 -43
- package/dist/cjs/features/embed.js.map +1 -1
- package/dist/cjs/graph/traverse.d.cts +2 -2
- package/dist/cjs/graph/traverse.d.ts +2 -2
- package/dist/cjs/graph/traverse.js +15 -5
- package/dist/cjs/graph/traverse.js.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/output/output.d.cts +4 -36
- package/dist/cjs/output/output.d.ts +4 -36
- package/dist/cjs/output/output.js +1 -2
- package/dist/cjs/output/output.js.map +1 -1
- package/dist/cjs/scan/pool.d.cts +2 -1
- package/dist/cjs/scan/pool.d.ts +2 -1
- package/dist/cjs/scan/pool.js +116 -27
- package/dist/cjs/scan/pool.js.map +1 -1
- package/dist/cjs/scan/reparse.d.cts +1 -0
- package/dist/cjs/scan/reparse.d.ts +1 -0
- package/dist/cjs/scan/reparse.js +75 -21
- package/dist/cjs/scan/reparse.js.map +1 -1
- package/dist/cjs/store/builder.d.cts +11 -21
- package/dist/cjs/store/builder.d.ts +11 -21
- package/dist/cjs/store/builder.js +1077 -438
- package/dist/cjs/store/builder.js.map +1 -1
- package/dist/cjs/store/duckdb/connection.js +16 -2
- package/dist/cjs/store/duckdb/connection.js.map +1 -1
- package/dist/cjs/store/duckdb/open.d.cts +1 -1
- package/dist/cjs/store/duckdb/open.d.ts +1 -1
- package/dist/cjs/store/duckdb/open.js +73 -65
- package/dist/cjs/store/duckdb/open.js.map +1 -1
- package/dist/cjs/store/duckdb/reconcile.js +533 -15
- package/dist/cjs/store/duckdb/reconcile.js.map +1 -1
- package/dist/cjs/store/embed-scope.js +19 -9
- package/dist/cjs/store/embed-scope.js.map +1 -1
- package/dist/cjs/store/index.d.cts +6 -0
- package/dist/cjs/store/index.d.ts +6 -0
- package/dist/cjs/store/index.js +8 -4
- package/dist/cjs/store/index.js.map +1 -1
- package/dist/cjs/store/open.d.cts +6 -1
- package/dist/cjs/store/open.d.ts +6 -1
- package/dist/cjs/store/open.js +230 -307
- package/dist/cjs/store/open.js.map +1 -1
- package/dist/cjs/store/readiness.d.cts +5 -0
- package/dist/cjs/store/readiness.d.ts +5 -0
- package/dist/cjs/store/readiness.js +39 -0
- package/dist/cjs/store/readiness.js.map +1 -0
- package/dist/cjs/store/reconcile.d.cts +26 -1
- package/dist/cjs/store/reconcile.d.ts +26 -1
- package/dist/cjs/store/reconcile.js +670 -576
- package/dist/cjs/store/reconcile.js.map +1 -1
- package/dist/cjs/store/signature.d.cts +1 -0
- package/dist/cjs/store/signature.d.ts +1 -0
- package/dist/cjs/store/signature.js +9 -0
- package/dist/cjs/store/signature.js.map +1 -1
- package/dist/cjs/store/sqlite/open.d.cts +1 -1
- package/dist/cjs/store/sqlite/open.d.ts +1 -1
- package/dist/cjs/store/sqlite/open.js +84 -90
- package/dist/cjs/store/sqlite/open.js.map +1 -1
- package/dist/cjs/store/sqlite/reconcile.js.map +1 -1
- package/dist/cjs/store/sqlite/store.js +63 -60
- package/dist/cjs/store/sqlite/store.js.map +1 -1
- package/dist/cjs/store/sqlite/vectors.d.cts +2 -2
- package/dist/cjs/store/sqlite/vectors.d.ts +2 -2
- package/dist/cjs/store/sqlite/vectors.js +8 -4
- package/dist/cjs/store/sqlite/vectors.js.map +1 -1
- package/dist/cjs/store/stages.js.map +1 -1
- package/dist/cjs/store/turso/connection.d.cts +1 -0
- package/dist/cjs/store/turso/connection.d.ts +1 -0
- package/dist/cjs/store/turso/connection.js +319 -94
- package/dist/cjs/store/turso/connection.js.map +1 -1
- package/dist/cjs/store/turso/open.d.cts +1 -1
- package/dist/cjs/store/turso/open.d.ts +1 -1
- package/dist/cjs/store/turso/open.js +70 -74
- package/dist/cjs/store/turso/open.js.map +1 -1
- package/dist/cjs/store/turso/store.js +25 -23
- package/dist/cjs/store/turso/store.js.map +1 -1
- package/dist/cjs/store/turso/vectors.d.cts +2 -2
- package/dist/cjs/store/turso/vectors.d.ts +2 -2
- package/dist/cjs/store/turso/vectors.js +26 -16
- package/dist/cjs/store/turso/vectors.js.map +1 -1
- package/dist/cjs/store/types.d.cts +4 -1
- package/dist/cjs/store/types.d.ts +4 -1
- package/dist/cjs/store/types.js.map +1 -1
- package/dist/cjs/store/vectors.d.cts +14 -1
- package/dist/cjs/store/vectors.d.ts +14 -1
- package/dist/cjs/store/vectors.js +61 -0
- package/dist/cjs/store/vectors.js.map +1 -1
- package/dist/cjs/watch.d.cts +6 -0
- package/dist/cjs/watch.d.ts +6 -0
- package/dist/cjs/watch.js +42 -10
- package/dist/cjs/watch.js.map +1 -1
- package/dist/cjs/workers/parse.d.cts +4 -3
- package/dist/cjs/workers/parse.d.ts +4 -3
- package/dist/cjs/workers/parse.js +19 -17
- package/dist/cjs/workers/parse.js.map +1 -1
- package/dist/esm/cli/index.d.ts +3 -3
- package/dist/esm/cli/index.js +3 -3
- package/dist/esm/cli/index.js.map +1 -1
- package/dist/esm/cli/path.js +4 -10
- package/dist/esm/cli/path.js.map +1 -1
- package/dist/esm/cli/peek.js +20 -2
- package/dist/esm/cli/peek.js.map +1 -1
- package/dist/esm/cli/related.js +5 -3
- package/dist/esm/cli/related.js.map +1 -1
- package/dist/esm/cli/search.js +12 -2
- package/dist/esm/cli/search.js.map +1 -1
- package/dist/esm/commands/index.d.ts +6 -3
- package/dist/esm/commands/index.js +1 -0
- package/dist/esm/commands/index.js.map +1 -1
- package/dist/esm/commands/map.d.ts +14 -5
- package/dist/esm/commands/map.js +2 -0
- package/dist/esm/commands/map.js.map +1 -1
- package/dist/esm/commands/path.d.ts +14 -0
- package/dist/esm/commands/path.js +33 -0
- package/dist/esm/commands/path.js.map +1 -0
- package/dist/esm/commands/peek.d.ts +25 -2
- package/dist/esm/commands/peek.js +59 -19
- package/dist/esm/commands/peek.js.map +1 -1
- package/dist/esm/commands/related.d.ts +16 -3
- package/dist/esm/commands/related.js +45 -28
- package/dist/esm/commands/related.js.map +1 -1
- package/dist/esm/commands/scope.d.ts +1 -0
- package/dist/esm/commands/scope.js +58 -0
- package/dist/esm/commands/scope.js.map +1 -1
- package/dist/esm/commands/search.d.ts +30 -3
- package/dist/esm/commands/search.js +95 -20
- package/dist/esm/commands/search.js.map +1 -1
- package/dist/esm/commands/signals.d.ts +22 -7
- package/dist/esm/commands/signals.js +74 -17
- package/dist/esm/commands/signals.js.map +1 -1
- package/dist/esm/commands/snapshot.d.ts +3 -0
- package/dist/esm/commands/snapshot.js +25 -0
- package/dist/esm/commands/snapshot.js.map +1 -0
- package/dist/esm/config/load.js +6 -0
- package/dist/esm/config/load.js.map +1 -1
- package/dist/esm/embed/cohere.js +35 -10
- package/dist/esm/embed/cohere.js.map +1 -1
- package/dist/esm/embed/endpoint.d.ts +2 -0
- package/dist/esm/embed/endpoint.js +11 -0
- package/dist/esm/embed/endpoint.js.map +1 -0
- package/dist/esm/embed/handoff.d.ts +7 -2
- package/dist/esm/embed/handoff.js +7 -0
- package/dist/esm/embed/handoff.js.map +1 -1
- package/dist/esm/embed/http.d.ts +18 -1
- package/dist/esm/embed/http.js +137 -17
- package/dist/esm/embed/http.js.map +1 -1
- package/dist/esm/embed/openai.js +34 -12
- package/dist/esm/embed/openai.js.map +1 -1
- package/dist/esm/embed/query.d.ts +9 -3
- package/dist/esm/embed/query.js +98 -26
- package/dist/esm/embed/query.js.map +1 -1
- package/dist/esm/embed/registry.d.ts +2 -2
- package/dist/esm/embed/registry.js +34 -5
- package/dist/esm/embed/registry.js.map +1 -1
- package/dist/esm/embed/static.js +10 -2
- package/dist/esm/embed/static.js.map +1 -1
- package/dist/esm/embed/store.js +30 -21
- package/dist/esm/embed/store.js.map +1 -1
- package/dist/esm/embed/types.d.ts +5 -2
- package/dist/esm/embed/types.js.map +1 -1
- package/dist/esm/features/embed.js +82 -21
- package/dist/esm/features/embed.js.map +1 -1
- package/dist/esm/graph/traverse.d.ts +2 -2
- package/dist/esm/graph/traverse.js +4 -2
- package/dist/esm/graph/traverse.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/output/output.d.ts +4 -36
- package/dist/esm/output/output.js +1 -2
- package/dist/esm/output/output.js.map +1 -1
- package/dist/esm/scan/pool.d.ts +2 -1
- package/dist/esm/scan/pool.js +80 -23
- package/dist/esm/scan/pool.js.map +1 -1
- package/dist/esm/scan/reparse.d.ts +1 -0
- package/dist/esm/scan/reparse.js +40 -12
- package/dist/esm/scan/reparse.js.map +1 -1
- package/dist/esm/store/builder.d.ts +11 -21
- package/dist/esm/store/builder.js +337 -133
- package/dist/esm/store/builder.js.map +1 -1
- package/dist/esm/store/duckdb/connection.js +9 -1
- package/dist/esm/store/duckdb/connection.js.map +1 -1
- package/dist/esm/store/duckdb/open.d.ts +1 -1
- package/dist/esm/store/duckdb/open.js +13 -9
- package/dist/esm/store/duckdb/open.js.map +1 -1
- package/dist/esm/store/duckdb/reconcile.js +145 -10
- package/dist/esm/store/duckdb/reconcile.js.map +1 -1
- package/dist/esm/store/embed-scope.js +16 -6
- package/dist/esm/store/embed-scope.js.map +1 -1
- package/dist/esm/store/index.d.ts +6 -0
- package/dist/esm/store/index.js +10 -4
- package/dist/esm/store/index.js.map +1 -1
- package/dist/esm/store/open.d.ts +6 -1
- package/dist/esm/store/open.js +77 -87
- package/dist/esm/store/open.js.map +1 -1
- package/dist/esm/store/readiness.d.ts +5 -0
- package/dist/esm/store/readiness.js +11 -0
- package/dist/esm/store/readiness.js.map +1 -0
- package/dist/esm/store/reconcile.d.ts +26 -1
- package/dist/esm/store/reconcile.js +142 -120
- package/dist/esm/store/reconcile.js.map +1 -1
- package/dist/esm/store/signature.d.ts +1 -0
- package/dist/esm/store/signature.js +8 -0
- package/dist/esm/store/signature.js.map +1 -1
- package/dist/esm/store/sqlite/open.d.ts +1 -1
- package/dist/esm/store/sqlite/open.js +12 -12
- package/dist/esm/store/sqlite/open.js.map +1 -1
- package/dist/esm/store/sqlite/reconcile.js +2 -2
- package/dist/esm/store/sqlite/reconcile.js.map +1 -1
- package/dist/esm/store/sqlite/store.js +21 -18
- package/dist/esm/store/sqlite/store.js.map +1 -1
- package/dist/esm/store/sqlite/vectors.d.ts +2 -2
- package/dist/esm/store/sqlite/vectors.js +7 -5
- package/dist/esm/store/sqlite/vectors.js.map +1 -1
- package/dist/esm/store/stages.js.map +1 -1
- package/dist/esm/store/turso/connection.d.ts +1 -0
- package/dist/esm/store/turso/connection.js +97 -28
- package/dist/esm/store/turso/connection.js.map +1 -1
- package/dist/esm/store/turso/open.d.ts +1 -1
- package/dist/esm/store/turso/open.js +9 -8
- package/dist/esm/store/turso/open.js.map +1 -1
- package/dist/esm/store/turso/store.js +16 -14
- package/dist/esm/store/turso/store.js.map +1 -1
- package/dist/esm/store/turso/vectors.d.ts +2 -2
- package/dist/esm/store/turso/vectors.js +27 -17
- package/dist/esm/store/turso/vectors.js.map +1 -1
- package/dist/esm/store/types.d.ts +4 -1
- package/dist/esm/store/types.js.map +1 -1
- package/dist/esm/store/vectors.d.ts +14 -1
- package/dist/esm/store/vectors.js +55 -0
- package/dist/esm/store/vectors.js.map +1 -1
- package/dist/esm/watch.d.ts +6 -0
- package/dist/esm/watch.js +40 -14
- package/dist/esm/watch.js.map +1 -1
- package/dist/esm/workers/parse.d.ts +4 -3
- package/dist/esm/workers/parse.js +19 -17
- package/dist/esm/workers/parse.js.map +1 -1
- package/package.json +1 -1
- package/skills/sense/EXAMPLES.md +3 -3
- package/skills/sense/SKILL.md +11 -3
- package/skills/sense/references/search.md +17 -1
- package/skills/sense/references/sql.md +1 -1
- package/skills/sense/references/stores/duckdb.md +1 -1
- package/skills/sense/references/terminology.md +32 -0
- package/skills/sense-setup/SKILL.md +2 -2
- package/skills/sense-setup/references/embeddings.md +1 -1
- package/skills/sense-setup/references/store-benchmarks.md +5 -5
- package/skills/sense-setup/references/stores/duckdb.md +1 -1
|
@@ -9,6 +9,9 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
+
get RELATED_DEFAULT_K () {
|
|
13
|
+
return RELATED_DEFAULT_K;
|
|
14
|
+
},
|
|
12
15
|
get relatedNotes () {
|
|
13
16
|
return relatedNotes;
|
|
14
17
|
},
|
|
@@ -23,6 +26,7 @@ var _errorsts = require("../errors.js");
|
|
|
23
26
|
var _serialqueryts = require("../lib/serial-query.js");
|
|
24
27
|
var _peekts = require("./peek.js");
|
|
25
28
|
var _scopets = require("./scope.js");
|
|
29
|
+
var _snapshotts = require("./snapshot.js");
|
|
26
30
|
function _array_like_to_array(arr, len) {
|
|
27
31
|
if (len == null || len > arr.length) len = arr.length;
|
|
28
32
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -175,6 +179,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
175
179
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
176
180
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
177
181
|
}
|
|
182
|
+
var RELATED_DEFAULT_K = 5;
|
|
178
183
|
function resolveRelatedSeed(store, pathArg) {
|
|
179
184
|
return _async_to_generator(function() {
|
|
180
185
|
var paths;
|
|
@@ -202,111 +207,139 @@ function resolveRelatedSeed(store, pathArg) {
|
|
|
202
207
|
});
|
|
203
208
|
})();
|
|
204
209
|
}
|
|
205
|
-
function relatedNotes(store, cfg, pathArg
|
|
210
|
+
function relatedNotes(store, cfg, pathArg) {
|
|
211
|
+
var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
206
212
|
return (0, _serialqueryts.serialQuery)(store, function() {
|
|
207
|
-
|
|
213
|
+
var _options_k;
|
|
214
|
+
return relatedIndexed(store, cfg, pathArg, options, (_options_k = options.k) !== null && _options_k !== void 0 ? _options_k : RELATED_DEFAULT_K);
|
|
208
215
|
});
|
|
209
216
|
}
|
|
210
217
|
function relatedIndexed(store, cfg, pathArg, overrides, k) {
|
|
211
218
|
return _async_to_generator(function() {
|
|
212
|
-
var
|
|
219
|
+
var effective, e;
|
|
213
220
|
return _ts_generator(this, function(_state) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return [
|
|
223
|
-
4,
|
|
224
|
-
store.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL AND dst != src')
|
|
225
|
-
];
|
|
226
|
-
case 2:
|
|
227
|
-
return [
|
|
228
|
-
4,
|
|
229
|
-
_state.sent().all(path)
|
|
230
|
-
];
|
|
231
|
-
case 3:
|
|
232
|
-
outbound = _state.sent().map(function(r) {
|
|
233
|
-
return r.dst;
|
|
234
|
-
});
|
|
235
|
-
return [
|
|
236
|
-
4,
|
|
237
|
-
store.prepare('SELECT DISTINCT src FROM links WHERE dst = ? AND src != dst')
|
|
238
|
-
];
|
|
239
|
-
case 4:
|
|
240
|
-
return [
|
|
241
|
-
4,
|
|
242
|
-
_state.sent().all(path)
|
|
243
|
-
];
|
|
244
|
-
case 5:
|
|
245
|
-
backlinks = _state.sent().map(function(r) {
|
|
246
|
-
return r.src;
|
|
247
|
-
});
|
|
248
|
-
exclude = new Set([
|
|
249
|
-
path
|
|
250
|
-
].concat(_to_consumable_array(outbound), _to_consumable_array(backlinks)));
|
|
251
|
-
// Vectors are the only signal `related` has, so every way of not having them is an error
|
|
252
|
-
// naming the cause; an empty result means one thing, nothing near in meaning.
|
|
253
|
-
effective = (0, _indexts.resolveSearch)(cfg, overrides);
|
|
254
|
-
if (!(0, _indexts.embedEnabled)(cfg)) {
|
|
255
|
-
throw new _errorsts.SenseError('EMBED_DISABLED', 'related ranks notes by meaning, and this tree has no embedding model; add an "embed" block naming one to sense.config.json (a Hugging Face id fetches automatically at first use; `sense download` prefetches it) -- search works without it, on words and links');
|
|
256
|
-
}
|
|
257
|
-
// search gates on the same signal, so a preset's declared signals mean one thing: without
|
|
258
|
-
// this check an overlapping vectors-on preset would answer for a scope that declined them.
|
|
259
|
-
if (effective.signals.vectors === undefined) {
|
|
260
|
-
throw new _errorsts.SenseError('PRESET_NOT_SEMANTIC', 'preset "'.concat(effective.presetName, '" has no "vectors" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add "vectors" to that preset\'s signals'));
|
|
261
|
-
}
|
|
262
|
-
// A downloadable HF id can be fetched by preparation. Only a local path with missing files
|
|
263
|
-
// can never fetch itself.
|
|
264
|
-
e = (0, _indexts.embedConfig)(cfg); // embedEnabled(cfg) above guarantees this is set
|
|
265
|
-
if ((0, _storets.localModelMissing)(e)) {
|
|
266
|
-
throw new _errorsts.SenseError('EMBED_MODEL_MISSING', 'related ranks notes by meaning, so it needs the embedding model, but the local model path "'.concat(e.model, '" is missing ').concat(_storets.MODEL_FILENAMES, "; point embed.model at a directory containing them (search still works without it, on words and links)"));
|
|
267
|
-
}
|
|
268
|
-
return [
|
|
269
|
-
4,
|
|
270
|
-
(0, _scopets.scopedPaths)(store, cfg, overrides)
|
|
271
|
-
];
|
|
272
|
-
case 6:
|
|
273
|
-
allowed = _state.sent();
|
|
274
|
-
// The seed may sit outside a narrowed candidate scope; both it and every eligible result must
|
|
275
|
-
// be ready, while pending vectors in unrelated notes do not block this operation.
|
|
276
|
-
return [
|
|
277
|
-
4,
|
|
278
|
-
(0, _queryts.ensureDocumentEmbeddings)(store, cfg, new Set(_to_consumable_array(allowed).concat([
|
|
279
|
-
path
|
|
280
|
-
])))
|
|
281
|
-
];
|
|
282
|
-
case 7:
|
|
283
|
-
_state.sent();
|
|
284
|
-
return [
|
|
285
|
-
4,
|
|
286
|
-
(0, _queryts.hasEmbedding)(store, path)
|
|
287
|
-
];
|
|
288
|
-
case 8:
|
|
289
|
-
if (!_state.sent()) {
|
|
290
|
-
throw new _errorsts.SenseError('NOTE_NOT_EMBEDDED', "".concat(path, " has no indexed text to compare -- a note that is frontmatter only, or empty, has nothing to rank by meaning"));
|
|
291
|
-
}
|
|
292
|
-
return [
|
|
293
|
-
4,
|
|
294
|
-
(0, _scopets.scopeHasEmbeddings)(store, cfg, allowed)
|
|
295
|
-
];
|
|
296
|
-
case 9:
|
|
297
|
-
if (!_state.sent()) return [
|
|
298
|
-
2,
|
|
299
|
-
[]
|
|
300
|
-
];
|
|
301
|
-
return [
|
|
302
|
-
2,
|
|
303
|
-
(0, _queryts.similarNotes)(store, cfg, path, {
|
|
304
|
-
exclude: exclude,
|
|
305
|
-
allowed: allowed,
|
|
306
|
-
k: k
|
|
307
|
-
})
|
|
308
|
-
];
|
|
221
|
+
if (!Number.isFinite(k) || !Number.isInteger(k) || k <= 0) {
|
|
222
|
+
throw new _errorsts.SenseError('SEARCH_OPTION_INVALID', 'related option "k" must be a positive finite integer, got '.concat(String(k)));
|
|
223
|
+
}
|
|
224
|
+
// Vectors are the only signal `related` has, so every way of not having them is an error
|
|
225
|
+
// naming the cause; an empty result means one thing, nothing near in meaning.
|
|
226
|
+
effective = (0, _indexts.resolveSearch)(cfg, overrides);
|
|
227
|
+
if (!(0, _indexts.embedEnabled)(cfg)) {
|
|
228
|
+
throw new _errorsts.SenseError('EMBED_DISABLED', 'related ranks notes by meaning, and this tree has no embedding model; add an "embed" block naming one to sense.config.json (a Hugging Face id fetches automatically at first use; `sense download` prefetches it) -- search works without it, on words and links');
|
|
309
229
|
}
|
|
230
|
+
// search gates on the same signal, so a preset's declared signals mean one thing: without
|
|
231
|
+
// this check an overlapping vectors-on preset would answer for a scope that declined them.
|
|
232
|
+
if (effective.signals.vectors === undefined) {
|
|
233
|
+
throw new _errorsts.SenseError('PRESET_NOT_SEMANTIC', 'preset "'.concat(effective.presetName, '" has no "vectors" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add "vectors" to that preset\'s signals'));
|
|
234
|
+
}
|
|
235
|
+
// A downloadable HF id can be fetched by preparation. Only a local path with missing files
|
|
236
|
+
// can never fetch itself.
|
|
237
|
+
e = (0, _indexts.embedConfig)(cfg); // embedEnabled(cfg) above guarantees this is set
|
|
238
|
+
if ((0, _storets.localModelMissing)(e)) {
|
|
239
|
+
throw new _errorsts.SenseError('EMBED_MODEL_MISSING', 'related ranks notes by meaning, so it needs the embedding model, but the local model path "'.concat(e.model, '" is missing ').concat(_storets.MODEL_FILENAMES, "; point embed.model at a directory containing them (search still works without it, on words and links)"));
|
|
240
|
+
}
|
|
241
|
+
return [
|
|
242
|
+
2,
|
|
243
|
+
store.transaction(function() {
|
|
244
|
+
return _async_to_generator(function() {
|
|
245
|
+
var current, path, outbound, backlinks, exclude, allowed;
|
|
246
|
+
return _ts_generator(this, function(_state) {
|
|
247
|
+
switch(_state.label){
|
|
248
|
+
case 0:
|
|
249
|
+
return [
|
|
250
|
+
4,
|
|
251
|
+
(0, _snapshotts.assertQuerySnapshot)(store, cfg)
|
|
252
|
+
];
|
|
253
|
+
case 1:
|
|
254
|
+
_state.sent();
|
|
255
|
+
// Repeat effective preset validation inside the snapshot that supplies its durable scope.
|
|
256
|
+
current = (0, _indexts.resolveSearch)(cfg, overrides);
|
|
257
|
+
if (current.signals.vectors === undefined) {
|
|
258
|
+
throw new _errorsts.SenseError('PRESET_NOT_SEMANTIC', 'preset "'.concat(current.presetName, '" has no "vectors" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add "vectors" to that preset\'s signals'));
|
|
259
|
+
}
|
|
260
|
+
return [
|
|
261
|
+
4,
|
|
262
|
+
resolveRelatedSeed(store, pathArg)
|
|
263
|
+
];
|
|
264
|
+
case 2:
|
|
265
|
+
path = _state.sent();
|
|
266
|
+
return [
|
|
267
|
+
4,
|
|
268
|
+
store.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL AND dst != src')
|
|
269
|
+
];
|
|
270
|
+
case 3:
|
|
271
|
+
return [
|
|
272
|
+
4,
|
|
273
|
+
_state.sent().all(path)
|
|
274
|
+
];
|
|
275
|
+
case 4:
|
|
276
|
+
outbound = _state.sent().map(function(r) {
|
|
277
|
+
return r.dst;
|
|
278
|
+
});
|
|
279
|
+
return [
|
|
280
|
+
4,
|
|
281
|
+
store.prepare('SELECT DISTINCT src FROM links WHERE dst = ? AND src != dst')
|
|
282
|
+
];
|
|
283
|
+
case 5:
|
|
284
|
+
return [
|
|
285
|
+
4,
|
|
286
|
+
_state.sent().all(path)
|
|
287
|
+
];
|
|
288
|
+
case 6:
|
|
289
|
+
backlinks = _state.sent().map(function(r) {
|
|
290
|
+
return r.src;
|
|
291
|
+
});
|
|
292
|
+
exclude = new Set([
|
|
293
|
+
path
|
|
294
|
+
].concat(_to_consumable_array(outbound), _to_consumable_array(backlinks)));
|
|
295
|
+
return [
|
|
296
|
+
4,
|
|
297
|
+
(0, _scopets.scopedPaths)(store, cfg, overrides)
|
|
298
|
+
];
|
|
299
|
+
case 7:
|
|
300
|
+
allowed = _state.sent();
|
|
301
|
+
// The seed may sit outside a narrowed candidate scope; both it and every eligible result must
|
|
302
|
+
// be ready, while pending vectors in unrelated notes do not block this operation.
|
|
303
|
+
return [
|
|
304
|
+
4,
|
|
305
|
+
(0, _queryts.ensureDocumentEmbeddings)(store, cfg, new Set(_to_consumable_array(allowed).concat([
|
|
306
|
+
path
|
|
307
|
+
])))
|
|
308
|
+
];
|
|
309
|
+
case 8:
|
|
310
|
+
_state.sent();
|
|
311
|
+
return [
|
|
312
|
+
4,
|
|
313
|
+
(0, _queryts.hasEmbedding)(store, path)
|
|
314
|
+
];
|
|
315
|
+
case 9:
|
|
316
|
+
if (!_state.sent()) {
|
|
317
|
+
throw new _errorsts.SenseError('NOTE_NOT_EMBEDDED', "".concat(path, " has no indexed text to compare -- a note that is frontmatter only, or empty, has nothing to rank by meaning"));
|
|
318
|
+
}
|
|
319
|
+
return [
|
|
320
|
+
4,
|
|
321
|
+
(0, _scopets.scopeHasEmbeddings)(store, cfg, allowed)
|
|
322
|
+
];
|
|
323
|
+
case 10:
|
|
324
|
+
if (!_state.sent()) return [
|
|
325
|
+
2,
|
|
326
|
+
[]
|
|
327
|
+
];
|
|
328
|
+
return [
|
|
329
|
+
2,
|
|
330
|
+
(0, _scopets.withMaterializedVectorScope)(store, allowed, function() {
|
|
331
|
+
return (0, _queryts.similarNotes)(store, cfg, path, {
|
|
332
|
+
exclude: exclude,
|
|
333
|
+
allowed: allowed,
|
|
334
|
+
k: k
|
|
335
|
+
});
|
|
336
|
+
})
|
|
337
|
+
];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
})();
|
|
341
|
+
})
|
|
342
|
+
];
|
|
310
343
|
});
|
|
311
344
|
})();
|
|
312
345
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/related.ts"],"sourcesContent":["import type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { embedConfig, embedEnabled, resolveSearch } from '../config/index.ts';\nimport { ensureDocumentEmbeddings, hasEmbedding, similarNotes } from '../embed/query.ts';\nimport { localModelMissing, MODEL_FILENAMES } from '../embed/store.ts';\nimport { SenseError } from '../errors.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Store } from '../store/types.ts';\nimport { resolveNote } from './peek.ts';\nimport { scopedPaths, scopeHasEmbeddings } from './scope.ts';\n\nexport async function resolveRelatedSeed(store: Store, pathArg: string): Promise<string> {\n const paths = ((await (await store.prepare('SELECT \"path\" FROM frontmatter')).all()) as Array<{ path: string }>).map((row) => row.path);\n return resolveNote(paths, pathArg);\n}\n\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/related.ts"],"sourcesContent":["import type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { embedConfig, embedEnabled, resolveSearch } from '../config/index.ts';\nimport { ensureDocumentEmbeddings, hasEmbedding, similarNotes } from '../embed/query.ts';\nimport { localModelMissing, MODEL_FILENAMES } from '../embed/store.ts';\nimport { SenseError } from '../errors.ts';\nimport { serialQuery } from '../lib/serial-query.ts';\nimport type { Store } from '../store/types.ts';\nimport { resolveNote } from './peek.ts';\nimport { scopedPaths, scopeHasEmbeddings, withMaterializedVectorScope } from './scope.ts';\nimport { assertQuerySnapshot } from './snapshot.ts';\n\nexport const RELATED_DEFAULT_K = 5;\n\n/**\n * Options for {@link relatedNotes}. Scope fields filter result candidates, not the seed note;\n * `k` defaults to 5, matching the CLI.\n */\nexport interface RelatedOptions extends SearchOverrides {\n k?: number;\n}\n\nexport type RelatedResult = {\n path: string;\n similarity: number;\n};\n\nexport async function resolveRelatedSeed(store: Store, pathArg: string): Promise<string> {\n const paths = ((await (await store.prepare('SELECT \"path\" FROM frontmatter')).all()) as Array<{ path: string }>).map((row) => row.path);\n return resolveNote(paths, pathArg);\n}\n\n/**\n * Returns the notes most similar to an indexed seed, excluding the seed and notes linked either\n * way. The seed resolves across the indexed tree even when it is outside the candidate scope.\n */\nexport function relatedNotes(store: Store, cfg: ResolvedConfig, pathArg: string, options: RelatedOptions = {}): Promise<RelatedResult[]> {\n return serialQuery(store, () => relatedIndexed(store, cfg, pathArg, options, options.k ?? RELATED_DEFAULT_K));\n}\n\nasync function relatedIndexed(store: Store, cfg: ResolvedConfig, pathArg: string, overrides: RelatedOptions, k: number): Promise<RelatedResult[]> {\n if (!Number.isFinite(k) || !Number.isInteger(k) || k <= 0) {\n throw new SenseError('SEARCH_OPTION_INVALID', `related option \"k\" must be a positive finite integer, got ${String(k)}`);\n }\n // Vectors are the only signal `related` has, so every way of not having them is an error\n // naming the cause; an empty result means one thing, nothing near in meaning.\n const effective = resolveSearch(cfg, overrides);\n if (!embedEnabled(cfg)) {\n throw new SenseError('EMBED_DISABLED', 'related ranks notes by meaning, and this tree has no embedding model; add an \"embed\" block naming one to sense.config.json (a Hugging Face id fetches automatically at first use; `sense download` prefetches it) -- search works without it, on words and links');\n }\n // search gates on the same signal, so a preset's declared signals mean one thing: without\n // this check an overlapping vectors-on preset would answer for a scope that declined them.\n if (effective.signals.vectors === undefined) {\n throw new SenseError('PRESET_NOT_SEMANTIC', `preset \"${effective.presetName}\" has no \"vectors\" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add \"vectors\" to that preset's signals`);\n }\n // A downloadable HF id can be fetched by preparation. Only a local path with missing files\n // can never fetch itself.\n const e = embedConfig(cfg); // embedEnabled(cfg) above guarantees this is set\n if (localModelMissing(e)) {\n throw new SenseError('EMBED_MODEL_MISSING', `related ranks notes by meaning, so it needs the embedding model, but the local model path \"${e.model}\" is missing ${MODEL_FILENAMES}; point embed.model at a directory containing them (search still works without it, on words and links)`);\n }\n\n return store.transaction(async () => {\n await assertQuerySnapshot(store, cfg);\n // Repeat effective preset validation inside the snapshot that supplies its durable scope.\n const current = resolveSearch(cfg, overrides);\n if (current.signals.vectors === undefined) {\n throw new SenseError('PRESET_NOT_SEMANTIC', `preset \"${current.presetName}\" has no \"vectors\" signal, so this scope has no vectors and related has no other signal; search it instead (words and links), or add \"vectors\" to that preset's signals`);\n }\n\n const path = await resolveRelatedSeed(store, pathArg);\n const outbound = ((await (await store.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL AND dst != src')).all(path)) as Array<{ dst: string }>).map((r) => r.dst);\n const backlinks = ((await (await store.prepare('SELECT DISTINCT src FROM links WHERE dst = ? AND src != dst')).all(path)) as Array<{ src: string }>).map((r) => r.src);\n const exclude = new Set([path, ...outbound, ...backlinks]);\n const allowed = await scopedPaths(store, cfg, overrides);\n // The seed may sit outside a narrowed candidate scope; both it and every eligible result must\n // be ready, while pending vectors in unrelated notes do not block this operation.\n await ensureDocumentEmbeddings(store, cfg, new Set([...allowed, path]));\n if (!(await hasEmbedding(store, path))) {\n throw new SenseError('NOTE_NOT_EMBEDDED', `${path} has no indexed text to compare -- a note that is frontmatter only, or empty, has nothing to rank by meaning`);\n }\n if (!(await scopeHasEmbeddings(store, cfg, allowed))) return [];\n return withMaterializedVectorScope(store, allowed, () => similarNotes(store, cfg, path, { exclude, allowed, k }));\n });\n}\n"],"names":["RELATED_DEFAULT_K","relatedNotes","resolveRelatedSeed","store","pathArg","paths","prepare","all","map","row","path","resolveNote","cfg","options","serialQuery","relatedIndexed","k","overrides","effective","e","Number","isFinite","isInteger","SenseError","String","resolveSearch","embedEnabled","signals","vectors","undefined","presetName","embedConfig","localModelMissing","MODEL_FILENAMES","model","transaction","current","outbound","backlinks","exclude","allowed","assertQuerySnapshot","r","dst","src","Set","scopedPaths","ensureDocumentEmbeddings","hasEmbedding","scopeHasEmbeddings","withMaterializedVectorScope","similarNotes"],"mappings":";;;;;;;;;;;QAWaA;eAAAA;;QAwBGC;eAAAA;;QATMC;eAAAA;;;uBAzBmC;uBACY;uBAClB;wBACxB;6BACC;sBAEA;uBACiD;0BACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,IAAMF,oBAAoB;AAe1B,SAAeE,mBAAmBC,KAAY,EAAEC,OAAe;;YAC9DC;;;;oBAAiB;;wBAAMF,MAAMG,OAAO,CAAC;;;oBAA3B;;wBAAO,cAAuDC,GAAG;;;oBAA3EF,QAAQ,AAAE,cAAiGG,GAAG,CAAC,SAACC;+BAAQA,IAAIC,IAAI;;oBACtI;;wBAAOC,IAAAA,mBAAW,EAACN,OAAOD;;;;IAC5B;;AAMO,SAASH,aAAaE,KAAY,EAAES,GAAmB,EAAER,OAAe;QAAES,UAAAA,iEAA0B,CAAC;IAC1G,OAAOC,IAAAA,0BAAW,EAACX,OAAO;YAAmDU;eAA7CE,eAAeZ,OAAOS,KAAKR,SAASS,UAASA,aAAAA,QAAQG,CAAC,cAATH,wBAAAA,aAAab;;AAC5F;AAEA,SAAee,eAAeZ,KAAY,EAAES,GAAmB,E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C;;;oCAA3B;;wCAAO,cAAwGC,GAAG,CAACG;;;oCAAhI2B,WAAW,AAAE,cAAqJ7B,GAAG,CAAC,SAACkC;+CAAMA,EAAEC,GAAG;;oCAC7J;;wCAAMxC,MAAMG,OAAO,CAAC;;;oCAA3B;;wCAAO,cAAoFC,GAAG,CAACG;;;oCAA7G4B,YAAY,AAAE,cAAiI9B,GAAG,CAAC,SAACkC;+CAAMA,EAAEE,GAAG;;oCAC/JL,UAAU,IAAIM,IAAI;wCAACnC;sCAAD,OAAO,qBAAG2B,WAAU,qBAAGC;oCAC/B;;wCAAMQ,IAAAA,oBAAW,EAAC3C,OAAOS,KAAKK;;;oCAAxCuB,UAAU;oCAChB,8FAA8F;oCAC9F,kFAAkF;oCAClF;;wCAAMO,IAAAA,iCAAwB,EAAC5C,OAAOS,KAAK,IAAIiC,IAAI,AAAC,qBAAGL;4CAAS9B;;;;oCAAhE;oCACM;;wCAAMsC,IAAAA,qBAAY,EAAC7C,OAAOO;;;oCAAhC,IAAI,CAAE,eAAkC;wCACtC,MAAM,IAAIa,oBAAU,CAAC,qBAAqB,AAAC,GAAO,OAALb,MAAK;oCACpD;oCACM;;wCAAMuC,IAAAA,2BAAkB,EAAC9C,OAAOS,KAAK4B;;;oCAA3C,IAAI,CAAE,eAAgD;;;;oCACtD;;wCAAOU,IAAAA,oCAA2B,EAAC/C,OAAOqC,SAAS;mDAAMW,IAAAA,qBAAY,EAAChD,OAAOS,KAAKF,MAAM;gDAAE6B,SAAAA;gDAASC,SAAAA;gDAASxB,GAAAA;4CAAE;;;;;oBAChH;;;;IACF"}
|
|
@@ -7,4 +7,5 @@ export declare function rawScope(store: Store, cfg: ResolvedConfig, overrides: S
|
|
|
7
7
|
export declare function narrowByWhere(store: Store, paths: Set<string>, where: string | undefined): Promise<Set<string>>;
|
|
8
8
|
export declare function scopedPaths(store: Store, cfg: ResolvedConfig, overrides: SearchOverrides): Promise<Set<string>>;
|
|
9
9
|
export declare function materializeScope(store: Store, table: string, paths: Set<string>): Promise<void>;
|
|
10
|
+
export declare function withMaterializedVectorScope<T>(store: Store, allowed: Set<string>, callback: () => Promise<T>, knownTotal?: number): Promise<T>;
|
|
10
11
|
export declare function setupMapScope(store: Store, paths: Set<string>): Promise<void>;
|
|
@@ -7,4 +7,5 @@ export declare function rawScope(store: Store, cfg: ResolvedConfig, overrides: S
|
|
|
7
7
|
export declare function narrowByWhere(store: Store, paths: Set<string>, where: string | undefined): Promise<Set<string>>;
|
|
8
8
|
export declare function scopedPaths(store: Store, cfg: ResolvedConfig, overrides: SearchOverrides): Promise<Set<string>>;
|
|
9
9
|
export declare function materializeScope(store: Store, table: string, paths: Set<string>): Promise<void>;
|
|
10
|
+
export declare function withMaterializedVectorScope<T>(store: Store, allowed: Set<string>, callback: () => Promise<T>, knownTotal?: number): Promise<T>;
|
|
10
11
|
export declare function setupMapScope(store: Store, paths: Set<string>): Promise<void>;
|
|
@@ -32,11 +32,15 @@ _export(exports, {
|
|
|
32
32
|
},
|
|
33
33
|
get setupMapScope () {
|
|
34
34
|
return setupMapScope;
|
|
35
|
+
},
|
|
36
|
+
get withMaterializedVectorScope () {
|
|
37
|
+
return withMaterializedVectorScope;
|
|
35
38
|
}
|
|
36
39
|
});
|
|
37
40
|
var _nodepath = require("node:path");
|
|
38
41
|
var _indexts = require("../config/index.js");
|
|
39
42
|
var _columnhintts = require("../output/column-hint.js");
|
|
43
|
+
var _vectorsts = require("../store/vectors.js");
|
|
40
44
|
function _array_like_to_array(arr, len) {
|
|
41
45
|
if (len == null || len > arr.length) len = arr.length;
|
|
42
46
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -448,6 +452,151 @@ function materializeScope(store, table, paths) {
|
|
|
448
452
|
});
|
|
449
453
|
})();
|
|
450
454
|
}
|
|
455
|
+
function withMaterializedVectorScope(store, allowed, callback, knownTotal) {
|
|
456
|
+
return _async_to_generator(function() {
|
|
457
|
+
var reservation, total, stmt, row, err, operationFailed, operationError, result, err1, cleanupFailed, cleanupError, err2;
|
|
458
|
+
return _ts_generator(this, function(_state) {
|
|
459
|
+
switch(_state.label){
|
|
460
|
+
case 0:
|
|
461
|
+
reservation = (0, _vectorsts.reserveNativeVectorScope)(store.vectors, allowed);
|
|
462
|
+
if (!reservation) return [
|
|
463
|
+
2,
|
|
464
|
+
callback()
|
|
465
|
+
];
|
|
466
|
+
if (allowed.size === 0) {
|
|
467
|
+
reservation.invalidate();
|
|
468
|
+
return [
|
|
469
|
+
2,
|
|
470
|
+
callback()
|
|
471
|
+
];
|
|
472
|
+
}
|
|
473
|
+
total = knownTotal;
|
|
474
|
+
if (!(total === undefined)) return [
|
|
475
|
+
3,
|
|
476
|
+
5
|
|
477
|
+
];
|
|
478
|
+
_state.label = 1;
|
|
479
|
+
case 1:
|
|
480
|
+
_state.trys.push([
|
|
481
|
+
1,
|
|
482
|
+
4,
|
|
483
|
+
,
|
|
484
|
+
5
|
|
485
|
+
]);
|
|
486
|
+
return [
|
|
487
|
+
4,
|
|
488
|
+
store.prepare('SELECT COUNT(*) AS count FROM frontmatter')
|
|
489
|
+
];
|
|
490
|
+
case 2:
|
|
491
|
+
stmt = _state.sent();
|
|
492
|
+
return [
|
|
493
|
+
4,
|
|
494
|
+
stmt.get()
|
|
495
|
+
];
|
|
496
|
+
case 3:
|
|
497
|
+
row = _state.sent();
|
|
498
|
+
total = Number(row.count);
|
|
499
|
+
return [
|
|
500
|
+
3,
|
|
501
|
+
5
|
|
502
|
+
];
|
|
503
|
+
case 4:
|
|
504
|
+
err = _state.sent();
|
|
505
|
+
reservation.invalidate();
|
|
506
|
+
throw err;
|
|
507
|
+
case 5:
|
|
508
|
+
// Materialization only buys work when this is a nonempty true narrowing and the allowed side
|
|
509
|
+
// is no larger than its complement. Direct adapter calls and broader scopes retain JS filtering.
|
|
510
|
+
if (allowed.size >= total || allowed.size > total - allowed.size) {
|
|
511
|
+
reservation.invalidate();
|
|
512
|
+
return [
|
|
513
|
+
2,
|
|
514
|
+
callback()
|
|
515
|
+
];
|
|
516
|
+
}
|
|
517
|
+
operationFailed = false;
|
|
518
|
+
_state.label = 6;
|
|
519
|
+
case 6:
|
|
520
|
+
_state.trys.push([
|
|
521
|
+
6,
|
|
522
|
+
9,
|
|
523
|
+
,
|
|
524
|
+
10
|
|
525
|
+
]);
|
|
526
|
+
return [
|
|
527
|
+
4,
|
|
528
|
+
materializeScope(store, _vectorsts.NATIVE_VECTOR_SCOPE_TABLE, allowed)
|
|
529
|
+
];
|
|
530
|
+
case 7:
|
|
531
|
+
_state.sent();
|
|
532
|
+
reservation.activate();
|
|
533
|
+
return [
|
|
534
|
+
4,
|
|
535
|
+
callback()
|
|
536
|
+
];
|
|
537
|
+
case 8:
|
|
538
|
+
result = _state.sent();
|
|
539
|
+
return [
|
|
540
|
+
3,
|
|
541
|
+
10
|
|
542
|
+
];
|
|
543
|
+
case 9:
|
|
544
|
+
err1 = _state.sent();
|
|
545
|
+
operationFailed = true;
|
|
546
|
+
operationError = err1;
|
|
547
|
+
return [
|
|
548
|
+
3,
|
|
549
|
+
10
|
|
550
|
+
];
|
|
551
|
+
case 10:
|
|
552
|
+
cleanupFailed = false;
|
|
553
|
+
_state.label = 11;
|
|
554
|
+
case 11:
|
|
555
|
+
_state.trys.push([
|
|
556
|
+
11,
|
|
557
|
+
13,
|
|
558
|
+
14,
|
|
559
|
+
15
|
|
560
|
+
]);
|
|
561
|
+
reservation.deactivate();
|
|
562
|
+
return [
|
|
563
|
+
4,
|
|
564
|
+
store.exec("DROP TABLE IF EXISTS ".concat(_vectorsts.NATIVE_VECTOR_SCOPE_TABLE))
|
|
565
|
+
];
|
|
566
|
+
case 12:
|
|
567
|
+
_state.sent();
|
|
568
|
+
return [
|
|
569
|
+
3,
|
|
570
|
+
15
|
|
571
|
+
];
|
|
572
|
+
case 13:
|
|
573
|
+
err2 = _state.sent();
|
|
574
|
+
cleanupFailed = true;
|
|
575
|
+
cleanupError = err2;
|
|
576
|
+
return [
|
|
577
|
+
3,
|
|
578
|
+
15
|
|
579
|
+
];
|
|
580
|
+
case 14:
|
|
581
|
+
reservation.invalidate();
|
|
582
|
+
return [
|
|
583
|
+
7
|
|
584
|
+
];
|
|
585
|
+
case 15:
|
|
586
|
+
if (operationFailed && cleanupFailed) throw new AggregateError([
|
|
587
|
+
operationError,
|
|
588
|
+
cleanupError
|
|
589
|
+
], 'native vector scope operation and cleanup failed');
|
|
590
|
+
if (operationFailed) throw operationError;
|
|
591
|
+
if (cleanupFailed) throw cleanupError;
|
|
592
|
+
return [
|
|
593
|
+
2,
|
|
594
|
+
result
|
|
595
|
+
];
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
})();
|
|
599
|
+
}
|
|
451
600
|
function setupMapScope(store, paths) {
|
|
452
601
|
return _async_to_generator(function() {
|
|
453
602
|
return _ts_generator(this, function(_state) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/scope.ts"],"sourcesContent":["import { matchesGlob } from 'node:path';\nimport type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { anyPresetEmbeds, resolveSearch } from '../config/index.ts';\nimport { columnHint } from '../output/column-hint.ts';\nimport type { Store } from '../store/types.ts';\n\nexport const INTERNAL_COLUMNS = new Set(['path', '_mtime', '_ctime', '_size', '_rank', '_parse_error']);\n\n// node:path's matchesGlob is experimental (stable behind an unstable-API flag) at the\n// Node >=22.20 engines floor; used here in JS rather than a directory walk in the query path.\nexport function inScope(path: string, include: string[], exclude?: string[]): boolean {\n if (!include.some((g) => matchesGlob(path, g))) return false;\n if (exclude?.some((g) => matchesGlob(path, g))) return false;\n return true;\n}\n\nexport async function scopeHasEmbeddings(store: Store, cfg: ResolvedConfig, scopedPaths: Set<string>): Promise<boolean> {\n if (!anyPresetEmbeds(cfg)) return false; // the embeddings table doesn't exist at all in this case\n const stmt = await store.prepare('SELECT DISTINCT \"path\" FROM embeddings WHERE vector IS NOT NULL');\n const rows = (await stmt.all()) as Array<{ path: string }>;\n return rows.some((r) => scopedPaths.has(r.path));\n}\n\n// Scope only (no --where): preset_files for a named preset, JS glob matching for an ad hoc\n// include/exclude override. Shared by scopedPaths() and search()'s candidate-pool sizing.\nexport async function rawScope(store: Store, cfg: ResolvedConfig, overrides: SearchOverrides, allPaths?: string[]): Promise<Set<string>> {\n const effective = resolveSearch(cfg, overrides);\n const { include, exclude } = effective;\n const adHocScope = overrides.include !== undefined || overrides.exclude !== undefined || overrides.noExclude === true;\n if (!adHocScope) {\n const stmt = await store.prepare('SELECT \"path\" FROM preset_files WHERE preset = ?');\n return new Set(((await stmt.all(effective.presetName)) as Array<{ path: string }>).map((r) => r.path));\n }\n const paths = allPaths ?? (await allFrontmatterPaths(store));\n return new Set(paths.filter((p) => inScope(p, include, exclude)));\n}\n\nasync function allFrontmatterPaths(store: Store): Promise<string[]> {\n const stmt = await store.prepare('SELECT \"path\" FROM frontmatter');\n return ((await stmt.all()) as Array<{ path: string }>).map((r) => r.path);\n}\n\nexport async function narrowByWhere(store: Store, paths: Set<string>, where: string | undefined): Promise<Set<string>> {\n if (!where) return paths;\n let whereRows: Array<{ path: string }>;\n try {\n const stmt = await store.prepare(`SELECT \"path\" FROM frontmatter f WHERE (${where})`);\n whereRows = (await stmt.all()) as Array<{ path: string }>;\n } catch (err) {\n throw columnHint(await store.docs.columns(), err as Error);\n }\n const wherePaths = new Set(whereRows.map((r) => r.path));\n return new Set([...paths].filter((p) => wherePaths.has(p)));\n}\n\n// The scope resolver for non-search commands (path, peek, map): same coverage rule search()\n// applies, then narrowed by the resolved `where`.\nexport async function scopedPaths(store: Store, cfg: ResolvedConfig, overrides: SearchOverrides): Promise<Set<string>> {\n const effective = resolveSearch(cfg, overrides);\n return narrowByWhere(store, await rawScope(store, cfg, overrides), effective.where);\n}\n\n// Materializes a path set into a named temp table (same shape as traverse.ts's allowed_nodes)\n// so a query can join/filter against it cheaply instead of binding a parameter per path.\nexport async function materializeScope(store: Store, table: string, paths: Set<string>): Promise<void> {\n await store.exec(`DROP TABLE IF EXISTS ${table}`);\n await store.exec(`CREATE TEMP TABLE ${table} (\"path\" TEXT PRIMARY KEY)`);\n await store.runBatch(\n `INSERT INTO ${table} (\"path\") VALUES (?)`,\n [...paths].map((p) => [p])\n );\n}\n\nexport async function setupMapScope(store: Store, paths: Set<string>): Promise<void> {\n await materializeScope(store, '_map_scope', paths);\n}\n"],"names":["INTERNAL_COLUMNS","inScope","materializeScope","narrowByWhere","rawScope","scopeHasEmbeddings","scopedPaths","setupMapScope","Set","path","include","exclude","some","g","matchesGlob","store","cfg","stmt","rows","anyPresetEmbeds","prepare","all","r","has","overrides","allPaths","effective","adHocScope","paths","resolveSearch","undefined","noExclude","presetName","map","allFrontmatterPaths","filter","p","where","whereRows","err","wherePaths","docs","columns","columnHint","table","exec","runBatch"],"mappings":";;;;;;;;;;;QAMaA;eAAAA;;QAIGC;eAAAA;;QAsDMC;eAAAA;;QAtBAC;eAAAA;;QAjBAC;eAAAA;;QATAC;eAAAA;;QAyCAC;eAAAA;;QAgBAC;eAAAA;;;wBAzEM;uBAEmB;4BACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpB,IAAMP,mBAAmB,IAAIQ,IAAI;IAAC;IAAQ;IAAU;IAAU;IAAS;IAAS;CAAe;AAI/F,SAASP,QAAQQ,IAAY,EAAEC,OAAiB,EAAEC,OAAkB;IACzE,IAAI,CAACD,QAAQE,IAAI,CAAC,SAACC;eAAMC,IAAAA,qBAAW,EAACL,MAAMI;QAAK,OAAO;IACvD,IAAIF,oBAAAA,8BAAAA,QAASC,IAAI,CAAC,SAACC;eAAMC,IAAAA,qBAAW,EAACL,MAAMI;QAAK,OAAO;IACvD,OAAO;AACT;A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AcQ,KAAY,EAAEa,KAAkB;;;;;oBAClE;;wBAAM1B,iBAAiBa,OAAO,cAAca;;;oBAA5C;;;;;;IACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/scope.ts"],"sourcesContent":["import { matchesGlob } from 'node:path';\nimport type { ResolvedConfig, SearchOverrides } from '../config/index.ts';\nimport { anyPresetEmbeds, resolveSearch } from '../config/index.ts';\nimport { columnHint } from '../output/column-hint.ts';\nimport type { Store } from '../store/types.ts';\nimport { NATIVE_VECTOR_SCOPE_TABLE, reserveNativeVectorScope } from '../store/vectors.ts';\n\nexport const INTERNAL_COLUMNS = new Set(['path', '_mtime', '_ctime', '_size', '_rank', '_parse_error']);\n\n// node:path's matchesGlob is experimental (stable behind an unstable-API flag) at the\n// Node >=22.20 engines floor; used here in JS rather than a directory walk in the query path.\nexport function inScope(path: string, include: string[], exclude?: string[]): boolean {\n if (!include.some((g) => matchesGlob(path, g))) return false;\n if (exclude?.some((g) => matchesGlob(path, g))) return false;\n return true;\n}\n\nexport async function scopeHasEmbeddings(store: Store, cfg: ResolvedConfig, scopedPaths: Set<string>): Promise<boolean> {\n if (!anyPresetEmbeds(cfg)) return false; // the embeddings table doesn't exist at all in this case\n const stmt = await store.prepare('SELECT DISTINCT \"path\" FROM embeddings WHERE vector IS NOT NULL');\n const rows = (await stmt.all()) as Array<{ path: string }>;\n return rows.some((r) => scopedPaths.has(r.path));\n}\n\n// Scope only (no --where): preset_files for a named preset, JS glob matching for an ad hoc\n// include/exclude override. Shared by scopedPaths() and search()'s candidate-pool sizing.\nexport async function rawScope(store: Store, cfg: ResolvedConfig, overrides: SearchOverrides, allPaths?: string[]): Promise<Set<string>> {\n const effective = resolveSearch(cfg, overrides);\n const { include, exclude } = effective;\n const adHocScope = overrides.include !== undefined || overrides.exclude !== undefined || overrides.noExclude === true;\n if (!adHocScope) {\n const stmt = await store.prepare('SELECT \"path\" FROM preset_files WHERE preset = ?');\n return new Set(((await stmt.all(effective.presetName)) as Array<{ path: string }>).map((r) => r.path));\n }\n const paths = allPaths ?? (await allFrontmatterPaths(store));\n return new Set(paths.filter((p) => inScope(p, include, exclude)));\n}\n\nasync function allFrontmatterPaths(store: Store): Promise<string[]> {\n const stmt = await store.prepare('SELECT \"path\" FROM frontmatter');\n return ((await stmt.all()) as Array<{ path: string }>).map((r) => r.path);\n}\n\nexport async function narrowByWhere(store: Store, paths: Set<string>, where: string | undefined): Promise<Set<string>> {\n if (!where) return paths;\n let whereRows: Array<{ path: string }>;\n try {\n const stmt = await store.prepare(`SELECT \"path\" FROM frontmatter f WHERE (${where})`);\n whereRows = (await stmt.all()) as Array<{ path: string }>;\n } catch (err) {\n throw columnHint(await store.docs.columns(), err as Error);\n }\n const wherePaths = new Set(whereRows.map((r) => r.path));\n return new Set([...paths].filter((p) => wherePaths.has(p)));\n}\n\n// The scope resolver for non-search commands (path, peek, map): same coverage rule search()\n// applies, then narrowed by the resolved `where`.\nexport async function scopedPaths(store: Store, cfg: ResolvedConfig, overrides: SearchOverrides): Promise<Set<string>> {\n const effective = resolveSearch(cfg, overrides);\n return narrowByWhere(store, await rawScope(store, cfg, overrides), effective.where);\n}\n\n// Materializes a path set into a named temp table (same shape as traverse.ts's allowed_nodes)\n// so a query can join/filter against it cheaply instead of binding a parameter per path.\nexport async function materializeScope(store: Store, table: string, paths: Set<string>): Promise<void> {\n await store.exec(`DROP TABLE IF EXISTS ${table}`);\n await store.exec(`CREATE TEMP TABLE ${table} (\"path\" TEXT PRIMARY KEY)`);\n await store.runBatch(\n `INSERT INTO ${table} (\"path\") VALUES (?)`,\n [...paths].map((p) => [p])\n );\n}\n\n// Native vector adapters can consume a small exact scope through their connection-local temp\n// table. The reservation is tied to this Store's VectorStore wrapper, so another Store cannot\n// activate it by receiving the same Set object.\nexport async function withMaterializedVectorScope<T>(store: Store, allowed: Set<string>, callback: () => Promise<T>, knownTotal?: number): Promise<T> {\n const reservation = reserveNativeVectorScope(store.vectors, allowed);\n if (!reservation) return callback();\n\n if (allowed.size === 0) {\n reservation.invalidate();\n return callback();\n }\n\n let total = knownTotal;\n if (total === undefined) {\n try {\n const stmt = await store.prepare('SELECT COUNT(*) AS count FROM frontmatter');\n const row = (await stmt.get()) as { count: number | bigint };\n total = Number(row.count);\n } catch (err) {\n reservation.invalidate();\n throw err;\n }\n }\n // Materialization only buys work when this is a nonempty true narrowing and the allowed side\n // is no larger than its complement. Direct adapter calls and broader scopes retain JS filtering.\n if (allowed.size >= total || allowed.size > total - allowed.size) {\n reservation.invalidate();\n return callback();\n }\n\n let operationFailed = false;\n let operationError: unknown;\n let result!: T;\n try {\n await materializeScope(store, NATIVE_VECTOR_SCOPE_TABLE, allowed);\n reservation.activate();\n result = await callback();\n } catch (err) {\n operationFailed = true;\n operationError = err;\n }\n\n let cleanupFailed = false;\n let cleanupError: unknown;\n try {\n reservation.deactivate();\n await store.exec(`DROP TABLE IF EXISTS ${NATIVE_VECTOR_SCOPE_TABLE}`);\n } catch (err) {\n cleanupFailed = true;\n cleanupError = err;\n } finally {\n reservation.invalidate();\n }\n\n if (operationFailed && cleanupFailed) throw new AggregateError([operationError, cleanupError], 'native vector scope operation and cleanup failed');\n if (operationFailed) throw operationError;\n if (cleanupFailed) throw cleanupError;\n return result;\n}\n\nexport async function setupMapScope(store: Store, paths: Set<string>): Promise<void> {\n await materializeScope(store, '_map_scope', paths);\n}\n"],"names":["INTERNAL_COLUMNS","inScope","materializeScope","narrowByWhere","rawScope","scopeHasEmbeddings","scopedPaths","setupMapScope","withMaterializedVectorScope","Set","path","include","exclude","some","g","matchesGlob","store","cfg","stmt","rows","anyPresetEmbeds","prepare","all","r","has","overrides","allPaths","effective","adHocScope","paths","resolveSearch","undefined","noExclude","presetName","map","allFrontmatterPaths","filter","p","where","whereRows","err","wherePaths","docs","columns","columnHint","table","exec","runBatch","allowed","callback","knownTotal","reservation","total","row","operationFailed","operationError","result","cleanupFailed","cleanupError","reserveNativeVectorScope","vectors","size","invalidate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BAA3BH,OAAO;oBACA;;wBAAMA,KAAK6C,GAAG;;;oBAArBV,MAAO;oBACbD,QAAQY,OAAOX,IAAIY,KAAK;;;;;;oBACjBzB;oBACPW,YAAYW,UAAU;oBACtB,MAAMtB;;oBAGV,6FAA6F;oBAC7F,iGAAiG;oBACjG,IAAIQ,QAAQa,IAAI,IAAIT,SAASJ,QAAQa,IAAI,GAAGT,QAAQJ,QAAQa,IAAI,EAAE;wBAChEV,YAAYW,UAAU;wBACtB;;4BAAOb;;oBACT;oBAEIK,kBAAkB;;;;;;;;;oBAIpB;;wBAAMpD,iBAAiBc,OAAOkD,oCAAyB,EAAElB;;;oBAAzD;oBACAG,YAAYgB,QAAQ;oBACX;;wBAAMlB;;;oBAAfO,SAAS;;;;;;oBACFhB;oBACPc,kBAAkB;oBAClBC,iBAAiBf;;;;;;oBAGfiB,gBAAgB;;;;;;;;;oBAGlBN,YAAYiB,UAAU;oBACtB;;wBAAMpD,MAAM8B,IAAI,CAAC,AAAC,wBAAiD,OAA1BoB,oCAAyB;;;oBAAlE;;;;;;oBACO1B;oBACPiB,gBAAgB;oBAChBC,eAAelB;;;;;;oBAEfW,YAAYW,UAAU;;;;;oBAGxB,IAAIR,mBAAmBG,eAAe,MAAM,IAAIY;wBAAgBd;wBAAgBG;uBAAe;oBAC/F,IAAIJ,iBAAiB,MAAMC;oBAC3B,IAAIE,eAAe,MAAMC;oBACzB;;wBAAOF;;;;IACT;;AAEO,SAAejD,cAAcS,KAAY,EAAEa,KAAkB;;;;;oBAClE;;wBAAM3B,iBAAiBc,OAAO,cAAca;;;oBAA5C;;;;;;IACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ResolvedConfig } from '../config/index.js';
|
|
2
|
-
import type { Row } from '../output/output.js';
|
|
3
2
|
import type { Store } from '../store/types.js';
|
|
3
|
+
import type { SearchResultVia, SearchSignalContribution } from './signals.js';
|
|
4
|
+
export type { SearchResultVia, SearchSignalContribution } from './signals.js';
|
|
4
5
|
export declare const SNIPPET_CHAR_LIMIT_DEFAULT = 80;
|
|
5
6
|
export declare const SNIPPET_COUNT_LIMIT_DEFAULT = 1;
|
|
6
7
|
export declare function computeSnippets(text: string, terms: string[], charLimit: number, countLimit: number): {
|
|
@@ -8,8 +9,11 @@ export declare function computeSnippets(text: string, terms: string[], charLimit
|
|
|
8
9
|
offset: number;
|
|
9
10
|
};
|
|
10
11
|
export declare function lineNumberAt(text: string, offset: number): number;
|
|
12
|
+
/** Options for the root {@link search} API. */
|
|
11
13
|
export interface SearchOptions {
|
|
12
14
|
k?: number;
|
|
15
|
+
/** Collects ranking contributions for returned candidates; omitted or false preserves ordinary output. */
|
|
16
|
+
explain?: boolean;
|
|
13
17
|
where?: string;
|
|
14
18
|
preset?: string;
|
|
15
19
|
include?: string[];
|
|
@@ -17,6 +21,29 @@ export interface SearchOptions {
|
|
|
17
21
|
noExclude?: boolean;
|
|
18
22
|
snippetCharLimit?: number;
|
|
19
23
|
snippetCountLimit?: number;
|
|
24
|
+
/** Cancels supported provider I/O and stops between phases after active native work finishes. */
|
|
25
|
+
signal?: AbortSignal;
|
|
20
26
|
}
|
|
21
|
-
export
|
|
22
|
-
|
|
27
|
+
export type SearchResult = {
|
|
28
|
+
path: string;
|
|
29
|
+
title: string;
|
|
30
|
+
summary: string;
|
|
31
|
+
snippets: string[];
|
|
32
|
+
via: SearchResultVia;
|
|
33
|
+
score: number;
|
|
34
|
+
lines: string | null;
|
|
35
|
+
similarity?: number | null;
|
|
36
|
+
/** Present only with explain: true, in words/links/vectors order; contributions can differ from via labels. */
|
|
37
|
+
explanation?: SearchSignalContribution[];
|
|
38
|
+
};
|
|
39
|
+
export interface SearchHydrationRow {
|
|
40
|
+
path: string;
|
|
41
|
+
snippets?: string[];
|
|
42
|
+
lines?: string | null;
|
|
43
|
+
}
|
|
44
|
+
export declare function hydrateSearchRows(store: Store, cfg: ResolvedConfig, rows: SearchHydrationRow[], matchedPaths: Set<string>, terms: string, opts?: Pick<SearchOptions, 'snippetCharLimit' | 'snippetCountLimit'>): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Searches one committed published generation. Provider work precedes the final read transaction;
|
|
47
|
+
* cancellation waits for active native work and transaction cleanup before rejection.
|
|
48
|
+
*/
|
|
49
|
+
export declare function search(store: Store, cfg: ResolvedConfig, terms: string, opts?: SearchOptions): Promise<SearchResult[]>;
|