Local embeddings on by default, ranking people_find #7

Closed
opened 2026-11-01 01:59:24 +00:00 by svc-agent-writer · 3 comments

Parent: #1. Records: ADR 0006.

What to build

  • The same pinned model as mailmind (bge-small-en-v1.5, int8 ONNX), fetched by a hash-checked script at image build and by make model. One core, a thread in the sync process.
  • One vector per Person, built from name, Organisation, title and Tags, stored as a BLOB and scored in numpy.
  • people_find free-text queries rank by vector score blended with exact and prefix matches. Exact Handle matches always rank first.
  • [embed] enabled = false turns it off; the tool then ranks by lexical match alone and people_status says so.

Acceptance criteria

  • With the model present, a free-text query for a role or Organisation returns the expected Person first in a fixture of 50.
  • With enabled = false, no model loads, the vector table stays empty, and people_find still answers.
  • Model tests skip until make model has run, as mailmind's do.
  • A Forget deletes the Person's vector.

Blocked by

Filed under: operator word "go. compelling public-facing README.md as A0" sha256:3f9e946994fa

Parent: #1. Records: ADR 0006. ## What to build - The same pinned model as mailmind (`bge-small-en-v1.5`, int8 ONNX), fetched by a hash-checked script at image build and by `make model`. One core, a thread in the sync process. - One vector per Person, built from name, Organisation, title and Tags, stored as a BLOB and scored in numpy. - `people_find` free-text queries rank by vector score blended with exact and prefix matches. Exact Handle matches always rank first. - `[embed] enabled = false` turns it off; the tool then ranks by lexical match alone and `people_status` says so. ## Acceptance criteria - With the model present, a free-text query for a role or Organisation returns the expected Person first in a fixture of 50. - With `enabled = false`, no model loads, the vector table stays empty, and `people_find` still answers. - Model tests skip until `make model` has run, as mailmind's do. - A Forget deletes the Person's vector. ## Blocked by - #4 Filed under: operator word "go. compelling public-facing README.md as A0" sha256:3f9e946994fa
Collaborator

⏸ SVD architect gate: dev/peoplemind-mcp#7 local-embeddings-on-by-default-ranking-people-find

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity substrate · dispatch effort high

Run: 20261101T112846Z-5865f73a

Held because: CLEAN but 8 open risk(s) (2 verification · 6 decision) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. The pattern to mirror, and the pinned model values, were unreadable: /Users/piers/src/imap-mailmind-mcp returned 'Operation not permitted' and network git ls-remote was denied. The HF revision, file names, sha256 values, pooling, query prefix and dependency pins must come from mailmind at dispatch. Question: can the dispatch runtime read imap-mailmind-mcp? If not, will the architect paste mailmind ADR 0005's revision and hashes into the spec before approval? Dispatch must halt rather than invent hashes. [decision]
  2. ADR 0006 §2 lists vector inputs the issue omits: relation labels, signature lines and the last ten mail_evidence subjects. Signature lines and subjects are not persisted at base (the mailmind Source parses subjects at sources/mailmind.py:96-103 but does not store them). The spec follows the issue: name, aliases, Organisation, title, Tags. Question: add relation labels now (already stored in relations.label), and file a follow-up for storing signatures and subjects? [decision]
  3. Wording diverges from the ADRs. ADR 0006 §4 says semantic-with-embed-off answers 'Error: embed is off'; this codebase renders tool errors as 'Error: code=' (rows.py:15-16), so the lean returns 'Error: code=embed-off', also for explicit hybrid. ADR 0001 Amendment 1 shows 'on covered=N' only while the first backfill runs; the lean always shows covered=N when on. Question: accept both and record them as an ADR 0006 amendment? [decision]
  4. The issue says the fetch script runs at image build, but no Dockerfile, Containerfile or compose file exists at 8c01615, and README.md:74 says the deploy slice has not shipped. This spec ships only scripts/fetch-model.sh and make model. Question: which issue owns the image build, so it can call scripts/fetch-model.sh? No ref could be named from the issue snapshot. [decision]
  5. Query embedding needs the model in the API process as well as the sync thread the issue names: about 157 MB RSS (ADR 0006 Context). The lean loads it lazily on the first people_find, only when enabled. Question: accept the API-side load, or design a sync-side query service instead? [decision]
  6. README is not updated: the 16-file ceiling is spent on code and tests, and tests/test_identity.py:445 forced a third version-literal edit. The people_status row (README.md:41) and the [embed]/make model docs remain stale. Question: a docs-only follow-up PR, or re-slice? [decision]
  7. The 'expected Person first in a fixture of 50' criterion and the min_score=0.55 default are only proven where the model exists; model tests skip elsewhere. Check on the host before merge: make model && uv run python3 -m pytest tests/test_embed.py -m model -q -rs reports both model tests as passed, not skipped. [verification]
  8. No numeric test baseline: the Half-A sandbox denied .venv/bin/python. Check: on the pristine base, uv run python3 -m pytest -q records the failure set before the first edit; after the change the same command shows the identical failure set plus the new tests/test_embed.py passes, and uv run mypy is clean. [verification]

Change: Mailmind is the pattern source, and the sandbox denied it. Dispatch must read mailmind's fetch script, embedder and ADR 0005 first and copy the revision, hashes, file names, pooling and dependency pins verbatim. If it cannot, it halts.

  1. Schema: append migration 5 in the shape of store.py:85-90. It adds person_vectors(person_id PK REFERENCES persons(id) ON DELETE CASCADE, model, text_hash, vector BLOB, updated_at) and bumps SCHEMA_VERSION to 5. The cascade makes Forget (graph.py:381) and merge-loser deletion (graph.py:197) remove the vector, with no graph.py change.
  2. Config: add EmbedConfig(enabled=True, model_dir, interval_seconds, min_score) after FeedConfig (config.py:95-103), and Config.embed.
  3. New embed.py:
    • an Embedder Protocol;
    • OnnxEmbedder with ORT on one intra-op and one inter-op thread, and lazy imports;
    • load(), which returns None when disabled and raises EmbedError(model-absent/unreadable) otherwise;
    • person_text() over names, aliases, organisation, title and prefix-stripped tags;
    • refresh(), keyed by sha256(MODEL_ID + "\0" + text), embedding outside the transaction and upserting batches with WHERE EXISTS persons;
    • clear();
    • scores(): numpy frombuffer matrix @ query, filtered by model.
  4. views.find (views.py:105-113):
    • The Exact branch is unchanged and always first.
    • The default mode is hybrid when an embedder is present, else lexical. Explicit semantic or hybrid with embedding off raises ToolError embed-off.
    • Handle-shaped queries stay lexical.
    • Hybrid score = lexical tier score + cosine. Semantic-only rows need cosine >= min_score and get reason semantic.
    • views.status(conn, cfg) renders off or on covered=N.
  5. server.py: people_find gains a final mode Literal parameter and uses a lazy, locked _embedder() holder that build_app resets. people_status passes cfg and its docstring is updated.
  6. sync.py: load_embedder and embed_pass. When disabled, embed_pass clears the table. A missing model prints embed=error code= and never refuses boot. A sync-embed thread mirrors worker (sync.py:96-113). cli._sync (cli.py:47-59) runs one embed pass after the sources.
  7. scripts/fetch-model.sh (radicale.sh header style) downloads to a temp dir, checks sha256, does an atomic mv and writes models/.gitignore containing *. The new Makefile has a model target.
  8. Tests: conftest make_config defaults [embed] enabled=false, so the existing suites stay deterministic. Three version literals go from 4 to 5. The new tests/test_embed.py has a FakeEmbedder and needs_model skip tests.

Files: pyproject.toml · uv.lock · Makefile · scripts/fetch-model.sh · src/peoplemind_mcp/config.py · src/peoplemind_mcp/store.py · src/peoplemind_mcp/embed.py · src/peoplemind_mcp/views.py · src/peoplemind_mcp/server.py · src/peoplemind_mcp/sync.py · src/peoplemind_mcp/cli.py · tests/conftest.py · tests/test_embed.py · tests/test_config_cli.py · tests/test_identity.py · tests/test_mailmind.py
Derived artifacts: uv.lock

Decision: accept the 8 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-local-embeddings-on-by-default-ranking-people-find.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-local-embeddings-on-by-default-ranking-people-find.md

### ⏸ SVD architect gate: dev/peoplemind-mcp#7 local-embeddings-on-by-default-ranking-people-find **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `substrate` · dispatch effort `high` **Run:** `20261101T112846Z-5865f73a` **Held because:** CLEAN but 8 open risk(s) (2 verification · 6 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. The pattern to mirror, and the pinned model values, were unreadable: /Users/piers/src/imap-mailmind-mcp returned 'Operation not permitted' and network git ls-remote was denied. The HF revision, file names, sha256 values, pooling, query prefix and dependency pins must come from mailmind at dispatch. Question: can the dispatch runtime read imap-mailmind-mcp? If not, will the architect paste mailmind ADR 0005's revision and hashes into the spec before approval? Dispatch must halt rather than invent hashes. [decision] 2. ADR 0006 §2 lists vector inputs the issue omits: relation labels, signature lines and the last ten mail_evidence subjects. Signature lines and subjects are not persisted at base (the mailmind Source parses subjects at sources/mailmind.py:96-103 but does not store them). The spec follows the issue: name, aliases, Organisation, title, Tags. Question: add relation labels now (already stored in relations.label), and file a follow-up for storing signatures and subjects? [decision] 3. Wording diverges from the ADRs. ADR 0006 §4 says semantic-with-embed-off answers 'Error: embed is off'; this codebase renders tool errors as 'Error: code=<code>' (rows.py:15-16), so the lean returns 'Error: code=embed-off', also for explicit hybrid. ADR 0001 Amendment 1 shows 'on covered=N' only while the first backfill runs; the lean always shows covered=N when on. Question: accept both and record them as an ADR 0006 amendment? [decision] 4. The issue says the fetch script runs at image build, but no Dockerfile, Containerfile or compose file exists at 8c01615, and README.md:74 says the deploy slice has not shipped. This spec ships only scripts/fetch-model.sh and make model. Question: which issue owns the image build, so it can call scripts/fetch-model.sh? No ref could be named from the issue snapshot. [decision] 5. Query embedding needs the model in the API process as well as the sync thread the issue names: about 157 MB RSS (ADR 0006 Context). The lean loads it lazily on the first people_find, only when enabled. Question: accept the API-side load, or design a sync-side query service instead? [decision] 6. README is not updated: the 16-file ceiling is spent on code and tests, and tests/test_identity.py:445 forced a third version-literal edit. The people_status row (README.md:41) and the [embed]/make model docs remain stale. Question: a docs-only follow-up PR, or re-slice? [decision] 7. The 'expected Person first in a fixture of 50' criterion and the min_score=0.55 default are only proven where the model exists; model tests skip elsewhere. Check on the host before merge: `make model && uv run python3 -m pytest tests/test_embed.py -m model -q -rs` reports both model tests as passed, not skipped. [verification] 8. No numeric test baseline: the Half-A sandbox denied .venv/bin/python. Check: on the pristine base, `uv run python3 -m pytest -q` records the failure set before the first edit; after the change the same command shows the identical failure set plus the new tests/test_embed.py passes, and `uv run mypy` is clean. [verification] **Change:** Mailmind is the pattern source, and the sandbox denied it. Dispatch must read mailmind's fetch script, embedder and ADR 0005 first and copy the revision, hashes, file names, pooling and dependency pins verbatim. If it cannot, it halts. 1. Schema: append migration 5 in the shape of store.py:85-90. It adds `person_vectors(person_id PK REFERENCES persons(id) ON DELETE CASCADE, model, text_hash, vector BLOB, updated_at)` and bumps SCHEMA_VERSION to 5. The cascade makes Forget (graph.py:381) and merge-loser deletion (graph.py:197) remove the vector, with no graph.py change. 2. Config: add `EmbedConfig(enabled=True, model_dir, interval_seconds, min_score)` after FeedConfig (config.py:95-103), and `Config.embed`. 3. New embed.py: - an `Embedder` Protocol; - `OnnxEmbedder` with ORT on one intra-op and one inter-op thread, and lazy imports; - `load()`, which returns None when disabled and raises `EmbedError(model-absent/unreadable)` otherwise; - `person_text()` over names, aliases, organisation, title and prefix-stripped tags; - `refresh()`, keyed by `sha256(MODEL_ID + "\0" + text)`, embedding outside the transaction and upserting batches with `WHERE EXISTS persons`; - `clear()`; - `scores()`: numpy `frombuffer` matrix @ query, filtered by model. 4. views.find (views.py:105-113): - The Exact branch is unchanged and always first. - The default mode is hybrid when an embedder is present, else lexical. Explicit semantic or hybrid with embedding off raises ToolError embed-off. - Handle-shaped queries stay lexical. - Hybrid score = lexical tier score + cosine. Semantic-only rows need cosine >= min_score and get reason `semantic`. - views.status(conn, cfg) renders `off` or `on covered=N`. 5. server.py: people_find gains a final `mode` Literal parameter and uses a lazy, locked `_embedder()` holder that build_app resets. people_status passes cfg and its docstring is updated. 6. sync.py: `load_embedder` and `embed_pass`. When disabled, embed_pass clears the table. A missing model prints `embed=error code=` and never refuses boot. A `sync-embed` thread mirrors `worker` (sync.py:96-113). cli._sync (cli.py:47-59) runs one embed pass after the sources. 7. scripts/fetch-model.sh (radicale.sh header style) downloads to a temp dir, checks sha256, does an atomic mv and writes `models/.gitignore` containing `*`. The new Makefile has a `model` target. 8. Tests: conftest make_config defaults `[embed] enabled=false`, so the existing suites stay deterministic. Three version literals go from 4 to 5. The new tests/test_embed.py has a FakeEmbedder and `needs_model` skip tests. **Files:** `pyproject.toml` · `uv.lock` · `Makefile` · `scripts/fetch-model.sh` · `src/peoplemind_mcp/config.py` · `src/peoplemind_mcp/store.py` · `src/peoplemind_mcp/embed.py` · `src/peoplemind_mcp/views.py` · `src/peoplemind_mcp/server.py` · `src/peoplemind_mcp/sync.py` · `src/peoplemind_mcp/cli.py` · `tests/conftest.py` · `tests/test_embed.py` · `tests/test_config_cli.py` · `tests/test_identity.py` · `tests/test_mailmind.py` **Derived artifacts:** `uv.lock` **Decision:** accept the 8 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-local-embeddings-on-by-default-ranking-people-find.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-local-embeddings-on-by-default-ranking-people-find.md`</sub>
Owner

Architect gate on the Half-A spec (run 20261101T112846Z-5865f73a, verdict CLEAN, 16 files, class substrate, dispatch base main 8c01615). Rulings recorded in the spec's ## Agent Adjustments:

  1. Pinned model values pasted from mailmind ADR 0005 §2 at d0ee0f1: Xenova/bge-small-en-v1.5 @ ea104dacec62c0de699686887e3f920caeb4f3e3, model_quantized.onnx and tokenizer.json with their sha256, CLS pooling, L2-normalised, no query prefix, one text per run, one thread. Pins onnxruntime>=1.31,<2, tokenizers>=0.23,<1, numpy>=2.3,<3. Dispatch invents nothing.
  2. Fetch script mirrors mailmind's stdlib Python scripts/fetch_model.py, not a bash script; make model calls it. Write set stays 16.
  3. Vector inputs for Phase A: name and aliases, organisation, title, tags, relation labels. Signature lines and subjects wait on #21; ADR 0006 Amendment 1 records this after merge.
  4. Error: code=embed-off and on covered=N accepted; same amendment.
  5. #9 owns the image build and calls the fetch script. API-side lazy model load accepted. README follows in the architect's amendment PR.
  6. Baseline on the host: 232 passed, 3 skipped, mypy and ruff clean. The architect runs make model and the model tests on a scratch worktree before merge.
  7. Reader sweep of excluded tests: no edit needed outside the write set.

Awaiting the operator's svd:go.

Architect gate on the Half-A spec (run 20261101T112846Z-5865f73a, verdict CLEAN, 16 files, class substrate, dispatch base main 8c01615). Rulings recorded in the spec's `## Agent Adjustments`: 1. Pinned model values pasted from mailmind ADR 0005 §2 at d0ee0f1: `Xenova/bge-small-en-v1.5` @ `ea104dacec62c0de699686887e3f920caeb4f3e3`, `model_quantized.onnx` and `tokenizer.json` with their sha256, CLS pooling, L2-normalised, no query prefix, one text per run, one thread. Pins `onnxruntime>=1.31,<2`, `tokenizers>=0.23,<1`, `numpy>=2.3,<3`. Dispatch invents nothing. 2. Fetch script mirrors mailmind's stdlib Python `scripts/fetch_model.py`, not a bash script; `make model` calls it. Write set stays 16. 3. Vector inputs for Phase A: name and aliases, organisation, title, tags, relation labels. Signature lines and subjects wait on #21; ADR 0006 Amendment 1 records this after merge. 4. `Error: code=embed-off` and `on covered=N` accepted; same amendment. 5. #9 owns the image build and calls the fetch script. API-side lazy model load accepted. README follows in the architect's amendment PR. 6. Baseline on the host: 232 passed, 3 skipped, mypy and ruff clean. The architect runs `make model` and the `model` tests on a scratch worktree before merge. 7. Reader sweep of excluded tests: no edit needed outside the write set. Awaiting the operator's `svd:go`.
Collaborator

spec-verify-dispatch Half B for dev/peoplemind-mcp#7 local-embeddings-on-by-default-ranking-people-find completed integration verify.

  • PR: dev/peoplemind-mcp#23
  • Branch: feat/svd-dev-peoplemind-mcp-7-local-embeddings-on-by-default-3e27f1f9
  • Commit: f17282df71
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Checks: PR #23 head f17282d: no Forgejo commit statuses reported, so no required remote checks. Local: 246 passed, 5 skipped; mypy, ruff check and ruff format are clean.
  • Warning: Forgejo commit statuses on PR head f17282d are empty: no remote CI has reported, so there is no remote check to gate on.
  • Warning: Five tests skipped, including the model-marked tests (test_model_ranks_role_and_organisation_first_in_fifty, test_onnx_embedder_is_normalised_and_single_threaded), because models/ is absent. Run make model and then pytest tests/test_embed.py -m model before relying on real-model ranking.
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261101T114655Z-3e27f1f9 --confirm-merge)
spec-verify-dispatch Half B for dev/peoplemind-mcp#7 local-embeddings-on-by-default-ranking-people-find completed integration verify. - PR: https://git.groupthink.asia/dev/peoplemind-mcp/pulls/23 - Branch: feat/svd-dev-peoplemind-mcp-7-local-embeddings-on-by-default-3e27f1f9 - Commit: f17282df71ccfe1c9ae4cec633be318cb7c9c557 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Checks: PR #23 head f17282d: no Forgejo commit statuses reported, so no required remote checks. Local: 246 passed, 5 skipped; mypy, ruff check and ruff format are clean. - Warning: Forgejo commit statuses on PR head f17282d are empty: no remote CI has reported, so there is no remote check to gate on. - Warning: Five tests skipped, including the model-marked tests (test_model_ranks_role_and_organisation_first_in_fifty, test_onnx_embedder_is_normalised_and_single_threaded), because models/ is absent. Run make model and then pytest tests/test_embed.py -m model before relying on real-model ranking. - Decision: review the PR and merge? (`codex-svd ship --run-id 20261101T114655Z-3e27f1f9 --confirm-merge`)
piers closed this issue 2026-11-01 11:56:34 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
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
dev/people-mind-mcp#7
No description provided.