@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.
Files changed (218) hide show
  1. package/README.md +1 -1
  2. package/assets/skill/SKILL.md +27 -0
  3. package/assets/skill/cli-reference.md +24 -15
  4. package/assets/spa-production.json.gz +0 -0
  5. package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.17.0.zip} +0 -0
  6. package/browser-extension/artifacts/gno-browser-clipper-v2.17.0.zip.sha256 +1 -0
  7. package/browser-extension/dist/manifest.json +1 -1
  8. package/package.json +1 -1
  9. package/spec/cli.md +43 -3
  10. package/spec/db/schema.sql +53 -1
  11. package/spec/mcp.md +9 -3
  12. package/spec/output-schemas/doctor.schema.json +27 -0
  13. package/spec/output-schemas/retrieval-trace-payloads.schema.json +14 -0
  14. package/spec/output-schemas/search-results.schema.json +14 -0
  15. package/spec/output-schemas/status.schema.json +22 -0
  16. package/src/cli/commands/agents/commands.ts +1 -1
  17. package/src/cli/commands/ask.ts +1 -1
  18. package/src/cli/commands/context-build.ts +1 -1
  19. package/src/cli/commands/doctor.ts +101 -29
  20. package/src/cli/commands/embed.ts +2 -2
  21. package/src/cli/commands/links.ts +30 -6
  22. package/src/cli/commands/mcp/install.ts +2 -2
  23. package/src/cli/commands/mcp/status.ts +1 -1
  24. package/src/cli/commands/mcp/uninstall.ts +1 -1
  25. package/src/cli/commands/query.ts +1 -1
  26. package/src/cli/commands/shared.ts +4 -4
  27. package/src/cli/commands/skill/install.ts +1 -1
  28. package/src/cli/commands/skill/paths-cmd.ts +1 -1
  29. package/src/cli/commands/skill/uninstall.ts +1 -1
  30. package/src/cli/commands/status.ts +75 -58
  31. package/src/cli/commands/vec.ts +180 -8
  32. package/src/cli/config-cache.ts +86 -0
  33. package/src/cli/globals.ts +64 -0
  34. package/src/cli/program.ts +63 -36
  35. package/src/cli/run.ts +121 -67
  36. package/src/cli/runtime-health.ts +132 -122
  37. package/src/cli/session-binding.ts +11 -2
  38. package/src/config/saver.ts +8 -0
  39. package/src/config/types.ts +6 -0
  40. package/src/converters/adapters/browser-export/formats.ts +25 -15
  41. package/src/converters/adapters/email/adapter.ts +37 -53
  42. package/src/converters/adapters/email/html.ts +37 -20
  43. package/src/converters/adapters/email/mime.ts +71 -39
  44. package/src/converters/adapters/ical/adapter.ts +20 -12
  45. package/src/converters/adapters/jsonl/adapter.ts +8 -6
  46. package/src/converters/adapters/shared/html-text.ts +55 -37
  47. package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
  48. package/src/converters/adapters/shared/utf8-lines.ts +69 -31
  49. package/src/converters/adapters/transcript/adapter.ts +12 -7
  50. package/src/converters/adapters/xlsx/adapter.ts +10 -7
  51. package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
  52. package/src/converters/canonicalize.ts +17 -3
  53. package/src/converters/native/markdown.ts +24 -17
  54. package/src/converters/native/plaintext.ts +5 -6
  55. package/src/converters/registry.ts +130 -8
  56. package/src/core/activation-status.ts +4 -8
  57. package/src/core/change-diff.ts +38 -11
  58. package/src/core/context-compiler.ts +17 -18
  59. package/src/core/context-evidence.ts +116 -25
  60. package/src/core/context-verifier.ts +70 -31
  61. package/src/core/file-lock.ts +10 -2
  62. package/src/core/graph-analysis.ts +3 -3
  63. package/src/core/link-inventory-markdown.ts +2 -2
  64. package/src/core/links.ts +20 -87
  65. package/src/core/memory-fence.ts +16 -9
  66. package/src/core/memory-recall.ts +168 -34
  67. package/src/core/path-rules.ts +143 -0
  68. package/src/core/retrieval-trace-session.ts +3 -0
  69. package/src/core/retrieval-trace.ts +9 -0
  70. package/src/core/section-parse.ts +16 -6
  71. package/src/core/typed-metadata.ts +68 -0
  72. package/src/core/vector-partition-status.ts +13 -0
  73. package/src/core/wiki-link-syntax.ts +88 -0
  74. package/src/embed/backlog.ts +142 -60
  75. package/src/embed/retry.ts +39 -33
  76. package/src/embed/variant-backlog.ts +582 -116
  77. package/src/embed/variant-retry.ts +157 -48
  78. package/src/index.ts +3 -3
  79. package/src/ingestion/budget-error-codes.ts +13 -0
  80. package/src/ingestion/chunker.ts +60 -49
  81. package/src/ingestion/compiled-context.ts +4 -5
  82. package/src/ingestion/convert-file.ts +1 -1
  83. package/src/ingestion/document-metadata.ts +16 -9
  84. package/src/ingestion/excluded-ranges.ts +97 -0
  85. package/src/ingestion/file-processor.ts +122 -37
  86. package/src/ingestion/frontmatter.ts +35 -7
  87. package/src/ingestion/graph-reconciliation.ts +187 -51
  88. package/src/ingestion/language.ts +66 -61
  89. package/src/ingestion/position.ts +5 -5
  90. package/src/ingestion/prepare-file.ts +50 -29
  91. package/src/ingestion/record-adapter-canonical.ts +37 -26
  92. package/src/ingestion/record-adapter.ts +46 -26
  93. package/src/ingestion/record-container.ts +121 -53
  94. package/src/ingestion/record-path.ts +5 -2
  95. package/src/ingestion/source-availability/darwin-io.ts +10 -7
  96. package/src/ingestion/source-availability/darwin-path.ts +21 -3
  97. package/src/ingestion/source-availability/readers.ts +51 -0
  98. package/src/ingestion/strip.ts +39 -105
  99. package/src/ingestion/sync.ts +692 -386
  100. package/src/ingestion/typed-metadata.ts +10 -4
  101. package/src/ingestion/walker.ts +485 -158
  102. package/src/llm/cache.ts +128 -84
  103. package/src/llm/http-inference.ts +112 -35
  104. package/src/llm/http-policy.ts +101 -0
  105. package/src/llm/httpEmbedding.ts +8 -1
  106. package/src/llm/httpGeneration.ts +5 -1
  107. package/src/llm/httpRerank.ts +5 -1
  108. package/src/llm/inference-scope.ts +15 -2
  109. package/src/llm/lazy-ports.ts +33 -3
  110. package/src/llm/lockfile.ts +34 -7
  111. package/src/llm/model-cleanup.ts +24 -0
  112. package/src/llm/native-worker/client.ts +23 -12
  113. package/src/llm/native-worker/dispatcher.ts +19 -9
  114. package/src/llm/native-worker/embedding-identity.ts +42 -16
  115. package/src/llm/native-worker/entry.ts +2 -1
  116. package/src/llm/native-worker/owner.ts +1 -0
  117. package/src/llm/native-worker/ports.ts +86 -23
  118. package/src/llm/native-worker/protocol.ts +386 -55
  119. package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
  120. package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
  121. package/src/llm/nodeLlamaCpp/generation.ts +194 -30
  122. package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
  123. package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
  124. package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
  125. package/src/llm/types.ts +14 -0
  126. package/src/mcp/context.ts +342 -23
  127. package/src/mcp/http-transport.ts +21 -3
  128. package/src/mcp/tool-profile-types.ts +62 -0
  129. package/src/mcp/tool-profile.ts +32 -56
  130. package/src/mcp/tools/context.ts +5 -1
  131. package/src/mcp/tools/index.ts +269 -191
  132. package/src/mcp/tools/links.ts +14 -6
  133. package/src/mcp/tools/query.ts +60 -37
  134. package/src/mcp/tools/vsearch.ts +25 -14
  135. package/src/pipeline/answer.ts +133 -40
  136. package/src/pipeline/claim-verification.ts +293 -189
  137. package/src/pipeline/claim-verifier.ts +6 -7
  138. package/src/pipeline/egress-lineage.ts +37 -26
  139. package/src/pipeline/exclude.ts +34 -11
  140. package/src/pipeline/expansion.ts +233 -19
  141. package/src/pipeline/explain.ts +17 -2
  142. package/src/pipeline/filters.ts +169 -33
  143. package/src/pipeline/graph-retrieval.ts +117 -61
  144. package/src/pipeline/hybrid.ts +626 -330
  145. package/src/pipeline/hydration.ts +86 -24
  146. package/src/pipeline/intent.ts +15 -7
  147. package/src/pipeline/owner-fusion.ts +61 -19
  148. package/src/pipeline/query-language.ts +15 -2
  149. package/src/pipeline/rerank.ts +15 -22
  150. package/src/pipeline/search.ts +193 -72
  151. package/src/pipeline/snippet.ts +15 -2
  152. package/src/pipeline/temporal.ts +51 -10
  153. package/src/pipeline/types.ts +7 -0
  154. package/src/pipeline/vsearch.ts +269 -154
  155. package/src/publish/attachment-raster.ts +2 -16
  156. package/src/publish/encrypted-export.ts +15 -5
  157. package/src/serve/browse-tree.ts +50 -42
  158. package/src/serve/connectors.ts +2 -1
  159. package/src/serve/context.ts +13 -4
  160. package/src/serve/doc-events.ts +3 -0
  161. package/src/serve/public/app.tsx +49 -21
  162. package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
  163. package/src/serve/public/components/CaptureModal.tsx +14 -10
  164. package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
  165. package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
  166. package/src/serve/public/globals.built.css +1 -1
  167. package/src/serve/public/globals.css +19 -0
  168. package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
  169. package/src/serve/public/lib/metadata-filter.ts +234 -9
  170. package/src/serve/public/pages/Browse.tsx +61 -27
  171. package/src/serve/public/pages/DocView.tsx +44 -25
  172. package/src/serve/public/pages/GraphView.tsx +8 -3
  173. package/src/serve/resident-runtime.ts +199 -48
  174. package/src/serve/routes/api.ts +98 -67
  175. package/src/serve/routes/links.ts +25 -5
  176. package/src/serve/server.ts +1370 -1180
  177. package/src/serve/spa-bundle-source.ts +52 -27
  178. package/src/serve/status.ts +101 -52
  179. package/src/serve/watch-reconciliation-fallback.ts +11 -7
  180. package/src/serve/watch-reconciliation-shared.ts +42 -4
  181. package/src/serve/watch-reconciliation.ts +21 -8
  182. package/src/serve/watch-service-events.ts +7 -1
  183. package/src/serve/watch-service-hosts.ts +3 -1
  184. package/src/serve/watch-service.ts +46 -21
  185. package/src/serve/watch-snapshot-scan.ts +6 -15
  186. package/src/sessions/archive.ts +20 -8
  187. package/src/sessions/sanitize.ts +38 -18
  188. package/src/sessions/service.ts +180 -102
  189. package/src/store/migrations/037-performance-indexes.ts +56 -0
  190. package/src/store/migrations/038-vector-mirror-null-cosine.ts +47 -0
  191. package/src/store/migrations/039-vector-mirror-v2.ts +94 -0
  192. package/src/store/migrations/index.ts +6 -0
  193. package/src/store/sqlite/adapter.ts +1260 -651
  194. package/src/store/sqlite/chunking-policy.ts +15 -1
  195. package/src/store/sqlite/eligibility.ts +110 -70
  196. package/src/store/sqlite/graph-neighbors.ts +71 -46
  197. package/src/store/sqlite/graph-reference-state.ts +27 -3
  198. package/src/store/sqlite/graph-similarity.ts +59 -12
  199. package/src/store/sqlite/metadata-predicate.ts +123 -28
  200. package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
  201. package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
  202. package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
  203. package/src/store/types.ts +32 -0
  204. package/src/store/vector/coarse-router.ts +312 -0
  205. package/src/store/vector/eligibility.ts +39 -0
  206. package/src/store/vector/lazy.ts +17 -0
  207. package/src/store/vector/partition-index.ts +333 -59
  208. package/src/store/vector/proof-cache.ts +209 -0
  209. package/src/store/vector/runtime-compat.ts +6 -0
  210. package/src/store/vector/sqlite-vec.ts +270 -162
  211. package/src/store/vector/stats.ts +37 -73
  212. package/src/store/vector/status.ts +169 -53
  213. package/src/store/vector/stored-vectors.ts +131 -45
  214. package/src/store/vector/types.ts +19 -0
  215. package/src/store/vector/v2-mirror.ts +669 -0
  216. package/src/store/vector/variant-search.ts +1187 -111
  217. package/src/store/vector/variants.ts +964 -160
  218. package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
package/README.md CHANGED
@@ -139,7 +139,7 @@ See the [guide](docs/COMPILED-CONTEXT.md).
139
139
 
140
140
  <!-- public-truth:current-version -->
141
141
 
142
- > Current source version: **v2.15.0**. See [CHANGELOG.md](./CHANGELOG.md).
142
+ > Current source version: **v2.17.0**. See [CHANGELOG.md](./CHANGELOG.md).
143
143
 
144
144
  <!-- /public-truth -->
145
145
 
@@ -766,6 +766,33 @@ MCP-equivalent write tool:
766
766
 
767
767
  - `gno_clear_collection_embeddings`
768
768
 
769
+ ## Vector Maintenance, Coarse Routing, and Diagnostics
770
+
771
+ For large unfiltered or collection-scoped vector searches, GNO maintains a 1-bit
772
+ coarse `vec0` mirror (`vec_v2_*`) alongside float32 vectors and rescores
773
+ candidates with exact float32 cosine. Coarse routing is enabled by default for
774
+ partitions above the exact cost budget that pass the build-time recall@10
775
+ self-check (>= 95%); filtered searches and small scopes stay exact.
776
+
777
+ - **Inspect route on a query**: pass `--explain` (`gno query ... --explain`,
778
+ `gno vsearch ... --explain`, or `--json --explain`) to see `vectorRoute`
779
+ (`exact-sql`, `exact-vec0`, or `coarse-bit`, plus `N`, `coarseK`, and
780
+ `rescored`).
781
+ - **Inspect mirror and mmap health**: `gno doctor` reports `sqlite-mmap` and
782
+ `coarse-mirror` (mirror freshness, stored self-check recall@10, and routing
783
+ state); `gno status --json` exposes `vectorPartitions[].coarseMirror`.
784
+ - **Repair mirrors without re-embedding**: run `gno vec sync` (or
785
+ `gno vec rebuild` for a full rebuild) when `coarse-mirror` is `missing` or
786
+ `dirty`.
787
+ - **Disable coarse routing for an index**: set `coarseVectorSearch: false` in
788
+ the index config file (`gno doctor` prints its path) to keep every query on
789
+ exact float32 paths.
790
+ - **Reclaim superseded legacy vector tables**: run `gno vec prune` to drop
791
+ superseded `vec_<hash>` tables, legacy `content_vectors` rows (only for models
792
+ with an activated partition), and orphaned `vec_v1_*` / `vec_v2_*` mirrors.
793
+ Add `--vacuum` for in-place SQLite `VACUUM`, or run SQLite `VACUUM INTO` a new
794
+ file on large databases.
795
+
769
796
  ## Reference Documentation
770
797
 
771
798
  | Topic | File |
@@ -117,9 +117,11 @@ gno collection clear-embeddings <name> [--all] [--json]
117
117
  ### gno embed
118
118
 
119
119
  ```bash
120
- gno embed [collection] [--collection <name>] [--force] [--model <uri>] [--batch-size <n>] [--dry-run] [--new-partition]
120
+ gno embed [collection] [--collection <name>] [--force] [--model <uri>] [--batch-size <n>] [--max-chunks <n>] [--max-seconds <n>] [--dry-run] [--new-partition]
121
121
  ```
122
122
 
123
+ Default foreground `--batch-size` is `64` (background embedding is capped at `32`). Use `--max-chunks` or `--max-seconds` to process a large backlog in bounded slices.
124
+
123
125
  Switching `GNO_LLAMA_GPU`, Bun version or thread count resumes the existing
124
126
  vector partition when a measured sample of stored chunks matches. If it does
125
127
  not, embed refuses to build a separate partition without `--new-partition`
@@ -169,7 +171,7 @@ them in a collection instead.
169
171
  Generate embeddings only.
170
172
 
171
173
  ```bash
172
- gno embed [--force] [--model <uri>] [--batch-size <n>] [--dry-run] [--new-partition]
174
+ gno embed [--force] [--model <uri>] [--batch-size <n>] [--max-chunks <n>] [--max-seconds <n>] [--dry-run] [--new-partition]
173
175
  ```
174
176
 
175
177
  ## Project Profiles
@@ -445,13 +447,13 @@ gno query <query> [options]
445
447
 
446
448
  Additional options:
447
449
 
448
- | Option | Description |
449
- | ------------- | ------------------------------------------ |
450
- | `--no-expand` | Disable query expansion |
451
- | `--no-rerank` | Disable reranking |
452
- | `--graph` | Explicitly enable default graph candidates |
453
- | `--no-graph` | Disable graph-neighbor candidates |
454
- | `--explain` | Print retrieval details to stderr |
450
+ | Option | Description |
451
+ | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
452
+ | `--no-expand` | Disable query expansion |
453
+ | `--no-rerank` | Disable reranking |
454
+ | `--graph` | Explicitly enable default graph candidates |
455
+ | `--no-graph` | Disable graph-neighbor candidates |
456
+ | `--explain` | Print retrieval details to stderr (timings, score breakdown, and vector route: `exact-sql`, `exact-vec0`, or `coarse-bit` with `N`, `coarseK`, `rescored`) |
455
457
 
456
458
  ### gno ask
457
459
 
@@ -902,12 +904,16 @@ gno peek [--json]
902
904
  gno status [--json|--md]
903
905
  ```
904
906
 
907
+ Reports index counts, active vector partitions, and each partition's `coarseMirror` state (`clean`, `dirty`, `missing`, `unsupported`) and build-time recall self-check result.
908
+
905
909
  ### gno doctor
906
910
 
907
911
  ```bash
908
912
  gno doctor [--json|--md]
909
913
  ```
910
914
 
915
+ Checks config, database, `sqlite-vec`, effective SQLite `mmap_size` (`sqlite-mmap`), embedding fingerprints, vector partitions, and `coarse-mirror` freshness/recall (`gno vec sync` repairs dirty or missing mirrors).
916
+
911
917
  ### gno cleanup
912
918
 
913
919
  ```bash
@@ -916,17 +922,20 @@ gno cleanup
916
922
 
917
923
  ### gno vec
918
924
 
919
- Vector index maintenance. Use when `gno similar` returns empty despite embeddings.
925
+ Vector index maintenance. Use when `gno similar` returns empty despite embeddings, when `gno doctor` flags a dirty/missing `coarse-mirror`, or to reclaim superseded legacy vector tables.
920
926
 
921
927
  ```bash
922
- gno vec sync # Fast incremental sync
923
- gno vec rebuild # Full rebuild
928
+ gno vec sync # Incremental sync of float32 (v1) and bit coarse (v2) mirrors + recall self-check
929
+ gno vec rebuild # Full rebuild of v1 and v2 mirrors from stored vectors (no re-embedding)
924
930
  gno vec drop <partition> # Drop an abandoned shadow partition (id prefix from gno status)
931
+ gno vec prune # Drop superseded legacy vec_<hash> tables, content_vectors rows, and orphan mirrors
932
+ gno vec prune --vacuum # Prune and run in-place SQLite VACUUM to shrink the DB file
925
933
  ```
926
934
 
927
- | Option | Description |
928
- | -------- | ----------- |
929
- | `--json` | JSON output |
935
+ | Option | Description |
936
+ | ---------- | --------------------------------------------------------- |
937
+ | `--vacuum` | (`prune` only) Run SQLite `VACUUM` in-place after pruning |
938
+ | `--json` | JSON output |
930
939
 
931
940
  ## MCP Server
932
941
 
Binary file
@@ -0,0 +1 @@
1
+ eace4a15079892d886c7f18875c96257652aec6a59c022baf3d886bee8cb4d4a gno-browser-clipper-v2.17.0.zip
@@ -21,5 +21,5 @@
21
21
  "content_security_policy": {
22
22
  "extension_pages": "script-src 'self'; object-src 'none'; connect-src http://127.0.0.1:*"
23
23
  },
24
- "version": "2.15.0"
24
+ "version": "2.17.0"
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmickel/gno",
3
- "version": "2.15.0",
3
+ "version": "2.17.0",
4
4
  "description": "Local semantic search for your documents. Index Markdown, PDF, and Office files with hybrid BM25 + vector search.",
5
5
  "keywords": [
6
6
  "embeddings",
package/spec/cli.md CHANGED
@@ -243,7 +243,10 @@ the model with `id`, `model`, `dimensions`, `state` (`active`|`shadow`),
243
243
  `legacy` (pre-runtime-independent key), `retrieval` (this runtime reads it),
244
244
  `droppable` (`gno vec drop` accepts it), `owners` (current chunks),
245
245
  `provenance` (building runtime, e.g. `CUDA, Bun 1.4.2`),
246
- `compatibleRuntimes` (runtimes that read it) and `incompatibleRuntimes`.
246
+ `compatibleRuntimes` (runtimes that read it), `incompatibleRuntimes`, and
247
+ optional `coarseMirror` (`state`: `clean`|`dirty`|`missing`|`unsupported`,
248
+ `checkRecall`, `checkQueries`, `checkCoarseK`, `belowFloor`) describing the
249
+ partition's v2 binary coarse `vec0` mirror and build-time recall self-check.
247
250
  Terminal output prints a `Vector partitions:` block
248
251
  unless there is exactly one healthy partition. `collections`, `totalDocuments`
249
252
  and `totalChunks` cover configured collections only. Opening an index never
@@ -1303,7 +1306,7 @@ gno update [--git-pull] [--json] [--lock-wait <duration>] [--no-wait]
1303
1306
  | `--lock-wait <duration>` | duration | How long to wait for the index write lease (default: `120s`). Accepts `120`, `120s`, or `2m`. |
1304
1307
  | `--no-wait` | boolean | Do not wait; fail immediately if another writer holds the lease |
1305
1308
 
1306
- **Concurrency:** One writer at a time on the shared index database. `update` waits up to `--lock-wait` for the lease (the same `.mcp-write.lock` MCP write tools use); `index`, `embed`, `cleanup`, `vec sync`, `vec rebuild`, `vec drop`, `collection clear-embeddings`, `tags add`, and `tags rm` follow the same contract; `capture` takes the same lock internally, and single-row writes such as `collection policy set` are absorbed by `busy_timeout`. `--no-wait` opts out. Reads (`search`, `query`, `get`) never take the lease. External serialising wrappers are no longer required for CLI-vs-CLI and CLI-vs-MCP overlap. A resident (`gno serve`/`gno daemon`) takes the same lease without waiting around each watcher sync, embed preparation, background-embedding page write (never around inference), and the final vector activation; when the lease is held it defers that work (watcher retry after 5s, embed pass rescheduled) instead of writing, so resident background writes never hold a SQLite write lock outside the lease. The resident's own SQLite busy wait is capped at 500ms so a stop signal is always handled within the stop grace.
1309
+ **Concurrency:** One writer at a time on the shared index database. `update` waits up to `--lock-wait` for the lease (the same `.mcp-write.lock` MCP write tools use); `index`, `embed`, `cleanup`, `vec sync`, `vec rebuild`, `vec drop`, `vec prune`, `collection clear-embeddings`, `tags add`, and `tags rm` follow the same contract; `capture` takes the same lock internally, and single-row writes such as `collection policy set` are absorbed by `busy_timeout`. `--no-wait` opts out. Reads (`search`, `query`, `get`) never take the lease. External serialising wrappers are no longer required for CLI-vs-CLI and CLI-vs-MCP overlap. A resident (`gno serve`/`gno daemon`) takes the same lease without waiting around each watcher sync, embed preparation, background-embedding page write (never around inference), and the final vector activation; when the lease is held it defers that work (watcher retry after 5s, embed pass rescheduled) instead of writing, so resident background writes never hold a SQLite write lock outside the lease. The resident's own SQLite busy wait is capped at 500ms so a stop signal is always handled within the stop grace.
1307
1310
 
1308
1311
  **Behavior:**
1309
1312
 
@@ -1454,7 +1457,7 @@ never confirms; without confirmation embed exits 2 and writes nothing.
1454
1457
  | ------------------------ | -------- | ------- | ---------------------------------------------------------------------------- |
1455
1458
  | `--force` | boolean | false | Re-embed all chunks (ignore existing vectors) |
1456
1459
  | `--model` | string | config | Override embedding model URI |
1457
- | `--batch-size` | integer | 32 | Chunks per batch |
1460
+ | `--batch-size` | integer | 64 | Chunks per batch (foreground default; background capped at 32) |
1458
1461
  | `--dry-run` | boolean | false | Show what would be embedded without doing it |
1459
1462
  | `--max-chunks <n>` | integer | - | Stop after the batch that reaches this many chunks (see Bounded runs above) |
1460
1463
  | `--max-seconds <n>` | integer | - | Stop after the batch that reaches this many seconds (see Bounded runs above) |
@@ -1828,6 +1831,7 @@ active with `sourceCount: 1`.
1828
1831
  ```
1829
1832
  [explain] expansion: enabled (3 lexical, 2 semantic variants)
1830
1833
  [explain] bm25: 45 candidates
1834
+ [explain] vector: 20 candidates (route=exact-sql, N=45000)
1831
1835
  [explain] vector: 38 candidates
1832
1836
  [explain] graph: seeds=5, candidates=4/20, explicit=3, inferred=1, ambiguous=0, similarity=0
1833
1837
  [explain] fusion: RRF k=60, 52 unique documents (best rank per list)
@@ -3167,6 +3171,42 @@ included, is refused. JSON output is
3167
3171
 
3168
3172
  ---
3169
3173
 
3174
+ ### gno vec prune
3175
+
3176
+ Drop superseded legacy `vec_<hash>` tables and delete legacy `content_vectors`
3177
+ rows for models that already have an activated v1 vector partition, plus any
3178
+ orphaned `vec_v1_<partition>` and `vec_v2_<partition>` tables (and orphaned
3179
+ `vector_partition_rows` / `vector_mirror_v2_state` rows) absent from
3180
+ `vector_partitions`. Models whose v1 partition is still `shadow` or absent keep
3181
+ their legacy tables and rows.
3182
+
3183
+ **Synopsis:**
3184
+
3185
+ ```bash
3186
+ gno vec prune [--vacuum] [--json] [--lock-wait <duration>] [--no-wait]
3187
+ ```
3188
+
3189
+ **Options:**
3190
+ | Option | Type | Description |
3191
+ |--------|------|-------------|
3192
+ | `--vacuum` | boolean | Run SQLite `VACUUM` in-place after pruning to reclaim disk space |
3193
+ | `--json` | boolean | JSON output (`{"droppedTables": string[], "removedRows": number, "vacuumed": boolean}`) |
3194
+ | `--lock-wait <duration>` | duration | How long to wait for the index write lease |
3195
+ | `--no-wait` | boolean | Fail immediately if another writer holds the lease |
3196
+
3197
+ **Notes:**
3198
+
3199
+ - Requires `sqlite-vec` (fails closed when the extension is unavailable or the database is read-only).
3200
+ - Without `--vacuum`, pruning frees internal SQLite pages without shrinking the file on disk. For large indexes, prefer `VACUUM INTO` a new file to reclaim disk space and defragment pages while keeping the original file as a rollback copy.
3201
+
3202
+ **Exit Codes:**
3203
+
3204
+ - 0: Success (including zero-op on a clean database)
3205
+ - 2: Runtime error (database open failed, read-only database, or `sqlite-vec` unavailable)
3206
+ - 4: Write lease busy with `--no-wait`
3207
+
3208
+ ---
3209
+
3170
3210
  ### gno cleanup
3171
3211
 
3172
3212
  Delete the documents of indexed collections the config does not list, then
@@ -308,7 +308,8 @@ CREATE INDEX IF NOT EXISTS idx_vector_owners_variant ON vector_owners(variant_id
308
308
  -- scan the variants index.
309
309
  CREATE TABLE IF NOT EXISTS vector_mirror_state (
310
310
  partition_id TEXT PRIMARY KEY,
311
- dirty INTEGER NOT NULL CHECK (dirty IN (0, 1))
311
+ dirty INTEGER NOT NULL CHECK (dirty IN (0, 1)),
312
+ null_cosine INTEGER CHECK (null_cosine IS NULL OR null_cosine IN (0, 1))
312
313
  );
313
314
  CREATE TRIGGER IF NOT EXISTS vector_variants_mirror_before_insert
314
315
  BEFORE INSERT ON vector_variants BEGIN
@@ -1005,3 +1006,54 @@ CREATE TRIGGER graph_inventory_graph_reference_documents_delete AFTER DELETE ON
1005
1006
  CREATE TRIGGER graph_inventory_graph_frontmatter_references_insert AFTER INSERT ON graph_frontmatter_references BEGIN UPDATE graph_projection_state SET dirty = 1, in_progress = 1 WHERE id = 1; END;
1006
1007
  CREATE TRIGGER graph_inventory_graph_frontmatter_references_update AFTER UPDATE ON graph_frontmatter_references BEGIN UPDATE graph_projection_state SET dirty = 1, in_progress = 1 WHERE id = 1; END;
1007
1008
  CREATE TRIGGER graph_inventory_graph_frontmatter_references_delete AFTER DELETE ON graph_frontmatter_references BEGIN UPDATE graph_projection_state SET dirty = 1, in_progress = 1 WHERE id = 1; END;
1009
+
1010
+ -- ─────────────────────────────────────────────────────────────────────────────
1011
+ -- Vector v2 bit coarse mirror metadata (migration 039, fn-235)
1012
+ -- ─────────────────────────────────────────────────────────────────────────────
1013
+
1014
+ CREATE TABLE IF NOT EXISTS vector_partition_rows (
1015
+ id INTEGER PRIMARY KEY,
1016
+ partition_id TEXT NOT NULL,
1017
+ collection TEXT NOT NULL,
1018
+ variant_id INTEGER NOT NULL,
1019
+ UNIQUE(partition_id, collection, variant_id)
1020
+ );
1021
+
1022
+ CREATE INDEX IF NOT EXISTS idx_vector_partition_rows_part_var
1023
+ ON vector_partition_rows(partition_id, variant_id);
1024
+
1025
+ CREATE TABLE IF NOT EXISTS vector_mirror_v2_state (
1026
+ partition_id TEXT PRIMARY KEY,
1027
+ dirty INTEGER NOT NULL CHECK (dirty IN (0, 1)),
1028
+ check_recall REAL,
1029
+ check_queries INTEGER,
1030
+ check_coarse_k INTEGER
1031
+ );
1032
+
1033
+ CREATE TRIGGER IF NOT EXISTS trg_vector_variants_v2_insert
1034
+ AFTER INSERT ON vector_variants
1035
+ BEGIN
1036
+ DELETE FROM vector_mirror_v2_state WHERE partition_id = NEW.partition_id;
1037
+ END;
1038
+ CREATE TRIGGER IF NOT EXISTS trg_vector_variants_v2_update
1039
+ AFTER UPDATE ON vector_variants
1040
+ BEGIN
1041
+ DELETE FROM vector_mirror_v2_state WHERE partition_id = OLD.partition_id;
1042
+ DELETE FROM vector_mirror_v2_state WHERE partition_id = NEW.partition_id;
1043
+ END;
1044
+ CREATE TRIGGER IF NOT EXISTS trg_vector_variants_v2_delete
1045
+ AFTER DELETE ON vector_variants
1046
+ BEGIN
1047
+ DELETE FROM vector_mirror_v2_state WHERE partition_id = OLD.partition_id;
1048
+ END;
1049
+ CREATE TRIGGER IF NOT EXISTS trg_vector_owners_v2_insert
1050
+ AFTER INSERT ON vector_owners
1051
+ BEGIN
1052
+ DELETE FROM vector_mirror_v2_state WHERE partition_id = NEW.partition_id;
1053
+ END;
1054
+ CREATE TRIGGER IF NOT EXISTS trg_vector_owners_v2_update
1055
+ AFTER UPDATE ON vector_owners
1056
+ BEGIN
1057
+ DELETE FROM vector_mirror_v2_state WHERE partition_id = OLD.partition_id;
1058
+ DELETE FROM vector_mirror_v2_state WHERE partition_id = NEW.partition_id;
1059
+ END;
package/spec/mcp.md CHANGED
@@ -1478,8 +1478,11 @@ read under the same selection rule as retrieval (`vectorRuntime` reports
1478
1478
  `vectors`, `unavailable` with a reason, or `unresolved` before its first query
1479
1479
  or embed). `droppable` marks what `gno vec drop` accepts. Other partitions carry `state`, `owners` and a
1480
1480
  readable `provenance`; `compatibleRuntimes` names the runtimes that read a
1481
- partition and `incompatibleRuntimes` names runtimes measured unable to
1482
- reproduce the stored vectors, whose queries use lexical retrieval only.
1481
+ partition, `incompatibleRuntimes` names runtimes measured unable to
1482
+ reproduce the stored vectors (whose queries use lexical retrieval only), and
1483
+ optional `coarseMirror` reports the partition's v2 bit coarse mirror freshness
1484
+ and build-time recall self-check (`state`, `checkRecall`, `checkQueries`,
1485
+ `checkCoarseK`, `belowFloor`).
1483
1486
 
1484
1487
  `contentTypeBoost` is a redacted ranking-status projection. It exposes only
1485
1488
  normalized IDs/factors plus the rules fingerprint; path prefixes are never
@@ -2229,7 +2232,10 @@ Get documents linking TO a document.
2229
2232
 
2230
2233
  ### gno_similar
2231
2234
 
2232
- Find semantically similar documents using vector embeddings.
2235
+ Find semantically similar documents using vector embeddings. When
2236
+ `crossCollection` is false (the default), the underlying vector search is scoped
2237
+ directly to the source document's collection so documents in other collections
2238
+ cannot crowd out same-collection candidates.
2233
2239
 
2234
2240
  **Input Schema:**
2235
2241
 
@@ -330,6 +330,33 @@
330
330
  "items": {
331
331
  "type": "string"
332
332
  }
333
+ },
334
+ "coarseMirror": {
335
+ "type": "object",
336
+ "additionalProperties": false,
337
+ "required": [
338
+ "state",
339
+ "checkRecall",
340
+ "checkQueries",
341
+ "checkCoarseK",
342
+ "belowFloor"
343
+ ],
344
+ "properties": {
345
+ "state": {
346
+ "type": "string",
347
+ "enum": ["clean", "dirty", "missing", "unsupported"]
348
+ },
349
+ "checkRecall": { "type": ["number", "null"] },
350
+ "checkQueries": {
351
+ "type": ["integer", "null"],
352
+ "minimum": 0
353
+ },
354
+ "checkCoarseK": {
355
+ "type": ["integer", "null"],
356
+ "minimum": 1
357
+ },
358
+ "belowFloor": { "type": "boolean" }
359
+ }
333
360
  }
334
361
  }
335
362
  }
@@ -92,6 +92,20 @@
92
92
  "type": "array",
93
93
  "maxItems": 100,
94
94
  "items": { "type": "string", "minLength": 1, "maxLength": 128 }
95
+ },
96
+ "vectorRoute": {
97
+ "type": "object",
98
+ "additionalProperties": false,
99
+ "required": ["route", "mirrorRows"],
100
+ "properties": {
101
+ "route": {
102
+ "type": "string",
103
+ "enum": ["exact-sql", "exact-vec0", "coarse-bit"]
104
+ },
105
+ "mirrorRows": { "type": "integer", "minimum": 0 },
106
+ "coarseK": { "type": "integer", "minimum": 1 },
107
+ "rescored": { "type": "integer", "minimum": 0 }
108
+ }
95
109
  }
96
110
  }
97
111
  },
@@ -592,6 +592,20 @@
592
592
  "results": {
593
593
  "type": "array",
594
594
  "items": { "$ref": "#/$defs/explainResult" }
595
+ },
596
+ "vectorRoute": {
597
+ "type": "object",
598
+ "additionalProperties": false,
599
+ "required": ["route", "mirrorRows"],
600
+ "properties": {
601
+ "route": {
602
+ "type": "string",
603
+ "enum": ["exact-sql", "exact-vec0", "coarse-bit"]
604
+ },
605
+ "mirrorRows": { "type": "integer", "minimum": 0 },
606
+ "coarseK": { "type": "integer", "minimum": 1 },
607
+ "rescored": { "type": "integer", "minimum": 0 }
608
+ }
595
609
  }
596
610
  },
597
611
  "additionalProperties": false
@@ -245,6 +245,28 @@
245
245
  "type": "string"
246
246
  },
247
247
  "description": "Runtimes measured incompatible; they read another partition or use lexical retrieval only"
248
+ },
249
+ "coarseMirror": {
250
+ "type": "object",
251
+ "additionalProperties": false,
252
+ "required": [
253
+ "state",
254
+ "checkRecall",
255
+ "checkQueries",
256
+ "checkCoarseK",
257
+ "belowFloor"
258
+ ],
259
+ "description": "Bit coarse vec0 mirror freshness and build-time recall self-check status",
260
+ "properties": {
261
+ "state": {
262
+ "type": "string",
263
+ "enum": ["clean", "dirty", "missing", "unsupported"]
264
+ },
265
+ "checkRecall": { "type": ["number", "null"] },
266
+ "checkQueries": { "type": ["integer", "null"], "minimum": 0 },
267
+ "checkCoarseK": { "type": ["integer", "null"], "minimum": 1 },
268
+ "belowFloor": { "type": "boolean" }
269
+ }
248
270
  }
249
271
  }
250
272
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { CliError } from "../../errors.js";
8
- import { getGlobals } from "../../program.js";
8
+ import { getGlobals } from "../../globals.js";
9
9
  import {
10
10
  BLOCK_VERSION,
11
11
  extractBlock,
@@ -37,7 +37,7 @@ import {
37
37
  createVectorIndexPort,
38
38
  type VectorIndexPort,
39
39
  } from "../../store/vector";
40
- import { getGlobals } from "../program";
40
+ import { getGlobals } from "../globals";
41
41
  import {
42
42
  createProgressRenderer,
43
43
  createThrottledProgressRenderer,
@@ -22,7 +22,7 @@ import { resolveDownloadPolicy } from "../../llm/policy";
22
22
  import { resolveModelUri } from "../../llm/registry";
23
23
  import { createVectorIndexPort } from "../../store/vector";
24
24
  import { CliError } from "../errors";
25
- import { getGlobals } from "../program";
25
+ import { getGlobals } from "../globals";
26
26
  import {
27
27
  createProgressRenderer,
28
28
  createThrottledProgressRenderer,
@@ -43,6 +43,7 @@ import {
43
43
  getExtensionLoadingMode,
44
44
  getLoadAttempts,
45
45
  } from "../../store/sqlite/setup";
46
+ import { COARSE_ROUTER_DEFAULTS } from "../../store/vector/coarse-router";
46
47
  import { getStoredEmbeddingFingerprint } from "../../store/vector/freshness";
47
48
  import { currentOwnerCount } from "../../store/vector/runtime-compat";
48
49
  import { storedVectorPartition } from "../../store/vector/status";
@@ -170,22 +171,30 @@ async function checkDatabase(indexName?: string): Promise<DoctorCheck> {
170
171
  }
171
172
 
172
173
  /**
173
- * Report the live SQLite busy_timeout (PRAGMA), not the config echo.
174
+ * Report live SQLite PRAGMAs (`busy_timeout` and `mmap_size`) read back from
175
+ * the open index connection, not config echoes or requested ceilings.
174
176
  */
175
- async function checkBusyTimeout(
177
+ async function checkSqlitePragmas(
176
178
  config: Config,
177
179
  indexName?: string
178
- ): Promise<DoctorCheck> {
180
+ ): Promise<DoctorCheck[]> {
179
181
  const dbPath = getIndexDbPath(indexName);
180
182
 
181
183
  try {
182
184
  await stat(dbPath);
183
185
  } catch {
184
- return {
185
- name: "busy-timeout",
186
- status: "warn",
187
- message: "Database not found. Run: gno init",
188
- };
186
+ return [
187
+ {
188
+ name: "busy-timeout",
189
+ status: "warn",
190
+ message: "Database not found. Run: gno init",
191
+ },
192
+ {
193
+ name: "sqlite-mmap",
194
+ status: "warn",
195
+ message: "Database not found. Run: gno init",
196
+ },
197
+ ];
189
198
  }
190
199
 
191
200
  const store = new SqliteAdapter();
@@ -198,30 +207,58 @@ async function checkBusyTimeout(
198
207
  config.busyTimeoutMs ?? DEFAULT_BUSY_TIMEOUT_MS
199
208
  );
200
209
  if (!openResult.ok) {
201
- return {
202
- name: "busy-timeout",
203
- status: "warn",
204
- message: `busy_timeout unavailable: ${openResult.error.message}`,
205
- };
210
+ return [
211
+ {
212
+ name: "busy-timeout",
213
+ status: "warn",
214
+ message: `busy_timeout unavailable: ${openResult.error.message}`,
215
+ },
216
+ {
217
+ name: "sqlite-mmap",
218
+ status: "warn",
219
+ message: `mmap_size unavailable: ${openResult.error.message}`,
220
+ },
221
+ ];
206
222
  }
207
223
 
208
224
  try {
209
- const timeout = store
210
- .getRawDb()
225
+ const db = store.getRawDb();
226
+ const timeout = db
211
227
  .query<{ timeout: number }, []>("PRAGMA busy_timeout")
212
228
  .get()?.timeout;
213
- if (timeout === undefined) {
214
- return {
215
- name: "busy-timeout",
216
- status: "warn",
217
- message: "PRAGMA busy_timeout returned no value",
218
- };
219
- }
220
- return {
221
- name: "busy-timeout",
222
- status: "ok",
223
- message: `busy_timeout ${timeout}ms`,
224
- };
229
+ const busyCheck: DoctorCheck =
230
+ timeout === undefined
231
+ ? {
232
+ name: "busy-timeout",
233
+ status: "warn",
234
+ message: "PRAGMA busy_timeout returned no value",
235
+ }
236
+ : {
237
+ name: "busy-timeout",
238
+ status: "ok",
239
+ message: `busy_timeout ${timeout}ms`,
240
+ };
241
+
242
+ const mmapSize = db
243
+ .query<{ mmap_size: number }, []>("PRAGMA mmap_size")
244
+ .get()?.mmap_size;
245
+ const mmapCheck: DoctorCheck =
246
+ mmapSize === undefined
247
+ ? {
248
+ name: "sqlite-mmap",
249
+ status: "warn",
250
+ message: "PRAGMA mmap_size returned no value",
251
+ }
252
+ : {
253
+ name: "sqlite-mmap",
254
+ status: "ok",
255
+ message:
256
+ mmapSize > 0
257
+ ? `mmap_size ${mmapSize} bytes (${Math.round(mmapSize / (1024 * 1024))} MiB)`
258
+ : "mmap_size 0 bytes (disabled)",
259
+ };
260
+
261
+ return [busyCheck, mmapCheck];
225
262
  } finally {
226
263
  await store.close();
227
264
  }
@@ -441,6 +478,40 @@ async function checkEmbeddingFingerprints(
441
478
  const runtime = statusResult.value.vectorRuntime;
442
479
  const partitionLines = formatVectorPartitionLines(partitions, runtime);
443
480
  const retrieval = partitions.find((p) => p.retrieval);
481
+ const activeTarget =
482
+ retrieval ?? partitions.find((p) => p.state === "active");
483
+ const coarse = activeTarget?.coarseMirror;
484
+ const coarseChecks: DoctorCheck[] = [];
485
+ if (activeTarget && coarse) {
486
+ const enabled =
487
+ config.coarseVectorSearch ?? COARSE_ROUTER_DEFAULTS.enabledByDefault;
488
+ let coarseStatus: DoctorCheckStatus = "ok";
489
+ let coarseMsg: string;
490
+ const coarseDetails: string[] = [];
491
+ if (coarse.state === "unsupported") {
492
+ coarseMsg = `unsupported (dimensions=${activeTarget.dimensions} not divisible by 8; stays exact)`;
493
+ } else if (coarse.state === "missing" || coarse.state === "dirty") {
494
+ coarseStatus = enabled ? "warn" : "info";
495
+ coarseMsg = `${coarse.state} (stays exact; run: gno vec sync)`;
496
+ coarseDetails.push("Run: gno vec sync");
497
+ } else if (coarse.belowFloor && coarse.checkRecall !== null) {
498
+ coarseStatus = enabled ? "warn" : "info";
499
+ coarseMsg = `clean, recall@10=${(coarse.checkRecall * 100).toFixed(1)}% below 95% floor (stays exact)`;
500
+ coarseDetails.push(
501
+ "Two-stage coarse routing stays disabled for this partition because self-check recall is below the 95% floor."
502
+ );
503
+ } else if (coarse.checkRecall !== null) {
504
+ coarseMsg = `clean, recall@10=${(coarse.checkRecall * 100).toFixed(1)}% (${coarse.checkQueries ?? 0}q, coarseK=${coarse.checkCoarseK ?? 200}); routing ${enabled ? "enabled" : "disabled in config"}`;
505
+ } else {
506
+ coarseMsg = `clean, self-check not run (partition within exact budget or unchecked; stays exact); routing ${enabled ? "enabled" : "disabled in config"}`;
507
+ }
508
+ coarseChecks.push({
509
+ name: "coarse-mirror",
510
+ status: coarseStatus,
511
+ message: coarseMsg,
512
+ ...(coarseDetails.length > 0 ? { details: coarseDetails } : {}),
513
+ });
514
+ }
444
515
  return [
445
516
  fingerprintCheck,
446
517
  {
@@ -455,6 +526,7 @@ async function checkEmbeddingFingerprints(
455
526
  vectorPartitions: partitions,
456
527
  vectorRuntime: runtime,
457
528
  },
529
+ ...coarseChecks,
458
530
  ];
459
531
  } finally {
460
532
  await store.close();
@@ -805,8 +877,8 @@ export async function doctor(
805
877
  const sqliteChecks = await checkSqliteExtensions();
806
878
  checks.push(...sqliteChecks);
807
879
 
808
- // Live busy_timeout from the open index (not the config echo)
809
- checks.push(await checkBusyTimeout(config, options.indexName));
880
+ // Live busy_timeout and mmap_size from the open index (not config echoes)
881
+ checks.push(...(await checkSqlitePragmas(config, options.indexName)));
810
882
 
811
883
  // Code chunking capability
812
884
  checks.push(checkCodeChunking());