Repository navigation
Read-embeddings API for cloud push (core half of sync #97) - #1416
Conversation
|
REQUEST CHANGES ⏳ Initial review, top commit Clean, well-scoped read API, and I verified the two claims that matter most: ✅ The ✅ Blob round-trip + column mapping are correct. ✅ One blocking item, plus one note: 🟡 🟢 Lexicographic timestamp cursor is correct today, but it's a load-bearing invariant worth a comment. Net: correct, ungated-correctly, and well-tested read layer — the one thing to resolve before merge is whether |
The Pro daemon's upcoming pgvector push needs to read locally-stored vectors, but core only exposed embedding *search* (KNN) and *write* (upsert) — no plain read. Add two read methods, both decoding the little-endian f32 blob written by `upsert_embeddings` back into the `Embedding` model via a new `row_to_embedding` helper: - `SqliteStore::get_embeddings(node_id)` — a node's embeddings, by chunk. - `SqliteStore::embeddings_modified_since(since)` — embeddings modified at or after a cursor, across all nodes, ordered by `modified_at`; this is what the daemon will sweep to push newly (re)computed vectors. Both are surfaced as `NodeService` wrappers (the daemon holds an `Arc<NodeService>`). They are deliberately NOT behind the `nlp` feature: they read the persisted `embedding` table, which exists whether or not embedding *generation* (llama-cpp) is compiled in — so a daemon built without NLP can still sync vectors. The recurring sweep gets a covering index: `idx_emb_modified ON embedding (modified_at, node_id, chunk_index)`. The existing idx_emb_stale_mod leads with `stale`, so it can't serve the stale-agnostic modified_at range scan — without the new index every sweep full-scans + filesorts. Also pinned the lexicographic-cursor invariant (UTC rfc3339 modified_at) in a doc comment. Test: upsert two synthetic 768-dim chunk vectors, assert both round-trip out of the blob in chunk order, the modified-since cursor includes them at epoch and excludes them in the future, the sweep's query plan uses idx_emb_modified with no filesort, and a node with no embeddings reads back empty. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed — force-pushed `d40fbff`. 🟡 Blocking: missing index for the sweep. Added it now (it lands where the method lives, not deferred). 🟢 Lexicographic-cursor invariant. Added a doc comment on Test green; additive only. |
|
APPROVE ⏳ Re-review at your request, now at Both items from my last pass are resolved, and the index one came back stronger than I asked: ✅ The sweep now has its index. ✅ And it's locked in with a query-plan test. The new ✅ Cursor invariant documented. The Everything else (the Good to merge. Thanks for turning the index note into a plan-asserting test — that's the right way to keep #97's push sweep honest. |
#1417) The Pro daemon's upcoming embedding PULL needs to apply vectors synced from another device into the local store, but `upsert_embeddings` / `delete_embeddings` were store-only (the read API from #1416 added reads; this adds the symmetric writes). Surface both as `NodeService` wrappers: - `NodeService::upsert_embeddings(node_id, Vec<NewEmbedding>)` — replace a node's vectors wholesale (mirrors the local generation path). - `NodeService::delete_embeddings(node_id)` — clear a node's vectors. Like the read wrappers, both are deliberately NOT behind the `nlp` feature: applying a received vector doesn't need the generation engine, so a daemon built without llama-cpp can still receive embeddings. Test: upsert a synthetic 768-dim vector via the wrapper, read it back via get_embeddings (round-trip), then delete and assert empty. Co-authored-by: Mayank Tomar <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
The Pro daemon's upcoming pgvector push needs to read locally-stored vectors, but core only exposed embedding *search* (KNN) and *write* (upsert) — no plain read. Add two read methods, both decoding the little-endian f32 blob written by `upsert_embeddings` back into the `Embedding` model via a new `row_to_embedding` helper: - `SqliteStore::get_embeddings(node_id)` — a node's embeddings, by chunk. - `SqliteStore::embeddings_modified_since(since)` — embeddings modified at or after a cursor, across all nodes, ordered by `modified_at`; this is what the daemon will sweep to push newly (re)computed vectors. Both are surfaced as `NodeService` wrappers (the daemon holds an `Arc<NodeService>`). They are deliberately NOT behind the `nlp` feature: they read the persisted `embedding` table, which exists whether or not embedding *generation* (llama-cpp) is compiled in — so a daemon built without NLP can still sync vectors. The recurring sweep gets a covering index: `idx_emb_modified ON embedding (modified_at, node_id, chunk_index)`. The existing idx_emb_stale_mod leads with `stale`, so it can't serve the stale-agnostic modified_at range scan — without the new index every sweep full-scans + filesorts. Also pinned the lexicographic-cursor invariant (UTC rfc3339 modified_at) in a doc comment. Test: upsert two synthetic 768-dim chunk vectors, assert both round-trip out of the blob in chunk order, the modified-since cursor includes them at epoch and excludes them in the future, the sweep's query plan uses idx_emb_modified with no filesort, and a node with no embeddings reads back empty. Co-authored-by: Mayank Tomar <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
#1417) The Pro daemon's upcoming embedding PULL needs to apply vectors synced from another device into the local store, but `upsert_embeddings` / `delete_embeddings` were store-only (the read API from #1416 added reads; this adds the symmetric writes). Surface both as `NodeService` wrappers: - `NodeService::upsert_embeddings(node_id, Vec<NewEmbedding>)` — replace a node's vectors wholesale (mirrors the local generation path). - `NodeService::delete_embeddings(node_id)` — clear a node's vectors. Like the read wrappers, both are deliberately NOT behind the `nlp` feature: applying a received vector doesn't need the generation engine, so a daemon built without llama-cpp can still receive embeddings. Test: upsert a synthetic 768-dim vector via the wrapper, read it back via get_embeddings (round-trip), then delete and assert empty. Co-authored-by: Mayank Tomar <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
What
Core half of NodeSpaceAI/nodespace-sync#97 (T11 — pgvector embedding sync), the push-path-first slice. The Pro daemon needs to read locally-stored vectors to mirror them into Supabase pgvector, but core only exposed embedding search (KNN) and write (upsert) — there was no plain read.
Changes
row_to_embeddinghelper — decodes a stored row back into theEmbeddingmodel, including the little-endian f32 blobupsert_embeddingswrites (chunks_exact(4)→f32::from_le_bytes).SqliteStore::get_embeddings(node_id)— all of a node's embedding chunks, ordered by chunk index.SqliteStore::embeddings_modified_since(since)— embeddings modified at/after a cursor, across all nodes, ordered bymodified_at. This is what the daemon's push sweep (PR 2) will advance a cursor over to push newly (re)computed vectors.NodeServicewrappers (the daemon holdsArc<NodeService>).Note on the
nlpfeatureThe new methods are deliberately not gated behind
nlp. They read the persistedembeddingtable, which exists regardless of whether embedding generation (llama-cpp) is compiled in — so a daemon built without NLP (cf. sync #10) can still sync vectors. Generation stays#[cfg(feature = "nlp")]; only reads are feature-independent.Verification
embeddings_modified_sinceincludes them at epoch, excludes them in the future; a node with no embeddings reads back empty.cargo test(new test green) +cargo clippy --libclean. Additive only — no existing method changed.Part of NodeSpaceAI/nodespace-sync#97 (PR 1 of the incremental push-first plan; PR 2 = daemon push + pin bump).