fleet-kb-index: ingest, kb tools and the incremental refresh unit (nix-config#1876) #2847

Merged
hermes merged 1 commit from kb/NCFG-1876-fleet-kb-package into main 2026-11-21 10:43:14 -06:00
Collaborator

What

One package carrying the three verbs over the fleet_kb store (schema landed in #1875, host wiring is #1877):

  • packages/fleet-kb-index/ingest.py — walks the five enumerated corpora (skill, note, config, card, event), heading-aware chunks (~600 tokens, heading path carried in the text), embeds with the packaged bge-m3 ONNX in-process, upserts by content_hash. Every corpus is a named root or an enumerated API source; a source's rows that are no longer produced are deleted so the store cannot drift from the text it points at. --skills-repo supplies git provenance for the (untracked) skill library; a file that repo does not carry keeps commit NULL, which kb_stale reports rather than guesses.
  • packages/fleet-kb-index/kb_server.py — search / get / stats / stale: pgvector cosine + english tsvector fused by RRF, metadata narrowing by jsonb containment, provenance + staleness per row. Also fleet-kb mcp (stdio MCP server, same four verbs) so a session and an operator cannot get different answers.
  • packages/fleet-kb-index/default.nix — one derivation with both CLIs; FLEET_KB_MODEL_DIR baked so no caller has to know a store path.
  • packages/fleet-kb-index/reindex.nix — the incremental refresh unit + timer, with the first-run timeout sized for the one-off full embed and a freshness report in ExecStartPost that does not red the unit.

Proof (throwaway Postgres 15 + pgvector cluster, never the live store)

  • schema applied twice: 0 errors on the second pass (idempotent)
  • all five corpora produce rows against the real sources (skills tree, notes-repo, both config clones, the board API, the Forgejo API)
  • wg-MTU skill: run 1 embeds N chunks, run 2 embeds 0 (skipped == run1.embedded)
  • kb search "wireguard mtu" → that skill's anchor, both RRF arms matched, provenance/staleness rendered
  • a committed edit to an indexed config file makes kb stale name the row
  • module evaluated through nixos/lib/eval-config: ExecStart/ExecStartPost/timer/hardening as intended

Incremental is a property of the upsert, not a mode: an unchanged chunk keeps its row and its vector.

Not in scope

overlays/fleet-kb.nix + hosts/vpn/default.nix (pgvector extension, ensureDatabases, MCP entry, package installs) — that is nix-config#1877, which consumes packages/services.fleet-kb-index from here.

## What One package carrying the three verbs over the `fleet_kb` store (schema landed in #1875, host wiring is #1877): - `packages/fleet-kb-index/ingest.py` — walks the five enumerated corpora (skill, note, config, card, event), heading-aware chunks (~600 tokens, heading path carried in the text), embeds with the packaged bge-m3 ONNX in-process, upserts by `content_hash`. Every corpus is a named root or an enumerated API source; a source's rows that are no longer produced are deleted so the store cannot drift from the text it points at. `--skills-repo` supplies git provenance for the (untracked) skill library; a file that repo does not carry keeps `commit` NULL, which `kb_stale` reports rather than guesses. - `packages/fleet-kb-index/kb_server.py` — `search` / `get` / `stats` / `stale`: pgvector cosine + english tsvector fused by RRF, metadata narrowing by jsonb containment, provenance + staleness per row. Also `fleet-kb mcp` (stdio MCP server, same four verbs) so a session and an operator cannot get different answers. - `packages/fleet-kb-index/default.nix` — one derivation with both CLIs; `FLEET_KB_MODEL_DIR` baked so no caller has to know a store path. - `packages/fleet-kb-index/reindex.nix` — the incremental refresh unit + timer, with the first-run timeout sized for the one-off full embed and a freshness report in `ExecStartPost` that does not red the unit. ## Proof (throwaway Postgres 15 + pgvector cluster, never the live store) - schema applied twice: 0 errors on the second pass (idempotent) - all five corpora produce rows against the real sources (skills tree, notes-repo, both config clones, the board API, the Forgejo API) - wg-MTU skill: run 1 embeds N chunks, **run 2 embeds 0** (`skipped == run1.embedded`) - `kb search "wireguard mtu"` → that skill's anchor, both RRF arms matched, provenance/staleness rendered - a committed edit to an indexed config file makes `kb stale` name the row - module evaluated through `nixos/lib/eval-config`: ExecStart/ExecStartPost/timer/hardening as intended Incremental is a property of the upsert, not a mode: an unchanged chunk keeps its row **and its vector**. ## Not in scope `overlays/fleet-kb.nix` + `hosts/vpn/default.nix` (pgvector extension, `ensureDatabases`, MCP entry, package installs) — that is nix-config#1877, which consumes `packages`/`services.fleet-kb-index` from here.
fleet-kb-index: ingest, kb tools and the incremental refresh unit
All checks were successful
PR base guard / Base drift / conflict check (pull_request) Successful in 9s
Policy Gates / Worker-scope reaper worker signature (mutation-tested) (pull_request) Successful in 7s
NixOS Build Check / Scope changed deployable hosts (pull_request) Successful in 14s
Policy Gates / Kanban pool capacity knob (runtime override + clamp, mutation-tested) (pull_request) Successful in 4s
NixOS Build Check / Flake input regression guard (pull_request) Successful in 10s
Policy Gates / Sentinel pass budget contract (prompt forbids the full board walk, mutation-tested) (pull_request) Successful in 7s
Policy Gates / CI-scratch reaper class table (mutation-tested) (pull_request) Successful in 4s
Policy Gates / Fleet cache sweep class table (mutation-tested) (pull_request) Successful in 4s
Secret Scan / gitleaks scan (pull_request) Successful in 55s
NixOS Build Check / Hermes runtime gates (one eval of vpn's runtime) (pull_request) Successful in 1m28s
Policy Gates / foremerge accept-order contract (real binary) (pull_request) Successful in 1m12s
Policy Gates / Scheduled foremerge reap command line (mutation-tested) (pull_request) Successful in 4s
Policy Gates / .forgejo/tests python suites (hermetic) (pull_request) Successful in 55s
Policy Gates / Fleet control ledger (sealed profile fails the build, mutation-tested) (pull_request) Successful in 19s
NixOS Build Check / Build changed host closures (per-host budget) (pull_request) Successful in 3m59s
NixOS Build Check / Gate summary (pull_request) Successful in 1s
foremerge intent (advisory) all 4 changed path(s) covered by a live foremerge intent
Repo Gates / Repo gates (script-only battery) (pull_request) Successful in 3m58s
ba21f461aa
One package carrying the three verbs over the fleet_kb store
(packages/fleet-kb-schema.sql):

  fleet-kb-ingest  walks the five enumerated corpora (skill, note, config,
                   card, event), chunks heading-aware (~600 tokens with the
                   heading path in the text), embeds with the packaged bge-m3
                   ONNX model in-process and upserts by content_hash. Nothing
                   is a catch-all walk: every corpus is a named root or an
                   enumerated API source, and a source's rows that are no
                   longer produced are deleted, so the store cannot drift from
                   the text it points at.

  fleet-kb         search / get / stats / stale over pgvector cosine and an
                   english tsvector fused by RRF, metadata narrowing by jsonb
                   containment, provenance and a staleness verdict per row,
                   plus `fleet-kb mcp` — the same four verbs as a stdio MCP
                   server, so a session and an operator cannot get different
                   answers.

  reindex.nix      the incremental refresh unit and timer. Incremental is a
                   property of the upsert, not a mode: an unchanged chunk keeps
                   its row and its vector, so a second run embeds zero chunks
                   and an edited file re-embeds only its changed chunks.

The skill library at /var/lib/hermes/.hermes/skills is not a git tree, so
--skills-repo names the repo carrying the canonical copies and a file it does
not carry keeps commit NULL — the schema's own rule for a source with no git
history, which kb_stale reports rather than guesses.

Verified in a throwaway Postgres 15 + pgvector cluster (never the live store):
schema applied twice with no errors; all five corpora produce rows against the
real sources; the wg-MTU skill's chunks embed on run 1 and run 2 embeds zero;
`fleet-kb search "wireguard mtu"` returns that skill's anchor with both arms
matched; a committed edit to an indexed config file makes kb_stale name the row.
hermes force-pushed kb/NCFG-1876-fleet-kb-package from ba21f461aa
All checks were successful
PR base guard / Base drift / conflict check (pull_request) Successful in 9s
Policy Gates / Worker-scope reaper worker signature (mutation-tested) (pull_request) Successful in 7s
NixOS Build Check / Scope changed deployable hosts (pull_request) Successful in 14s
Policy Gates / Kanban pool capacity knob (runtime override + clamp, mutation-tested) (pull_request) Successful in 4s
NixOS Build Check / Flake input regression guard (pull_request) Successful in 10s
Policy Gates / Sentinel pass budget contract (prompt forbids the full board walk, mutation-tested) (pull_request) Successful in 7s
Policy Gates / CI-scratch reaper class table (mutation-tested) (pull_request) Successful in 4s
Policy Gates / Fleet cache sweep class table (mutation-tested) (pull_request) Successful in 4s
Secret Scan / gitleaks scan (pull_request) Successful in 55s
NixOS Build Check / Hermes runtime gates (one eval of vpn's runtime) (pull_request) Successful in 1m28s
Policy Gates / foremerge accept-order contract (real binary) (pull_request) Successful in 1m12s
Policy Gates / Scheduled foremerge reap command line (mutation-tested) (pull_request) Successful in 4s
Policy Gates / .forgejo/tests python suites (hermetic) (pull_request) Successful in 55s
Policy Gates / Fleet control ledger (sealed profile fails the build, mutation-tested) (pull_request) Successful in 19s
NixOS Build Check / Build changed host closures (per-host budget) (pull_request) Successful in 3m59s
NixOS Build Check / Gate summary (pull_request) Successful in 1s
foremerge intent (advisory) all 4 changed path(s) covered by a live foremerge intent
Repo Gates / Repo gates (script-only battery) (pull_request) Successful in 3m58s
to bbe54ab349
All checks were successful
PR base guard / Base drift / conflict check (pull_request) Successful in 6s
Secret Scan / gitleaks scan (pull_request) Successful in 10s
NixOS Build Check / Scope changed deployable hosts (pull_request) Successful in 26s
NixOS Build Check / Flake input regression guard (pull_request) Successful in 10s
Giga Build Check / Build giga target closure (pull_request) Successful in 55s
Policy Gates / Worker-scope reaper worker signature (mutation-tested) (pull_request) Successful in 4s
Policy Gates / Kanban pool capacity knob (runtime override + clamp, mutation-tested) (pull_request) Successful in 4s
Policy Gates / Sentinel pass budget contract (prompt forbids the full board walk, mutation-tested) (pull_request) Successful in 3s
Policy Gates / CI-scratch reaper class table (mutation-tested) (pull_request) Successful in 4s
Policy Gates / Fleet cache sweep class table (mutation-tested) (pull_request) Successful in 4s
NixOS Build Check / Hermes runtime gates (one eval of vpn's runtime) (pull_request) Successful in 1m9s
Policy Gates / foremerge accept-order contract (real binary) (pull_request) Successful in 1m13s
Policy Gates / Scheduled foremerge reap command line (mutation-tested) (pull_request) Successful in 3s
NixOS Build Check / Build changed host closures (per-host budget) (pull_request) Successful in 2m34s
NixOS Build Check / Gate summary (pull_request) Successful in 0s
Policy Gates / .forgejo/tests python suites (hermetic) (pull_request) Successful in 55s
Policy Gates / Fleet control ledger (sealed profile fails the build, mutation-tested) (pull_request) Successful in 20s
foremerge intent (advisory) all 4 changed path(s) covered by a live foremerge intent
Repo Gates / Repo gates (script-only battery) (pull_request) Successful in 3m51s
2026-11-21 10:32:47 -06:00
Compare
hermes merged commit 788e996573 into main 2026-11-21 10:43:14 -06:00
hermes deleted branch kb/NCFG-1876-fleet-kb-package 2026-11-21 10:43:15 -06:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ymrtech/nix-config!2847
No description provided.