@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
|
@@ -11,6 +11,8 @@ import type { StoreResult } from "../types";
|
|
|
11
11
|
import type { BacklogItem, VectorStatsPort } from "./types";
|
|
12
12
|
|
|
13
13
|
import { err, ok } from "../types";
|
|
14
|
+
import { currentOwnerCount } from "./runtime-compat";
|
|
15
|
+
import { storedVectorPartition } from "./status";
|
|
14
16
|
|
|
15
17
|
const statsDatabases = new WeakMap<VectorStatsPort, Database>();
|
|
16
18
|
|
|
@@ -56,11 +58,17 @@ export function createVectorStatsPort(db: Database): VectorStatsPort {
|
|
|
56
58
|
const port: VectorStatsPort = {
|
|
57
59
|
countVectors(model: string): Promise<StoreResult<number>> {
|
|
58
60
|
try {
|
|
61
|
+
const partition = storedVectorPartition(db, model);
|
|
62
|
+
if (partition) {
|
|
63
|
+
return Promise.resolve(
|
|
64
|
+
ok(currentOwnerCount(db, partition.partitionId))
|
|
65
|
+
);
|
|
66
|
+
}
|
|
59
67
|
const result = db
|
|
60
|
-
.
|
|
68
|
+
.query<{ count: number }, [string]>(
|
|
61
69
|
"SELECT COUNT(*) as count FROM content_vectors WHERE model = ?"
|
|
62
70
|
)
|
|
63
|
-
.get(model)
|
|
71
|
+
.get(model)!;
|
|
64
72
|
return Promise.resolve(ok(result.count));
|
|
65
73
|
} catch (e) {
|
|
66
74
|
return Promise.resolve(
|
|
@@ -84,21 +92,17 @@ export function createVectorStatsPort(db: Database): VectorStatsPort {
|
|
|
84
92
|
const sql = `
|
|
85
93
|
SELECT COUNT(*) as count
|
|
86
94
|
FROM content_chunks c
|
|
95
|
+
LEFT JOIN content_vectors v
|
|
96
|
+
ON v.mirror_hash = c.mirror_hash
|
|
97
|
+
AND v.seq = c.seq
|
|
98
|
+
AND v.model = ?
|
|
99
|
+
AND v.embed_fingerprint = ?
|
|
87
100
|
WHERE ${activeDoc.sql}
|
|
88
|
-
|
|
89
|
-
SELECT 1 FROM content_vectors v
|
|
90
|
-
WHERE v.mirror_hash = c.mirror_hash
|
|
91
|
-
AND v.seq = c.seq
|
|
92
|
-
AND v.model = ?
|
|
93
|
-
AND v.embed_fingerprint = ?
|
|
94
|
-
AND v.embedded_at >= c.created_at
|
|
95
|
-
)
|
|
101
|
+
AND (v.mirror_hash IS NULL OR v.embedded_at IS NULL OR v.embedded_at < c.created_at)
|
|
96
102
|
`;
|
|
97
103
|
const result = db
|
|
98
|
-
.
|
|
99
|
-
.get(...activeDoc.params
|
|
100
|
-
count: number;
|
|
101
|
-
};
|
|
104
|
+
.query<{ count: number }, string[]>(sql)
|
|
105
|
+
.get(model, embedFingerprint, ...activeDoc.params)!;
|
|
102
106
|
return Promise.resolve(ok(result.count));
|
|
103
107
|
} catch (e) {
|
|
104
108
|
return Promise.resolve(
|
|
@@ -124,86 +128,46 @@ export function createVectorStatsPort(db: Database): VectorStatsPort {
|
|
|
124
128
|
const after = options?.after;
|
|
125
129
|
const activeDoc = buildActiveDocumentExistsClause(options?.collection);
|
|
126
130
|
|
|
127
|
-
// Seek pagination:
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
(SELECT d.title FROM documents d WHERE d.mirror_hash = c.mirror_hash AND d.active = 1 ORDER BY d.id LIMIT 1) as title,
|
|
134
|
-
CASE
|
|
135
|
-
WHEN NOT EXISTS (
|
|
136
|
-
SELECT 1 FROM content_vectors v
|
|
137
|
-
WHERE v.mirror_hash = c.mirror_hash
|
|
138
|
-
AND v.seq = c.seq
|
|
139
|
-
AND v.model = ?
|
|
140
|
-
AND v.embed_fingerprint = ?
|
|
141
|
-
) THEN 'new'
|
|
142
|
-
ELSE 'changed'
|
|
143
|
-
END as reason
|
|
144
|
-
FROM content_chunks c
|
|
145
|
-
WHERE ${activeDoc.sql}
|
|
146
|
-
AND NOT EXISTS (
|
|
147
|
-
SELECT 1 FROM content_vectors v
|
|
148
|
-
WHERE v.mirror_hash = c.mirror_hash
|
|
149
|
-
AND v.seq = c.seq
|
|
150
|
-
AND v.model = ?
|
|
151
|
-
AND v.embed_fingerprint = ?
|
|
152
|
-
AND v.embedded_at >= c.created_at
|
|
153
|
-
)
|
|
154
|
-
AND (c.mirror_hash > ? OR (c.mirror_hash = ? AND c.seq > ?))
|
|
155
|
-
ORDER BY c.mirror_hash, c.seq
|
|
156
|
-
LIMIT ?
|
|
157
|
-
`
|
|
158
|
-
: `
|
|
131
|
+
// Seek pagination: single LEFT JOIN computes both pending eligibility
|
|
132
|
+
// and 'new' vs 'changed' reason without double NOT EXISTS lookups.
|
|
133
|
+
const cursorClause = after
|
|
134
|
+
? "AND (c.mirror_hash > ? OR (c.mirror_hash = ? AND c.seq > ?))"
|
|
135
|
+
: "";
|
|
136
|
+
const sql = `
|
|
159
137
|
SELECT c.mirror_hash as mirrorHash, c.seq, c.text,
|
|
160
138
|
(SELECT d.title FROM documents d WHERE d.mirror_hash = c.mirror_hash AND d.active = 1 ORDER BY d.id LIMIT 1) as title,
|
|
161
139
|
CASE
|
|
162
|
-
WHEN
|
|
163
|
-
SELECT 1 FROM content_vectors v
|
|
164
|
-
WHERE v.mirror_hash = c.mirror_hash
|
|
165
|
-
AND v.seq = c.seq
|
|
166
|
-
AND v.model = ?
|
|
167
|
-
AND v.embed_fingerprint = ?
|
|
168
|
-
) THEN 'new'
|
|
140
|
+
WHEN v.mirror_hash IS NULL THEN 'new'
|
|
169
141
|
ELSE 'changed'
|
|
170
142
|
END as reason
|
|
171
143
|
FROM content_chunks c
|
|
144
|
+
LEFT JOIN content_vectors v
|
|
145
|
+
ON v.mirror_hash = c.mirror_hash
|
|
146
|
+
AND v.seq = c.seq
|
|
147
|
+
AND v.model = ?
|
|
148
|
+
AND v.embed_fingerprint = ?
|
|
172
149
|
WHERE ${activeDoc.sql}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
WHERE v.mirror_hash = c.mirror_hash
|
|
176
|
-
AND v.seq = c.seq
|
|
177
|
-
AND v.model = ?
|
|
178
|
-
AND v.embed_fingerprint = ?
|
|
179
|
-
AND v.embedded_at >= c.created_at
|
|
180
|
-
)
|
|
150
|
+
AND (v.mirror_hash IS NULL OR v.embedded_at IS NULL OR v.embedded_at < c.created_at)
|
|
151
|
+
${cursorClause}
|
|
181
152
|
ORDER BY c.mirror_hash, c.seq
|
|
182
153
|
LIMIT ?
|
|
183
154
|
`;
|
|
184
155
|
|
|
185
|
-
const params = after
|
|
156
|
+
const params: (string | number)[] = after
|
|
186
157
|
? [
|
|
187
158
|
model,
|
|
188
159
|
embedFingerprint,
|
|
189
160
|
...activeDoc.params,
|
|
190
|
-
model,
|
|
191
|
-
embedFingerprint,
|
|
192
161
|
after.mirrorHash,
|
|
193
162
|
after.mirrorHash,
|
|
194
163
|
after.seq,
|
|
195
164
|
limit,
|
|
196
165
|
]
|
|
197
|
-
: [
|
|
198
|
-
model,
|
|
199
|
-
embedFingerprint,
|
|
200
|
-
...activeDoc.params,
|
|
201
|
-
model,
|
|
202
|
-
embedFingerprint,
|
|
203
|
-
limit,
|
|
204
|
-
];
|
|
166
|
+
: [model, embedFingerprint, ...activeDoc.params, limit];
|
|
205
167
|
|
|
206
|
-
const results = db
|
|
168
|
+
const results = db
|
|
169
|
+
.query<BacklogItem, (string | number)[]>(sql)
|
|
170
|
+
.all(...params);
|
|
207
171
|
return Promise.resolve(ok(results));
|
|
208
172
|
} catch (e) {
|
|
209
173
|
return Promise.resolve(
|
|
@@ -3,6 +3,7 @@ import type { Database } from "bun:sqlite";
|
|
|
3
3
|
|
|
4
4
|
import { getEmbeddingFingerprint } from "../../embed/fingerprint";
|
|
5
5
|
import { formatDocForEmbedding } from "../../pipeline/contextual";
|
|
6
|
+
import { provenOwners, vectorProofKey } from "./proof-cache";
|
|
6
7
|
import {
|
|
7
8
|
currentOwnerCount,
|
|
8
9
|
identityPartitionId,
|
|
@@ -10,6 +11,12 @@ import {
|
|
|
10
11
|
retrievalUse,
|
|
11
12
|
selectRuntimePartition,
|
|
12
13
|
} from "./runtime-compat";
|
|
14
|
+
import {
|
|
15
|
+
dropV2PartitionMirrorInTx,
|
|
16
|
+
getV2MirrorStatus,
|
|
17
|
+
hasV2MirrorTables,
|
|
18
|
+
type V2MirrorStatusInfo,
|
|
19
|
+
} from "./v2-mirror";
|
|
13
20
|
import {
|
|
14
21
|
embeddingInputHash,
|
|
15
22
|
loadSqliteVec,
|
|
@@ -51,6 +58,8 @@ export interface VectorPartitionStatus {
|
|
|
51
58
|
compatibleRuntimes: string[];
|
|
52
59
|
/** Runtimes measured incompatible; they need another partition or lexical. */
|
|
53
60
|
incompatibleRuntimes: string[];
|
|
61
|
+
/** Bit coarse vec0 mirror status (fn-235); omitted on pre-v39 schemas. */
|
|
62
|
+
coarseMirror?: V2MirrorStatusInfo;
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
/** The calling process's runtime, resolved exactly as its queries resolve it. */
|
|
@@ -224,6 +233,7 @@ export function listVectorPartitions(
|
|
|
224
233
|
const runtimes = db.prepare<{ label: string }, [string, string]>(
|
|
225
234
|
"SELECT DISTINCT label FROM vector_runtime_verdicts WHERE partition_id = ? AND verdict = ? ORDER BY label"
|
|
226
235
|
);
|
|
236
|
+
const trackV2 = hasV2MirrorTables(db);
|
|
227
237
|
return partitions.map(
|
|
228
238
|
(p): VectorPartitionStatus => ({
|
|
229
239
|
id: p.partition_id,
|
|
@@ -246,6 +256,11 @@ export function listVectorPartitions(
|
|
|
246
256
|
incompatibleRuntimes: runtimes
|
|
247
257
|
.all(p.partition_id, "incompatible")
|
|
248
258
|
.map((row) => row.label),
|
|
259
|
+
...(trackV2
|
|
260
|
+
? {
|
|
261
|
+
coarseMirror: getV2MirrorStatus(db, p.partition_id, p.dimensions),
|
|
262
|
+
}
|
|
263
|
+
: {}),
|
|
249
264
|
})
|
|
250
265
|
);
|
|
251
266
|
})();
|
|
@@ -257,7 +272,6 @@ interface OwnerCoverage {
|
|
|
257
272
|
collection: string;
|
|
258
273
|
mirror_hash: string;
|
|
259
274
|
seq: number;
|
|
260
|
-
text: string;
|
|
261
275
|
title: string | null;
|
|
262
276
|
input_hash: string | null;
|
|
263
277
|
embedding_bytes: number | null;
|
|
@@ -269,6 +283,7 @@ export function getVariantStatus(
|
|
|
269
283
|
db: Database,
|
|
270
284
|
options?: { embedModel?: string; embedFingerprint?: string }
|
|
271
285
|
): { backlog: number; embeddedByCollection: Map<string, number> } | null {
|
|
286
|
+
const inOuterTx = db.inTransaction;
|
|
272
287
|
return db.transaction(() => {
|
|
273
288
|
if (!hasPartitionTable(db)) return null;
|
|
274
289
|
const partitions = readPartitions(db, options?.embedModel ?? null);
|
|
@@ -308,71 +323,169 @@ export function getVariantStatus(
|
|
|
308
323
|
usablePartitions.set(partition.partition_id, partition);
|
|
309
324
|
}
|
|
310
325
|
if (authoritativeModels.size === 0) return null;
|
|
326
|
+
const proofs = provenOwners(db, inOuterTx);
|
|
327
|
+
const usableJson = JSON.stringify([...usablePartitions.keys()]);
|
|
328
|
+
const scopedToModel = Boolean(options?.embedModel);
|
|
311
329
|
// Unscoped legacy coverage remains valid only for models that have never
|
|
312
|
-
// selected or activated verified authority;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
330
|
+
// selected or activated verified authority; omit the legacy CTE entirely
|
|
331
|
+
// when embedModel is set, and defer c.text reads to uncached bound rows.
|
|
332
|
+
const sql = scopedToModel
|
|
333
|
+
? `
|
|
334
|
+
SELECT d.id AS document_id, o.partition_id, d.collection, d.mirror_hash, c.seq, d.title,
|
|
335
|
+
v.input_hash, length(v.embedding) AS embedding_bytes,
|
|
336
|
+
0 AS legacy_embedded
|
|
337
|
+
FROM documents d
|
|
338
|
+
JOIN content_chunks c ON c.mirror_hash = d.mirror_hash
|
|
339
|
+
LEFT JOIN vector_owners o ON o.document_id = d.id AND o.seq = c.seq
|
|
340
|
+
AND o.mirror_hash = d.mirror_hash
|
|
341
|
+
AND o.partition_id IN (SELECT value FROM json_each(?))
|
|
342
|
+
LEFT JOIN vector_variants v ON v.variant_id = o.variant_id
|
|
343
|
+
AND v.partition_id = o.partition_id
|
|
344
|
+
WHERE d.active = 1
|
|
345
|
+
`
|
|
346
|
+
: `
|
|
347
|
+
WITH legacy_vectors AS (
|
|
348
|
+
SELECT mirror_hash, seq, MAX(embedded_at) AS embedded_at
|
|
349
|
+
FROM content_vectors
|
|
350
|
+
WHERE model NOT IN (SELECT value FROM json_each(?))
|
|
351
|
+
GROUP BY mirror_hash, seq
|
|
352
|
+
)
|
|
353
|
+
SELECT d.id AS document_id, o.partition_id, d.collection, d.mirror_hash, c.seq, d.title,
|
|
354
|
+
v.input_hash, length(v.embedding) AS embedding_bytes,
|
|
355
|
+
CASE WHEN lv.embedded_at >= c.created_at THEN 1 ELSE 0 END AS legacy_embedded
|
|
356
|
+
FROM documents d
|
|
357
|
+
JOIN content_chunks c ON c.mirror_hash = d.mirror_hash
|
|
358
|
+
LEFT JOIN vector_owners o ON o.document_id = d.id AND o.seq = c.seq
|
|
359
|
+
AND o.mirror_hash = d.mirror_hash
|
|
360
|
+
AND o.partition_id IN (SELECT value FROM json_each(?))
|
|
361
|
+
LEFT JOIN vector_variants v ON v.variant_id = o.variant_id
|
|
362
|
+
AND v.partition_id = o.partition_id
|
|
363
|
+
LEFT JOIN legacy_vectors lv ON lv.mirror_hash = c.mirror_hash AND lv.seq = c.seq
|
|
364
|
+
WHERE d.active = 1
|
|
365
|
+
`;
|
|
366
|
+
const statement = db.prepare<OwnerCoverage, string[]>(sql);
|
|
367
|
+
const statementParams = scopedToModel
|
|
368
|
+
? [usableJson]
|
|
369
|
+
: [JSON.stringify([...authoritativeModels]), usableJson];
|
|
336
370
|
const owners = new Map<
|
|
337
371
|
string,
|
|
338
372
|
{ collection: string; chunk: string; embedded: boolean }
|
|
339
373
|
>();
|
|
374
|
+
const pendingProofs: Array<{
|
|
375
|
+
ownerKey: string;
|
|
376
|
+
proofKey: string;
|
|
377
|
+
mirrorHash: string;
|
|
378
|
+
seq: number;
|
|
379
|
+
title: string | null;
|
|
380
|
+
model: string;
|
|
381
|
+
inputHash: string;
|
|
382
|
+
}> = [];
|
|
383
|
+
const neededChunks = new Map<string, [string, number]>();
|
|
384
|
+
const PROOF_TEXT_BATCH_SIZE = 512;
|
|
385
|
+
const fetchChunkTexts = db.query<
|
|
386
|
+
{ mirror_hash: string; seq: number; text: string },
|
|
387
|
+
[string]
|
|
388
|
+
>(`
|
|
389
|
+
WITH req AS (
|
|
390
|
+
SELECT
|
|
391
|
+
json_extract(value, '$[0]') AS mirror_hash,
|
|
392
|
+
json_extract(value, '$[1]') AS seq
|
|
393
|
+
FROM json_each(?)
|
|
394
|
+
)
|
|
395
|
+
SELECT c.mirror_hash, c.seq, c.text
|
|
396
|
+
FROM req r
|
|
397
|
+
JOIN content_chunks c ON c.mirror_hash = r.mirror_hash AND c.seq = r.seq
|
|
398
|
+
`);
|
|
399
|
+
const flushPendingProofs = (): void => {
|
|
400
|
+
if (pendingProofs.length === 0) return;
|
|
401
|
+
const textByChunk = new Map<string, string>();
|
|
402
|
+
const chunkEntries = [...neededChunks.values()];
|
|
403
|
+
for (const row of fetchChunkTexts.all(JSON.stringify(chunkEntries))) {
|
|
404
|
+
textByChunk.set(`${row.mirror_hash}\0${row.seq}`, row.text);
|
|
405
|
+
}
|
|
406
|
+
for (const item of pendingProofs) {
|
|
407
|
+
const owner = owners.get(item.ownerKey);
|
|
408
|
+
if (!owner) continue;
|
|
409
|
+
let valid = proofs.get(item.proofKey);
|
|
410
|
+
if (valid === undefined) {
|
|
411
|
+
const text = textByChunk.get(`${item.mirrorHash}\0${item.seq}`);
|
|
412
|
+
valid =
|
|
413
|
+
text !== undefined &&
|
|
414
|
+
item.inputHash ===
|
|
415
|
+
embeddingInputHash(
|
|
416
|
+
formatDocForEmbedding(text, item.title ?? undefined, item.model)
|
|
417
|
+
);
|
|
418
|
+
proofs.set(item.proofKey, valid);
|
|
419
|
+
}
|
|
420
|
+
if (valid) owner.embedded = true;
|
|
421
|
+
}
|
|
422
|
+
pendingProofs.length = 0;
|
|
423
|
+
neededChunks.clear();
|
|
424
|
+
};
|
|
340
425
|
try {
|
|
341
|
-
for (const row of statement.iterate(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
426
|
+
for (const row of statement.iterate(...statementParams)) {
|
|
427
|
+
const ownerKey = `${row.document_id}:${row.seq}`;
|
|
428
|
+
let owner = owners.get(ownerKey);
|
|
429
|
+
if (!owner) {
|
|
430
|
+
owner = {
|
|
431
|
+
collection: row.collection,
|
|
432
|
+
chunk: `${row.mirror_hash}\0${row.seq}`,
|
|
433
|
+
embedded: false,
|
|
434
|
+
};
|
|
435
|
+
owners.set(ownerKey, owner);
|
|
436
|
+
}
|
|
437
|
+
if (owner.embedded) continue;
|
|
438
|
+
if (row.legacy_embedded) {
|
|
439
|
+
owner.embedded = true;
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
346
442
|
const partition = row.partition_id
|
|
347
443
|
? usablePartitions.get(row.partition_id)
|
|
348
444
|
: undefined;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
445
|
+
if (
|
|
446
|
+
!partition ||
|
|
447
|
+
row.input_hash === null ||
|
|
448
|
+
row.embedding_bytes !==
|
|
449
|
+
partition.dimensions * Float32Array.BYTES_PER_ELEMENT
|
|
450
|
+
) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
const pKey = vectorProofKey(
|
|
454
|
+
partition.model,
|
|
455
|
+
row.document_id,
|
|
456
|
+
row.mirror_hash,
|
|
457
|
+
row.seq,
|
|
458
|
+
row.input_hash
|
|
362
459
|
);
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
460
|
+
const cached = proofs.get(pKey);
|
|
461
|
+
if (cached !== undefined) {
|
|
462
|
+
if (cached) owner.embedded = true;
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
pendingProofs.push({
|
|
466
|
+
ownerKey,
|
|
467
|
+
proofKey: pKey,
|
|
468
|
+
mirrorHash: row.mirror_hash,
|
|
469
|
+
seq: row.seq,
|
|
470
|
+
title: row.title,
|
|
471
|
+
model: partition.model,
|
|
472
|
+
inputHash: row.input_hash,
|
|
473
|
+
});
|
|
474
|
+
const chunkKey = `${row.mirror_hash}\0${row.seq}`;
|
|
475
|
+
if (!neededChunks.has(chunkKey)) {
|
|
476
|
+
neededChunks.set(chunkKey, [row.mirror_hash, row.seq]);
|
|
477
|
+
}
|
|
478
|
+
if (
|
|
479
|
+
neededChunks.size >= PROOF_TEXT_BATCH_SIZE ||
|
|
480
|
+
pendingProofs.length >= PROOF_TEXT_BATCH_SIZE
|
|
481
|
+
) {
|
|
482
|
+
flushPendingProofs();
|
|
483
|
+
}
|
|
372
484
|
}
|
|
373
485
|
} finally {
|
|
374
486
|
statement.finalize();
|
|
375
487
|
}
|
|
488
|
+
flushPendingProofs();
|
|
376
489
|
const collections = new Map<string, Map<string, boolean>>();
|
|
377
490
|
let backlog = 0;
|
|
378
491
|
for (const owner of owners.values()) {
|
|
@@ -440,9 +553,11 @@ export async function dropVectorPartition(
|
|
|
440
553
|
: `Refusing to drop active partition ${partition.id.slice(0, 12)}: other runtimes may read it, or it awaits its one-time re-key`,
|
|
441
554
|
};
|
|
442
555
|
const table = `vec_v1_${partition.id}`;
|
|
556
|
+
const v2Table = `vec_v2_${partition.id}`;
|
|
443
557
|
if (
|
|
444
558
|
!vecLoaded &&
|
|
445
|
-
db.query("SELECT 1 FROM sqlite_master WHERE name = ?").get(table)
|
|
559
|
+
(db.query("SELECT 1 FROM sqlite_master WHERE name = ?").get(table) ||
|
|
560
|
+
db.query("SELECT 1 FROM sqlite_master WHERE name = ?").get(v2Table))
|
|
446
561
|
)
|
|
447
562
|
return {
|
|
448
563
|
ok: false,
|
|
@@ -458,6 +573,7 @@ export async function dropVectorPartition(
|
|
|
458
573
|
])
|
|
459
574
|
db.run(statement, [partition.id]);
|
|
460
575
|
db.exec(`DROP TABLE IF EXISTS ${table}`);
|
|
576
|
+
dropV2PartitionMirrorInTx(db, partition.id);
|
|
461
577
|
return { ok: true, partition };
|
|
462
578
|
})
|
|
463
579
|
.immediate();
|