Embed every mirrored message locally with a pinned model #43

Closed
opened 2026-10-31 13:08:55 +00:00 by svc-agent-writer · 0 comments

Part of #9. Decision: ADR 0005 §2 to §5 and §7.

What to build

  • Image. The Containerfile downloads onnx/model_quantized.onnx and tokenizer.json from Xenova/bge-small-en-v1.5 at revision ea104dacec62c0de699686887e3f920caeb4f3e3. The build checks both sha256 values from ADR 0005 §2 and fails on a mismatch. The files go to a fixed path in the image, read-only, owned by root. Add onnxruntime, tokenizers and numpy to pyproject.toml and uv.lock.

  • Config. An optional [embed] section with model_dir (default: the image path), batch (messages per tick, default 32), pause_seconds (default 0), and poll_seconds (default 60). With the section absent, nothing loads the model.

  • Schema v4. embeddings(message_id INTEGER PRIMARY KEY, model TEXT NOT NULL, vec BLOB NOT NULL). The vector is 384 float32 values. Deleting a message deletes its vector in the same transaction. The reader waits for v4 as it does today.

  • embed.py. One Embedder that loads the session with one intra-op thread, tokenises with truncation at 512, and returns the CLS output L2-normalised. The input text is the subject plus the blade's trim_quoted plain text. One message per model run.

  • The thread. SyncWorker.run_forever starts an embed thread when [embed] is set. Each tick does three things:

    1. It copies vectors to rows with the same Message-ID.
    2. It embeds up to batch messages without a vector for the current model, newest first.
    3. It writes them in one transaction.

    It then sleeps for poll_seconds, or loops at once while a backlog remains, with pause_seconds between batches.

  • Reporting. mail_status reports embed: off or embed: model=bge-small-en-v1.5, plus embedded=N per account. mailmind check loads the model and embeds one fixed string. sync --once runs one embed tick.

  • Logs. Counts, the model name and timings only.

Acceptance

  • A unit test embeds two fixed strings with the real model and checks the dimension, the unit norm, and that a near-duplicate scores higher than an unrelated string.
  • A test runs the thread over a fixture store. It backfills, resumes after a stop, and copies a vector by Message-ID without a model run.
  • A test deletes a message and checks that its vector is gone.
  • A model-name change re-embeds every message.
  • make check passes, including pip-audit. make image-amd64 builds, and the image size growth is stated in the PR.
Part of #9. Decision: ADR 0005 §2 to §5 and §7. ## What to build - **Image.** The `Containerfile` downloads `onnx/model_quantized.onnx` and `tokenizer.json` from `Xenova/bge-small-en-v1.5` at revision `ea104dacec62c0de699686887e3f920caeb4f3e3`. The build checks both sha256 values from ADR 0005 §2 and fails on a mismatch. The files go to a fixed path in the image, read-only, owned by root. Add `onnxruntime`, `tokenizers` and `numpy` to `pyproject.toml` and `uv.lock`. - **Config.** An optional `[embed]` section with `model_dir` (default: the image path), `batch` (messages per tick, default 32), `pause_seconds` (default 0), and `poll_seconds` (default 60). With the section absent, nothing loads the model. - **Schema v4.** `embeddings(message_id INTEGER PRIMARY KEY, model TEXT NOT NULL, vec BLOB NOT NULL)`. The vector is 384 float32 values. Deleting a message deletes its vector in the same transaction. The reader waits for v4 as it does today. - **`embed.py`.** One `Embedder` that loads the session with one intra-op thread, tokenises with truncation at 512, and returns the CLS output L2-normalised. The input text is the subject plus the blade's `trim_quoted` plain text. One message per model run. - **The thread.** `SyncWorker.run_forever` starts an `embed` thread when `[embed]` is set. Each tick does three things: 1. It copies vectors to rows with the same Message-ID. 2. It embeds up to `batch` messages without a vector for the current model, newest first. 3. It writes them in one transaction. It then sleeps for `poll_seconds`, or loops at once while a backlog remains, with `pause_seconds` between batches. - **Reporting.** `mail_status` reports `embed: off` or `embed: model=bge-small-en-v1.5`, plus `embedded=N` per account. `mailmind check` loads the model and embeds one fixed string. `sync --once` runs one embed tick. - **Logs.** Counts, the model name and timings only. ## Acceptance - A unit test embeds two fixed strings with the real model and checks the dimension, the unit norm, and that a near-duplicate scores higher than an unrelated string. - A test runs the thread over a fixture store. It backfills, resumes after a stop, and copies a vector by Message-ID without a model run. - A test deletes a message and checks that its vector is gone. - A model-name change re-embeds every message. - `make check` passes, including pip-audit. `make image-amd64` builds, and the image size growth is stated in the PR.
Sign in to join this conversation.
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
dev/mail-mind-mcp#43
No description provided.