1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2026 AlphaOne LLC
// SPDX-License-Identifier: Apache-2.0
//! Source-embed pipeline + post-insert HNSW warm-up.
//!
//! #881 (PR-4 extraction): split out of the monolithic
//! `src/mcp/tools/store.rs` so the embed-before-store branch lives in
//! its own ~70-LOC module. Wire-compat preserved verbatim: every
//! tracing warn label is byte-identical to the pre-#881 inline code
//! path.
//!
//! The embed pass runs AFTER `db::insert` lands so the row id is
//! known. The embedder + HNSW writes are best-effort — a failure
//! degrades recall on this row but does NOT roll back the store.
//!
//! Form 2 synchronous atomisation SKIPs the source embed entirely;
//! the atomiser archives the parent with `atomised_into > 0` and
//! atoms get their own embed-on-insert path. The store handler
//! resolves the skip flag and gates this helper accordingly.
use crateEmbed;
use crateVectorIndex;
use crateMemory;
use crate::;
use AUTONOMY_MIN_CONTENT_LEN;
/// Decide whether to skip the source embed because Form 2 synchronous
/// atomisation will run the per-atom embed path instead. Mirrors the
/// pre-#881 inline guard in `handle_store`.
pub
/// Generate the embedding for the just-stored memory and persist it
/// to the `embeddings` table + the HNSW vector index. Best-effort —
/// any failure logs at WARN and lets the store response proceed
/// without the embedding (degrades recall on this row, never blocks
/// the write).
///
/// #1579 A1 — `precomputed` carries the document embedding the
/// proactive-conflict check already produced for the IDENTICAL
/// `embedding_document(title, content)` text earlier in
/// `handle_store`. When `Some`, the second (duplicate) embed call is
/// skipped — at semantic/smart tiers the embed is the dominant
/// per-store cost (~150-400 ms inline MiniLM on commodity hardware;
/// one network round-trip per call on remote embedders), so reusing
/// the vector halves store latency. `None` preserves the legacy
/// embed-here path for callers that skipped the conflict check
/// (`force=true`) or whose earlier embed attempt failed (the retry
/// keeps the WARN label attribution on `actual_id` byte-identical to
/// the pre-#1579 contract).
pub