@gmickel/gno 2.15.0 → 2.17.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 +1 -1
- package/assets/skill/SKILL.md +27 -0
- package/assets/skill/cli-reference.md +24 -15
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.17.0.zip} +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.17.0.zip.sha256 +1 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/spec/cli.md +43 -3
- package/spec/db/schema.sql +53 -1
- package/spec/mcp.md +9 -3
- package/spec/output-schemas/doctor.schema.json +27 -0
- package/spec/output-schemas/retrieval-trace-payloads.schema.json +14 -0
- package/spec/output-schemas/search-results.schema.json +14 -0
- package/spec/output-schemas/status.schema.json +22 -0
- package/src/cli/commands/agents/commands.ts +1 -1
- package/src/cli/commands/ask.ts +1 -1
- package/src/cli/commands/context-build.ts +1 -1
- package/src/cli/commands/doctor.ts +101 -29
- package/src/cli/commands/embed.ts +2 -2
- package/src/cli/commands/links.ts +30 -6
- package/src/cli/commands/mcp/install.ts +2 -2
- package/src/cli/commands/mcp/status.ts +1 -1
- package/src/cli/commands/mcp/uninstall.ts +1 -1
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/shared.ts +4 -4
- package/src/cli/commands/skill/install.ts +1 -1
- package/src/cli/commands/skill/paths-cmd.ts +1 -1
- package/src/cli/commands/skill/uninstall.ts +1 -1
- package/src/cli/commands/status.ts +75 -58
- package/src/cli/commands/vec.ts +180 -8
- package/src/cli/config-cache.ts +86 -0
- package/src/cli/globals.ts +64 -0
- package/src/cli/program.ts +63 -36
- package/src/cli/run.ts +121 -67
- package/src/cli/runtime-health.ts +132 -122
- package/src/cli/session-binding.ts +11 -2
- package/src/config/saver.ts +8 -0
- package/src/config/types.ts +6 -0
- package/src/converters/adapters/browser-export/formats.ts +25 -15
- package/src/converters/adapters/email/adapter.ts +37 -53
- package/src/converters/adapters/email/html.ts +37 -20
- package/src/converters/adapters/email/mime.ts +71 -39
- package/src/converters/adapters/ical/adapter.ts +20 -12
- package/src/converters/adapters/jsonl/adapter.ts +8 -6
- package/src/converters/adapters/shared/html-text.ts +55 -37
- package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
- package/src/converters/adapters/shared/utf8-lines.ts +69 -31
- package/src/converters/adapters/transcript/adapter.ts +12 -7
- package/src/converters/adapters/xlsx/adapter.ts +10 -7
- package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
- package/src/converters/canonicalize.ts +17 -3
- package/src/converters/native/markdown.ts +24 -17
- package/src/converters/native/plaintext.ts +5 -6
- package/src/converters/registry.ts +130 -8
- package/src/core/activation-status.ts +4 -8
- package/src/core/change-diff.ts +38 -11
- package/src/core/context-compiler.ts +17 -18
- package/src/core/context-evidence.ts +116 -25
- package/src/core/context-verifier.ts +70 -31
- package/src/core/file-lock.ts +10 -2
- package/src/core/graph-analysis.ts +3 -3
- package/src/core/link-inventory-markdown.ts +2 -2
- package/src/core/links.ts +20 -87
- package/src/core/memory-fence.ts +16 -9
- package/src/core/memory-recall.ts +168 -34
- package/src/core/path-rules.ts +143 -0
- package/src/core/retrieval-trace-session.ts +3 -0
- package/src/core/retrieval-trace.ts +9 -0
- package/src/core/section-parse.ts +16 -6
- package/src/core/typed-metadata.ts +68 -0
- package/src/core/vector-partition-status.ts +13 -0
- package/src/core/wiki-link-syntax.ts +88 -0
- package/src/embed/backlog.ts +142 -60
- package/src/embed/retry.ts +39 -33
- package/src/embed/variant-backlog.ts +582 -116
- package/src/embed/variant-retry.ts +157 -48
- package/src/index.ts +3 -3
- package/src/ingestion/budget-error-codes.ts +13 -0
- package/src/ingestion/chunker.ts +60 -49
- package/src/ingestion/compiled-context.ts +4 -5
- package/src/ingestion/convert-file.ts +1 -1
- package/src/ingestion/document-metadata.ts +16 -9
- package/src/ingestion/excluded-ranges.ts +97 -0
- package/src/ingestion/file-processor.ts +122 -37
- package/src/ingestion/frontmatter.ts +35 -7
- package/src/ingestion/graph-reconciliation.ts +187 -51
- package/src/ingestion/language.ts +66 -61
- package/src/ingestion/position.ts +5 -5
- package/src/ingestion/prepare-file.ts +50 -29
- package/src/ingestion/record-adapter-canonical.ts +37 -26
- package/src/ingestion/record-adapter.ts +46 -26
- package/src/ingestion/record-container.ts +121 -53
- package/src/ingestion/record-path.ts +5 -2
- package/src/ingestion/source-availability/darwin-io.ts +10 -7
- package/src/ingestion/source-availability/darwin-path.ts +21 -3
- package/src/ingestion/source-availability/readers.ts +51 -0
- package/src/ingestion/strip.ts +39 -105
- package/src/ingestion/sync.ts +692 -386
- package/src/ingestion/typed-metadata.ts +10 -4
- package/src/ingestion/walker.ts +485 -158
- package/src/llm/cache.ts +128 -84
- package/src/llm/http-inference.ts +112 -35
- package/src/llm/http-policy.ts +101 -0
- package/src/llm/httpEmbedding.ts +8 -1
- package/src/llm/httpGeneration.ts +5 -1
- package/src/llm/httpRerank.ts +5 -1
- package/src/llm/inference-scope.ts +15 -2
- package/src/llm/lazy-ports.ts +33 -3
- package/src/llm/lockfile.ts +34 -7
- package/src/llm/model-cleanup.ts +24 -0
- package/src/llm/native-worker/client.ts +23 -12
- package/src/llm/native-worker/dispatcher.ts +19 -9
- package/src/llm/native-worker/embedding-identity.ts +42 -16
- package/src/llm/native-worker/entry.ts +2 -1
- package/src/llm/native-worker/owner.ts +1 -0
- package/src/llm/native-worker/ports.ts +86 -23
- package/src/llm/native-worker/protocol.ts +386 -55
- package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
- package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
- package/src/llm/nodeLlamaCpp/generation.ts +194 -30
- package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
- package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
- package/src/llm/types.ts +14 -0
- package/src/mcp/context.ts +342 -23
- package/src/mcp/http-transport.ts +21 -3
- package/src/mcp/tool-profile-types.ts +62 -0
- package/src/mcp/tool-profile.ts +32 -56
- package/src/mcp/tools/context.ts +5 -1
- package/src/mcp/tools/index.ts +269 -191
- package/src/mcp/tools/links.ts +14 -6
- package/src/mcp/tools/query.ts +60 -37
- package/src/mcp/tools/vsearch.ts +25 -14
- package/src/pipeline/answer.ts +133 -40
- package/src/pipeline/claim-verification.ts +293 -189
- package/src/pipeline/claim-verifier.ts +6 -7
- package/src/pipeline/egress-lineage.ts +37 -26
- package/src/pipeline/exclude.ts +34 -11
- package/src/pipeline/expansion.ts +233 -19
- package/src/pipeline/explain.ts +17 -2
- package/src/pipeline/filters.ts +169 -33
- package/src/pipeline/graph-retrieval.ts +117 -61
- package/src/pipeline/hybrid.ts +626 -330
- package/src/pipeline/hydration.ts +86 -24
- package/src/pipeline/intent.ts +15 -7
- package/src/pipeline/owner-fusion.ts +61 -19
- package/src/pipeline/query-language.ts +15 -2
- package/src/pipeline/rerank.ts +15 -22
- package/src/pipeline/search.ts +193 -72
- package/src/pipeline/snippet.ts +15 -2
- package/src/pipeline/temporal.ts +51 -10
- package/src/pipeline/types.ts +7 -0
- package/src/pipeline/vsearch.ts +269 -154
- package/src/publish/attachment-raster.ts +2 -16
- package/src/publish/encrypted-export.ts +15 -5
- package/src/serve/browse-tree.ts +50 -42
- package/src/serve/connectors.ts +2 -1
- package/src/serve/context.ts +13 -4
- package/src/serve/doc-events.ts +3 -0
- package/src/serve/public/app.tsx +49 -21
- package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
- package/src/serve/public/components/CaptureModal.tsx +14 -10
- package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
- package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/globals.css +19 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
- package/src/serve/public/lib/metadata-filter.ts +234 -9
- package/src/serve/public/pages/Browse.tsx +61 -27
- package/src/serve/public/pages/DocView.tsx +44 -25
- package/src/serve/public/pages/GraphView.tsx +8 -3
- package/src/serve/resident-runtime.ts +199 -48
- package/src/serve/routes/api.ts +98 -67
- package/src/serve/routes/links.ts +25 -5
- package/src/serve/server.ts +1370 -1180
- package/src/serve/spa-bundle-source.ts +52 -27
- package/src/serve/status.ts +101 -52
- package/src/serve/watch-reconciliation-fallback.ts +11 -7
- package/src/serve/watch-reconciliation-shared.ts +42 -4
- package/src/serve/watch-reconciliation.ts +21 -8
- package/src/serve/watch-service-events.ts +7 -1
- package/src/serve/watch-service-hosts.ts +3 -1
- package/src/serve/watch-service.ts +46 -21
- package/src/serve/watch-snapshot-scan.ts +6 -15
- package/src/sessions/archive.ts +20 -8
- package/src/sessions/sanitize.ts +38 -18
- package/src/sessions/service.ts +180 -102
- package/src/store/migrations/037-performance-indexes.ts +56 -0
- package/src/store/migrations/038-vector-mirror-null-cosine.ts +47 -0
- package/src/store/migrations/039-vector-mirror-v2.ts +94 -0
- package/src/store/migrations/index.ts +6 -0
- package/src/store/sqlite/adapter.ts +1260 -651
- package/src/store/sqlite/chunking-policy.ts +15 -1
- package/src/store/sqlite/eligibility.ts +110 -70
- package/src/store/sqlite/graph-neighbors.ts +71 -46
- package/src/store/sqlite/graph-reference-state.ts +27 -3
- package/src/store/sqlite/graph-similarity.ts +59 -12
- package/src/store/sqlite/metadata-predicate.ts +123 -28
- package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
- package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
- package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
- package/src/store/types.ts +32 -0
- package/src/store/vector/coarse-router.ts +312 -0
- package/src/store/vector/eligibility.ts +39 -0
- package/src/store/vector/lazy.ts +17 -0
- package/src/store/vector/partition-index.ts +333 -59
- package/src/store/vector/proof-cache.ts +209 -0
- package/src/store/vector/runtime-compat.ts +6 -0
- package/src/store/vector/sqlite-vec.ts +270 -162
- package/src/store/vector/stats.ts +37 -73
- package/src/store/vector/status.ts +169 -53
- package/src/store/vector/stored-vectors.ts +131 -45
- package/src/store/vector/types.ts +19 -0
- package/src/store/vector/v2-mirror.ts +669 -0
- package/src/store/vector/variant-search.ts +1187 -111
- package/src/store/vector/variants.ts +964 -160
- package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
|
@@ -23,6 +23,22 @@ function freezeDeep<T>(value: T): T {
|
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function freezeChunkRows(rows: ChunkRow[]): ChunkRow[] {
|
|
27
|
+
const copy = Array.from<ChunkRow>({ length: rows.length });
|
|
28
|
+
for (let i = 0; i < rows.length; i++) {
|
|
29
|
+
copy[i] = Object.freeze({ ...rows[i]! });
|
|
30
|
+
}
|
|
31
|
+
return Object.freeze(copy) as ChunkRow[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function cloneAndFreeze<T>(value: T): T {
|
|
35
|
+
return freezeDeep(structuredClone(value));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function identitySnapshot<T>(value: T): T {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
/** Each caller owns its Map; cached rows are detached, recursively frozen data.
|
|
27
43
|
* The StorePort-compatible types let existing consumers read these snapshots.
|
|
28
44
|
* Consumers that need to mutate a row/array must copy it first.
|
|
@@ -30,7 +46,8 @@ function freezeDeep<T>(value: T): T {
|
|
|
30
46
|
async function loadBatch<T>(
|
|
31
47
|
cache: BatchCache<T>,
|
|
32
48
|
keys: string[],
|
|
33
|
-
load: (missing: string[]) => Promise<StoreResult<Map<string, T
|
|
49
|
+
load: (missing: string[]) => Promise<StoreResult<Map<string, T>>>,
|
|
50
|
+
snapshot: (value: T) => T = cloneAndFreeze
|
|
34
51
|
): Promise<StoreResult<Map<string, T>>> {
|
|
35
52
|
const unique = [...new Set(keys)];
|
|
36
53
|
const missing = unique.filter((key) => !cache.has(key));
|
|
@@ -43,10 +60,7 @@ async function loadBatch<T>(
|
|
|
43
60
|
const snapshots = new Map<string, T>();
|
|
44
61
|
for (const key of missing) {
|
|
45
62
|
if (result.value.has(key)) {
|
|
46
|
-
snapshots.set(
|
|
47
|
-
key,
|
|
48
|
-
freezeDeep(structuredClone(result.value.get(key)!))
|
|
49
|
-
);
|
|
63
|
+
snapshots.set(key, snapshot(result.value.get(key)!));
|
|
50
64
|
}
|
|
51
65
|
}
|
|
52
66
|
return ok(snapshots);
|
|
@@ -104,14 +118,21 @@ export class RequestHydration {
|
|
|
104
118
|
this.documents.clear();
|
|
105
119
|
};
|
|
106
120
|
|
|
121
|
+
hasChunks(hash: string): boolean {
|
|
122
|
+
return this.chunks.has(hash);
|
|
123
|
+
}
|
|
124
|
+
|
|
107
125
|
getChunksBatch(
|
|
108
126
|
hashes: string[]
|
|
109
127
|
): Promise<StoreResult<Map<string, ChunkRow[]>>> {
|
|
110
128
|
const store = this.store;
|
|
111
129
|
if (!store)
|
|
112
130
|
return Promise.resolve(err("QUERY_FAILED", "Hydration request released"));
|
|
113
|
-
return loadBatch(
|
|
114
|
-
|
|
131
|
+
return loadBatch(
|
|
132
|
+
this.chunks,
|
|
133
|
+
hashes,
|
|
134
|
+
(missing) => store.getChunksBatch(missing),
|
|
135
|
+
freezeChunkRows
|
|
115
136
|
);
|
|
116
137
|
}
|
|
117
138
|
|
|
@@ -119,19 +140,29 @@ export class RequestHydration {
|
|
|
119
140
|
const store = this.store;
|
|
120
141
|
if (!store)
|
|
121
142
|
return Promise.resolve(err("QUERY_FAILED", "Hydration request released"));
|
|
122
|
-
return loadBatch(
|
|
123
|
-
|
|
143
|
+
return loadBatch(
|
|
144
|
+
this.content,
|
|
145
|
+
hashes,
|
|
146
|
+
(missing) => getContentBatch(store, missing),
|
|
147
|
+
identitySnapshot
|
|
124
148
|
);
|
|
125
149
|
}
|
|
126
150
|
|
|
127
151
|
async getContent(hash: string): Promise<StoreResult<string | null>> {
|
|
128
152
|
const store = this.store;
|
|
129
153
|
if (!store) return err("QUERY_FAILED", "Hydration request released");
|
|
130
|
-
const result = await loadBatch(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
154
|
+
const result = await loadBatch(
|
|
155
|
+
this.content,
|
|
156
|
+
[hash],
|
|
157
|
+
async () => {
|
|
158
|
+
const content = await store.getContent(hash);
|
|
159
|
+
if (!content.ok) return content;
|
|
160
|
+
return ok(
|
|
161
|
+
new Map(content.value === null ? [] : [[hash, content.value]])
|
|
162
|
+
);
|
|
163
|
+
},
|
|
164
|
+
identitySnapshot
|
|
165
|
+
);
|
|
135
166
|
return result.ok ? ok(result.value.get(hash) ?? null) : result;
|
|
136
167
|
}
|
|
137
168
|
|
|
@@ -141,6 +172,8 @@ export class RequestHydration {
|
|
|
141
172
|
): Promise<StoreResult<DocumentRow[]>> {
|
|
142
173
|
const store = this.store;
|
|
143
174
|
if (!store) return err("QUERY_FAILED", "Hydration request released");
|
|
175
|
+
const uniqueHashes = [...new Set(hashes)];
|
|
176
|
+
if (uniqueHashes.length === 0) return ok([]);
|
|
144
177
|
// Capture caller-owned options before any asynchronous read. Collection
|
|
145
178
|
// scope and activity are part of the lookup identity; titles never key by
|
|
146
179
|
// hash.
|
|
@@ -148,19 +181,48 @@ export class RequestHydration {
|
|
|
148
181
|
...options,
|
|
149
182
|
collections: options?.collections ? [...options.collections] : undefined,
|
|
150
183
|
};
|
|
151
|
-
|
|
152
|
-
// batch boundaries). Regrouping by content hash would reorder documents.
|
|
153
|
-
const requested = [...hashes];
|
|
154
|
-
const identity = JSON.stringify([
|
|
184
|
+
const scopeKey = JSON.stringify([
|
|
155
185
|
scope.collection ?? null,
|
|
156
186
|
scope.collections ?? null,
|
|
157
187
|
scope.activeOnly ?? null,
|
|
158
|
-
requested,
|
|
159
188
|
]);
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
189
|
+
const cacheKeys = uniqueHashes.map((hash) => `${scopeKey}\0${hash}`);
|
|
190
|
+
const keyToHash = new Map<string, string>();
|
|
191
|
+
for (let i = 0; i < uniqueHashes.length; i++) {
|
|
192
|
+
keyToHash.set(cacheKeys[i]!, uniqueHashes[i]!);
|
|
193
|
+
}
|
|
194
|
+
const result = await loadBatch(
|
|
195
|
+
this.documents,
|
|
196
|
+
cacheKeys,
|
|
197
|
+
async (missingKeys) => {
|
|
198
|
+
const missingHashes = missingKeys.map((key) => keyToHash.get(key)!);
|
|
199
|
+
const rows = await store.getDocumentsByMirrorHashes(
|
|
200
|
+
missingHashes,
|
|
201
|
+
scope
|
|
202
|
+
);
|
|
203
|
+
if (!rows.ok) return rows;
|
|
204
|
+
const grouped = new Map<string, DocumentRow[]>();
|
|
205
|
+
for (const key of missingKeys) {
|
|
206
|
+
grouped.set(key, []);
|
|
207
|
+
}
|
|
208
|
+
for (const row of rows.value) {
|
|
209
|
+
if (!row.mirrorHash) continue;
|
|
210
|
+
const key = `${scopeKey}\0${row.mirrorHash}`;
|
|
211
|
+
const list = grouped.get(key);
|
|
212
|
+
if (list) list.push(row);
|
|
213
|
+
}
|
|
214
|
+
return ok(grouped);
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
if (!result.ok) return result;
|
|
218
|
+
const merged: DocumentRow[] = [];
|
|
219
|
+
for (const key of cacheKeys) {
|
|
220
|
+
const list = result.value.get(key);
|
|
221
|
+
if (list) {
|
|
222
|
+
for (const doc of list) merged.push(doc);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
merged.sort((left, right) => left.id - right.id);
|
|
226
|
+
return ok(merged);
|
|
165
227
|
}
|
|
166
228
|
}
|
package/src/pipeline/intent.ts
CHANGED
|
@@ -71,12 +71,11 @@ export function extractSteeringTerms(text: string): string[] {
|
|
|
71
71
|
return dedupe(terms);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
function
|
|
75
|
-
if (terms.length === 0 ||
|
|
74
|
+
function scoreLowerTextForTerms(haystack: string, terms: string[]): number {
|
|
75
|
+
if (terms.length === 0 || haystack.length === 0) {
|
|
76
76
|
return 0;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const haystack = text.toLowerCase();
|
|
80
79
|
let score = 0;
|
|
81
80
|
|
|
82
81
|
for (const term of terms) {
|
|
@@ -91,6 +90,9 @@ function scoreTextForTerms(text: string, terms: string[]): number {
|
|
|
91
90
|
export interface ChunkSelectionOptions {
|
|
92
91
|
preferredSeq?: number | null;
|
|
93
92
|
intentWeight: number;
|
|
93
|
+
/** Optional pre-extracted steering terms hoisted across documents. */
|
|
94
|
+
queryTerms?: string[];
|
|
95
|
+
intentTerms?: string[];
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
/**
|
|
@@ -105,17 +107,23 @@ export function selectBestChunkForSteering(
|
|
|
105
107
|
if (chunks.length === 0) {
|
|
106
108
|
return null;
|
|
107
109
|
}
|
|
110
|
+
if (chunks.length === 1) {
|
|
111
|
+
return chunks[0] ?? null;
|
|
112
|
+
}
|
|
108
113
|
|
|
109
|
-
const queryTerms = extractSteeringTerms(query);
|
|
110
|
-
const intentTerms = extractSteeringTerms(intent ?? "");
|
|
114
|
+
const queryTerms = options.queryTerms ?? extractSteeringTerms(query);
|
|
115
|
+
const intentTerms = options.intentTerms ?? extractSteeringTerms(intent ?? "");
|
|
116
|
+
const needsTextScan = queryTerms.length > 0 || intentTerms.length > 0;
|
|
111
117
|
const preferredSeq = options.preferredSeq ?? null;
|
|
112
118
|
let bestChunk: ChunkRow | null = null;
|
|
113
119
|
let bestScore = Number.NEGATIVE_INFINITY;
|
|
114
120
|
|
|
115
121
|
for (const chunk of chunks) {
|
|
116
|
-
const
|
|
122
|
+
const haystack =
|
|
123
|
+
needsTextScan && chunk.text.length > 0 ? chunk.text.toLowerCase() : "";
|
|
124
|
+
const queryScore = scoreLowerTextForTerms(haystack, queryTerms);
|
|
117
125
|
const intentScore =
|
|
118
|
-
|
|
126
|
+
scoreLowerTextForTerms(haystack, intentTerms) * options.intentWeight;
|
|
119
127
|
const preferredBonus =
|
|
120
128
|
preferredSeq !== null && chunk.seq === preferredSeq
|
|
121
129
|
? MATCH_ANCHOR_BONUS
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { StorePort } from "../store/types";
|
|
1
|
+
import type { StorePort, TagRow } from "../store/types";
|
|
2
2
|
import type { RankedInput } from "./fusion";
|
|
3
3
|
import type { RequestHydration } from "./hydration";
|
|
4
4
|
import type { HybridSearchOptions } from "./types";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
compileDocumentFilters,
|
|
8
|
+
evaluateRetrievalEligibility,
|
|
9
|
+
} from "./filters";
|
|
7
10
|
|
|
8
11
|
export class OwnerMetadataError extends Error {}
|
|
9
12
|
|
|
@@ -13,9 +16,11 @@ export async function resolveFusionOwners(
|
|
|
13
16
|
store: StorePort,
|
|
14
17
|
hydration: RequestHydration,
|
|
15
18
|
query: string,
|
|
16
|
-
options: HybridSearchOptions
|
|
19
|
+
options: HybridSearchOptions,
|
|
20
|
+
forceResolve = false
|
|
17
21
|
): Promise<RankedInput[]> {
|
|
18
22
|
if (
|
|
23
|
+
!forceResolve &&
|
|
19
24
|
!inputs.some((input) =>
|
|
20
25
|
input.results.some((result) => result.documentId !== undefined)
|
|
21
26
|
)
|
|
@@ -28,30 +33,64 @@ export async function resolveFusionOwners(
|
|
|
28
33
|
)
|
|
29
34
|
),
|
|
30
35
|
];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
if (hashes.length === 0) return inputs;
|
|
37
|
+
const [documents, chunks] = await Promise.all([
|
|
38
|
+
hydration.getDocumentsByMirrorHashes(hashes, {
|
|
39
|
+
collection: options.collection,
|
|
40
|
+
collections: options.collections,
|
|
41
|
+
activeOnly: true,
|
|
42
|
+
}),
|
|
43
|
+
hydration.getChunksBatch(hashes),
|
|
44
|
+
]);
|
|
37
45
|
if (!documents.ok || !chunks.ok)
|
|
38
46
|
throw new OwnerMetadataError("Vector owner metadata unavailable");
|
|
47
|
+
|
|
39
48
|
let memoryIds: Set<number> | undefined;
|
|
40
|
-
|
|
49
|
+
const needsTags = Boolean(options.tagsAll?.length || options.tagsAny?.length);
|
|
50
|
+
const candidateDocs = documents.value.filter((doc) =>
|
|
51
|
+
Boolean(doc.mirrorHash)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const memoryPromise = options.memoryFilter
|
|
55
|
+
? Promise.all(
|
|
56
|
+
[...new Set(documents.value.map((doc) => doc.collection))].map(
|
|
57
|
+
(collection) =>
|
|
58
|
+
store.listMemoryEligibleDocuments({
|
|
59
|
+
collection,
|
|
60
|
+
scopes: options.memoryFilter!.scopes,
|
|
61
|
+
excludeSuperseded: options.memoryFilter!.excludeSuperseded,
|
|
62
|
+
})
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
: undefined;
|
|
66
|
+
|
|
67
|
+
const tagsPromise =
|
|
68
|
+
needsTags &&
|
|
69
|
+
candidateDocs.length > 0 &&
|
|
70
|
+
typeof store.getTagsBatch === "function"
|
|
71
|
+
? store.getTagsBatch(candidateDocs.map((doc) => doc.id))
|
|
72
|
+
: undefined;
|
|
73
|
+
|
|
74
|
+
const [memoryResults, tagsResult] = await Promise.all([
|
|
75
|
+
memoryPromise,
|
|
76
|
+
tagsPromise,
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
if (memoryResults) {
|
|
41
80
|
memoryIds = new Set();
|
|
42
|
-
for (const
|
|
43
|
-
documents.value.map((doc) => doc.collection)
|
|
44
|
-
)) {
|
|
45
|
-
const eligible = await store.listMemoryEligibleDocuments({
|
|
46
|
-
collection,
|
|
47
|
-
scopes: options.memoryFilter.scopes,
|
|
48
|
-
excludeSuperseded: options.memoryFilter.excludeSuperseded,
|
|
49
|
-
});
|
|
81
|
+
for (const eligible of memoryResults) {
|
|
50
82
|
if (!eligible.ok)
|
|
51
83
|
throw new OwnerMetadataError("Memory owner metadata unavailable");
|
|
52
84
|
for (const doc of eligible.value) memoryIds.add(doc.id);
|
|
53
85
|
}
|
|
54
86
|
}
|
|
87
|
+
|
|
88
|
+
let prefetchedTags: Map<number, TagRow[]> | null | undefined;
|
|
89
|
+
if (tagsPromise) {
|
|
90
|
+
prefetchedTags = tagsResult?.ok ? tagsResult.value : null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const compiledFilters = compileDocumentFilters(query, options);
|
|
55
94
|
const docids = new Map(documents.value.map((doc) => [doc.id, doc.docid]));
|
|
56
95
|
const owners = new Map<string, number[]>();
|
|
57
96
|
for (const doc of documents.value) {
|
|
@@ -61,7 +100,10 @@ export async function resolveFusionOwners(
|
|
|
61
100
|
query,
|
|
62
101
|
doc,
|
|
63
102
|
chunks.value.get(doc.mirrorHash),
|
|
64
|
-
options
|
|
103
|
+
options,
|
|
104
|
+
undefined,
|
|
105
|
+
compiledFilters,
|
|
106
|
+
prefetchedTags
|
|
65
107
|
);
|
|
66
108
|
for (const chunk of eligibility.chunks) {
|
|
67
109
|
const key = `${doc.mirrorHash}:${chunk.seq}`;
|
|
@@ -4,7 +4,20 @@
|
|
|
4
4
|
* IMPORTANT: This affects prompt selection and metadata ONLY.
|
|
5
5
|
* It does NOT affect retrieval filtering - that's controlled by CLI --lang flag.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type FrancFn = typeof import("franc").franc;
|
|
8
|
+
let cachedFranc: FrancFn | null = null;
|
|
9
|
+
|
|
10
|
+
function getFranc(): FrancFn {
|
|
11
|
+
if (!cachedFranc) {
|
|
12
|
+
// Static require("franc") is bundled by `bun build --compile` into
|
|
13
|
+
// standalone executables while still remaining lazily evaluated at runtime
|
|
14
|
+
// until a >= 15-char query without `--lang` arrives.
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
16
|
+
const mod = require("franc") as { franc: FrancFn };
|
|
17
|
+
cachedFranc = mod.franc;
|
|
18
|
+
}
|
|
19
|
+
return cachedFranc;
|
|
20
|
+
}
|
|
8
21
|
|
|
9
22
|
const MIN_RELIABLE_LENGTH = 15;
|
|
10
23
|
|
|
@@ -101,7 +114,7 @@ export function detectQueryLanguage(text: string): LanguageDetection {
|
|
|
101
114
|
return { bcp47: "und", iso639_3: "und", confident: false };
|
|
102
115
|
}
|
|
103
116
|
|
|
104
|
-
const detected =
|
|
117
|
+
const detected = getFranc()(trimmed, {
|
|
105
118
|
minLength: MIN_RELIABLE_LENGTH,
|
|
106
119
|
only: SUPPORTED_LANGUAGES,
|
|
107
120
|
});
|
package/src/pipeline/rerank.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "../llm/inference-scope";
|
|
16
16
|
import {
|
|
17
17
|
buildIntentAwareRerankQuery,
|
|
18
|
+
extractSteeringTerms,
|
|
18
19
|
selectBestChunkForSteering,
|
|
19
20
|
} from "./intent";
|
|
20
21
|
import { DEFAULT_BLENDING_SCHEDULE } from "./types";
|
|
@@ -119,40 +120,32 @@ async function fetchChunkTexts(
|
|
|
119
120
|
const chunksByHash: Map<string, ChunkRow[]> = chunksBatchResult.ok
|
|
120
121
|
? chunksBatchResult.value
|
|
121
122
|
: new Map();
|
|
122
|
-
const
|
|
123
|
-
const ownerHashes = new Map(
|
|
124
|
-
toRerank.map((candidate) => [
|
|
125
|
-
rerankOwnerKey(candidate),
|
|
126
|
-
candidate.mirrorHash,
|
|
127
|
-
])
|
|
128
|
-
);
|
|
123
|
+
const bestByOwner = new Map<string, FusionCandidate>();
|
|
124
|
+
const ownerHashes = new Map<string, string>();
|
|
129
125
|
|
|
130
126
|
for (const candidate of toRerank) {
|
|
131
127
|
assertInferenceActive();
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
139
|
-
if (
|
|
140
|
-
existingCandidate &&
|
|
141
|
-
existingCandidate.fusionScore >= candidate.fusionScore
|
|
142
|
-
) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
128
|
+
const ownerKey = rerankOwnerKey(candidate);
|
|
129
|
+
if (!ownerHashes.has(ownerKey)) {
|
|
130
|
+
ownerHashes.set(ownerKey, candidate.mirrorHash);
|
|
131
|
+
}
|
|
132
|
+
const existing = bestByOwner.get(ownerKey);
|
|
133
|
+
if (!existing || candidate.fusionScore > existing.fusionScore) {
|
|
134
|
+
bestByOwner.set(ownerKey, candidate);
|
|
145
135
|
}
|
|
146
|
-
preferredSeqByHash.set(rerankOwnerKey(candidate), candidate.seq);
|
|
147
136
|
}
|
|
148
137
|
|
|
138
|
+
const queryTerms = extractSteeringTerms(query);
|
|
139
|
+
const intentTerms = extractSteeringTerms(intent ?? "");
|
|
149
140
|
const chunkTexts = new Map<string, string>();
|
|
150
141
|
for (const [hash, mirrorHash] of ownerHashes) {
|
|
151
142
|
assertInferenceActive();
|
|
152
143
|
const chunks = chunksByHash.get(mirrorHash);
|
|
153
144
|
const bestChunk = selectBestChunkForSteering(chunks ?? [], query, intent, {
|
|
154
|
-
preferredSeq:
|
|
145
|
+
preferredSeq: bestByOwner.get(hash)?.seq ?? null,
|
|
155
146
|
intentWeight: 0.5,
|
|
147
|
+
queryTerms,
|
|
148
|
+
intentTerms,
|
|
156
149
|
});
|
|
157
150
|
const text = bestChunk?.text ?? "";
|
|
158
151
|
chunkTexts.set(
|